agent: compile web assets into consul binary

This commit is contained in:
Ryan Uber 2015-11-30 11:24:08 -08:00
parent 1e66aba424
commit a262115679
3 changed files with 30 additions and 4 deletions

View File

@ -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

View File

@ -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

View File

@ -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.