diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9990f4c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM alpine:3.4 + +MAINTAINER Pavel Paulau + +EXPOSE 8000 + +ENV CB_HOST "" +ENV CB_PASS "" + +COPY app app +COPY showfast /usr/local/bin/showfast + +CMD ["showfast"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1f2368f --- /dev/null +++ b/Makefile @@ -0,0 +1,12 @@ +build: + go build -v + +fmt: + find . -name "*.go" -not -path "./vendor/*" | xargs gofmt -w -s + +docker: + CGO_ENABLED=0 go build -v -a --ldflags "-s" && upx -q6 showfast + docker build --rm -t perflab/showfast . + +clean: + rm -fr showfast diff --git a/README.md b/README.md index b5fafca..b15e18b 100644 --- a/README.md +++ b/README.md @@ -1,32 +1,26 @@ -[![Go Report Card](https://goreportcard.com/badge/github.com/couchbaselabs/showfast)](https://goreportcard.com/report/github.com/couchbaselabs/showfast) showfast ======== +[![Go Report Card](https://goreportcard.com/badge/github.com/couchbaselabs/showfast)](https://goreportcard.com/report/github.com/couchbaselabs/showfast) -Performance dashboard. Powered by web.go, AngularJS, nvd3 and Couchbase Server. +Couchbase Server performance dashboard. Prerequisites ------------- -* go 1.1 -* Couchbase Server 2.0.0 or higher +* go 1.6 +* Couchbase Server 4.x. Required buckets ---------------- * benchmarks * clusters +* feed * metrics -Installation ------------- - - go get github.com/couchbaselabs/showfast - Usage ----- - $GOPATH/bin/showfast - - All parameters are specified in config.json - \ No newline at end of file + docker pull perflab/showfast + docker run -t -i -e CB_HOST=... -e CB_PASS=... -p 8000:8000 perflab/showfast diff --git a/config.json b/config.json deleted file mode 100644 index 192f85e..0000000 --- a/config.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "CouchbaseAddress": "127.0.0.1:8091", - "BucketPassword": "password", - "ListenAddress": "127.0.0.1:8000" -} diff --git a/datasources.go b/datasources.go index c9e4102..c683be6 100644 --- a/datasources.go +++ b/datasources.go @@ -52,11 +52,11 @@ var ddocs = map[string]string{ } type DataSource struct { - CouchbaseAddress, BucketPassword string + hostname, password string } func (ds *DataSource) getBucket(bucket string) *couchbase.Bucket { - uri := fmt.Sprintf("http://%s:%s@%s/", bucket, ds.BucketPassword, ds.CouchbaseAddress) + uri := fmt.Sprintf("http://%s:%s@%s:8091/", bucket, ds.password, ds.hostname) client, _ := couchbase.Connect(uri) pool, _ := client.GetPool("default") diff --git a/main.go b/main.go index 45881e7..bc53c74 100644 --- a/main.go +++ b/main.go @@ -9,37 +9,43 @@ import ( "github.com/hoisie/web" ) -var pkgDir string +const ( + address = ":8000" + staticDir = "app" +) -var dataSource DataSource +var ( + dataSource DataSource + cbHost, cbPass string +) func home() []byte { - content, _ := ioutil.ReadFile(pkgDir + "app/index.html") + content, _ := ioutil.ReadFile("app/index.html") return content } -func allRuns(ctx *web.Context) []byte { - metric := ctx.Params["metric"] - build := ctx.Params["build"] - - return dataSource.getAllRuns(metric, build) -} - func admin() []byte { - content, _ := ioutil.ReadFile(pkgDir + "app/admin.html") + content, _ := ioutil.ReadFile("app/admin.html") return content } func release() []byte { - content, _ := ioutil.ReadFile(pkgDir + "app/release.html") + content, _ := ioutil.ReadFile("app/release.html") return content } func feed() []byte { - content, _ := ioutil.ReadFile(pkgDir + "app/feed.html") + content, _ := ioutil.ReadFile("app/feed.html") return content } +func allRuns(ctx *web.Context) []byte { + metric := ctx.Params["metric"] + build := ctx.Params["build"] + + return dataSource.getAllRuns(metric, build) +} + func getComparison(ctx *web.Context) []byte { baseline := ctx.Params["baseline"] target := ctx.Params["target"] @@ -64,32 +70,24 @@ func reverseObsolete(ctx *web.Context) { dataSource.reverseObsolete(params.ID) } -type Config struct { - CouchbaseAddress, BucketPassword, ListenAddress string +func init() { + cbHost = os.Getenv("CB_HOST") + cbPass = os.Getenv("CB_PASS") + if cbHost == "" || cbPass == "" { + log.Fatalln("Missing Couchbase Server settings.") + } } func main() { - pkgDir = os.Getenv("GOPATH") + "/src/github.com/couchbaselabs/showfast/" - web.Config.StaticDir = pkgDir + "app" - - configFile, err := ioutil.ReadFile(pkgDir + "config.json") - if err != nil { - log.Fatal(err) - } - - var config Config - err = json.Unmarshal(configFile, &config) - if err != nil { - log.Fatal(err) - } - - dataSource = DataSource{config.CouchbaseAddress, config.BucketPassword} + dataSource = DataSource{cbHost, cbPass} web.Get("/", home) web.Get("/admin", admin) web.Get("/release", release) web.Get("/feed", feed) + web.Config.StaticDir = staticDir + web.Get("/all_metrics", dataSource.getAllMetrics) web.Get("/all_clusters", dataSource.getAllClusters) web.Get("/all_timelines", dataSource.getAllTimelines) @@ -101,5 +99,5 @@ func main() { web.Post("/delete", deleteBenchmark) web.Post("/reverse_obsolete", reverseObsolete) - web.Run(config.ListenAddress) + web.Run(address) }