diff --git a/Makefile b/Makefile index f937c9d91..316b070e3 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,5 @@ -GOTOOLS = github.com/mitchellh/gox golang.org/x/tools/cmd/stringer +GOTOOLS = github.com/mitchellh/gox golang.org/x/tools/cmd/stringer \ + github.com/jteeuwen/go-bindata/... github.com/elazarl/go-bindata-assetfs/... DEPS = $(shell go list -f '{{range .TestImports}}{{.}} {{end}}' ./...) PACKAGES = $(shell go list ./...) VETARGS?=-asmdecl -atomic -bool -buildtags -copylocks -methods \ @@ -68,10 +69,17 @@ generate: deps find . -type f -name '.DS_Store' -delete go generate ./... +# generates the static web ui +static-assets: deps + @echo "--> Generating static assets" + @go-bindata-assetfs -pkg agent -prefix ui ./ui/dist/... + @mv bindata_assetfs.go command/agent + $(MAKE) format + web: ./scripts/website_run.sh web-push: ./scripts/website_push.sh -.PHONY: all bin dev dist cov deps test vet web web-push generate test-nodep +.PHONY: all bin dev dist cov deps test vet web web-push generate test-nodep static-assets diff --git a/command/agent/http.go b/command/agent/http.go index 9828444d8..4438d1f00 100644 --- a/command/agent/http.go +++ b/command/agent/http.go @@ -275,10 +275,11 @@ func (s *HTTPServer) registerHandlers(enableDebug bool) { s.mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol) } - // Enable the UI + special endpoints + // Use the custom UI dir if provided. if s.uiDir != "" { - // Static file serving done from /ui/ s.mux.Handle("/ui/", http.StripPrefix("/ui/", http.FileServer(http.Dir(s.uiDir)))) + } else { + s.mux.Handle("/ui/", http.StripPrefix("/ui/", http.FileServer(assetFS()))) } // API's are under /internal/ui/ to avoid conflict diff --git a/ui/README.md b/ui/README.md index 561eab541..08d4a9b64 100644 --- a/ui/README.md +++ b/ui/README.md @@ -60,3 +60,20 @@ The `dist` folder will contain the files you should use for deployment. ###Acknowledgements cog icon by useiconic.com from the [Noun Project](https://thenounproject.com/term/setting/45865/) + +### Compiling the UI into the Go binary + +The UI is compiled and shipped with the Consul go binary. The generated bindata +file lives in the `command/agent/bindata_assetfs.go` file and is checked into +source control. This is useful so that not every Consul developer needs to set +up bundler etc. To re-generate the file, first follow the compilation steps +above to build the UI assets into the `dist/` folder. With that done, from the +root of the Consul repo, run: + +``` +$ make static-assets +``` + +The file will now be refreshed with the current UI data. You can now rebuild the +Consul binary normally with `make bin` or `make dev`, and see the updated UI +after re-launching Consul.