From 3027137a965730e6970bf0c169f93a0ea3020b98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Sat, 25 Mar 2017 10:11:49 -0700 Subject: [PATCH 1/5] Cleanup make targets and update readme to match it Refactor make targets to make it easier to follow, add missing PORT env variable to the readme. --- Makefile | 44 ++++++++++++++++++++++++++------------------ README.md | 53 +++++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 65 insertions(+), 32 deletions(-) diff --git a/Makefile b/Makefile index 20c8bc58c..3817f5f2e 100644 --- a/Makefile +++ b/Makefile @@ -1,34 +1,40 @@ +NAME := unsee VERSION := $(shell git describe --tags --always --dirty='-dev') +# Alertmanager instance used when running locally, points to mock data +ALERTMANAGER_URI := https://raw.githubusercontent.com/prymitive/alertmanager-demo-api/master +# Listen port when running locally +PORT := 8080 + +SOURCES := $(wildcard *.go) $(wildcard */*.go) + +.DEFAULT_GOAL := $(NAME) + .build/deps.ok: .gitmodules git submodule update --init --recursive mkdir -p .build touch $@ +$(NAME): .build/deps.ok $(SOURCES) + go build -ldflags "-X main.version=$(VERSION)" + +.PHONY: run +run: $(NAME) + DEBUG=true ALERTMANAGER_URI=$(ALERTMANAGER_URI) PORT=$(PORT) ./unsee + .PHONY: docker-image -docker-image: - docker build --build-arg VERSION=$(VERSION) -t unsee:$(VERSION) . +docker-image: bindata_assetfs.go + docker build --build-arg VERSION=$(VERSION) -t $(NAME):$(VERSION) . -ALERTMANAGER_URI := https://raw.githubusercontent.com/prymitive/alertmanager-demo-api/master -PORT := 8080 - -.PHONY: demo -demo: docker-image - @docker rm -f unsee-dev || true +.PHONY: run-docker +run-docker: docker-image + @docker rm -f $(NAME) || true docker run \ - --name unsee-dev \ + --name $(NAME) \ -e ALERTMANAGER_URI=$(ALERTMANAGER_URI) \ -e PORT=$(PORT) \ -p $(PORT):$(PORT) \ - unsee:$(VERSION) - -.PHONY: dev -dev: .build/deps.ok - go build -v -ldflags "-X main.version=${VERSION:-dev}" && \ - DEBUG=true \ - ALERTMANAGER_URI=$(ALERTMANAGER_URI) \ - PORT=$(PORT) \ - ./unsee + $(NAME):$(VERSION) .PHONY: lint lint: .build/deps.ok @@ -38,6 +44,8 @@ lint: .build/deps.ok test: lint @go test -cover `go list ./... | grep -v /vendor/` +#======================== asset helper targets ================================= + ASSETS_DIR := $(CURDIR)/static/assets CDNJS_PREFIX := https://cdnjs.cloudflare.com/ajax/libs diff --git a/README.md b/README.md index c12ca7843..d25b2c685 100644 --- a/README.md +++ b/README.md @@ -9,15 +9,35 @@ to alert data, therefore safe to be accessed by wider audience. ## Building and running -### Running in dev mode +### Building from source -Requires Go. +To clone git repo and build the binary yourself run: - make dev + git clone https://github.com/cloudflare/unsee $GOPATH/src/github.com/cloudflare/unsee + cd $GOPATH/src/github.com/cloudflare/unsee + make -Will compile unsee and run the binary (not using Docker), by default will use -same port and Alertmanager URI as demo mode. This is intended for local -development. +`unsee` binary will be compiled in project directory. + +### Running + +`unsee` is configured via environment variables or command line flags. +Environment variable `ALERTMANAGER_URI` or cli flag `-alertmanager.uri` is the +only option required to run. See `Environment variables` section below for the +full list of supported environment variables. Examples: + + ALERTMANAGER_URI=https://alertmanager.example.com unsee + unsee -alertmanager.uri https://alertmanager.example.com + +There is a make target which will compile and run unsee: + + make run + +By default it will listen on port `8080` and Alertmanager mock data will be +used, to override Alertmanager URI set `ALERTMANAGER_URI` and/or `PORT` make +variables. Example: + + make PORT=5000 ALERTMANAGER_URI=https://alertmanager.example.com run ### Build a Docker image @@ -25,17 +45,14 @@ development. This will build a Docker image from sources. -### Running the Docker image in demo mode +### Running the Docker image - make demo + make run-docker -Will run locally build Docker image. This is intended for testing build Docker -images or checking unsee functionality. -By default unsee will listen on port `8080` and Alertmanager mock data will be -used, to override Alertmanager URI set `ALERTMANAGER_URI` and/or `PORT` make -variables. Example: +Will run locally built Docker image. Same defaults and override variables +apply as with `make run`. Example: - make PORT=5000 ALERTMANAGER_URI=https://alertmanager.example.com run + make PORT=5000 ALERTMANAGER_URI=https://alertmanager.example.com run-docker ### Environment variables @@ -172,6 +189,14 @@ This option can also be set using `-jira.regex` flag. Example: This variable is optional and default is not set (no rule will be applied). +#### PORT + +HTTP port to listen on. Example: + + PORT=8000 + +Default is `8080`. + #### SENTRY_DSN DSN for [Sentry](https://sentry.io) integration in Go. See From f8420d4632a78ad07d4186f351855d4762d6c616 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Sat, 25 Mar 2017 13:15:54 -0700 Subject: [PATCH 2/5] Use go-bindata-assetfs for static files This allows unsee to be compiled into a single self-contained binary, without any need to external static files or templates --- .gitmodules | 66 +- Dockerfile | 7 +- Makefile | 27 +- assets.go | 84 +- {static => assets/static}/alerts.js | 0 {static => assets/static}/autocomplete.js | 0 {static => assets/static}/base.css | 0 {static => assets/static}/colors.js | 0 {static => assets/static}/config.js | 0 {static => assets/static}/counter.js | 0 {static => assets/static}/favicon.ico | Bin {static => assets/static}/filters.js | 0 {static => assets/static}/grid.js | 0 .../static}/jquery.typing-0.2.0.js | 0 {static => assets/static}/lru.js | 0 .../static/managed}/css/0.1.2-loaders.min.css | 0 .../managed}/css/0.2.0-nprogress.min.css | 0 .../0.8.0-bootstrap-tagsinput-typeahead.css | 0 .../css/0.8.0-bootstrap-tagsinput.css | 0 .../css/3.3.2-bootstrap-switch.min.css | 0 .../managed}/css/3.3.7-bootstrap.min.css | 0 .../managed}/css/4.7.0-font-awesome.min.css | 0 .../static/managed}/css/assets.txt | 0 .../static/managed}/fonts/FontAwesome.otf | Bin .../managed}/fonts/fontawesome-webfont.eot | Bin .../managed}/fonts/fontawesome-webfont.svg | 0 .../managed}/fonts/fontawesome-webfont.ttf | Bin .../managed}/fonts/fontawesome-webfont.woff | Bin .../managed}/fonts/fontawesome-webfont.woff2 | Bin .../managed}/js/0.1.2-loaders.css.min.js | 0 .../js/0.11.1-typeahead.bundle.min.js | 0 .../static/managed}/js/0.2.0-nprogress.min.js | 0 .../static/managed}/js/0.3.10-favico.min.js | 0 .../static/managed}/js/0.4.0-sha1.min.js | 0 .../js/0.8.0-bootstrap-tagsinput.min.js | 0 .../managed}/js/1.5.16-clipboard.min.js | 0 .../managed}/js/1.8.3-underscore-min.js | 0 .../static/managed}/js/2.1.3-js.cookie.min.js | 0 .../static/managed}/js/2.17.1-moment.min.js | 0 .../static/managed}/js/2.2.4-jquery.min.js | 0 .../js/2.4.0-underscore.string.min.js | 0 .../managed}/js/2.4.2-isInViewport.min.js | 0 .../managed}/js/3.3.2-bootstrap-switch.min.js | 0 .../static/managed}/js/3.3.7-bootstrap.min.js | 0 .../static/managed}/js/3.9.1-raven.min.js | 0 .../managed}/js/4.1.1-masonry.pkgd.min.js | 0 .../static/managed}/js/5.4-haml.js | 0 .../static/managed}/js/assets.txt | 0 .../js/bootstrap-tagsinput.min.js.map | 0 .../static/managed}/js/haml.map | 0 .../static/managed}/js/jquery.min.map | 0 .../static/managed}/js/js.cookie.min.js.map | 0 .../static/managed}/js/raven.min.js.map | 0 .../static/managed}/js/underscore-min.map | 0 {static => assets/static}/progress.js | 0 {static => assets/static}/querystring.js | 0 {static => assets/static}/summary.js | 0 {static => assets/static}/unsee.js | 0 {static => assets/static}/watchdog.js | 0 {templates => assets/templates}/errors.haml | 0 {templates => assets/templates}/groups.haml | 0 {templates => assets/templates}/help.html | 2 +- {templates => assets/templates}/index.html | 14 +- {templates => assets/templates}/js.html | 0 {templates => assets/templates}/modal.haml | 0 {templates => assets/templates}/summary.haml | 0 bindata_assetfs.go | 1661 +++++++++++++++++ main.go | 24 +- vendor/github.com/Sirupsen/logrus | 2 +- vendor/github.com/asaskevich/govalidator | 2 +- vendor/github.com/elazarl/go-bindata-assetfs | 1 + vendor/github.com/gin-contrib/static | 1 + vendor/github.com/golang/protobuf | 2 +- vendor/github.com/mattn/go-isatty | 2 +- vendor/github.com/prometheus/client_golang | 2 +- vendor/golang.org/x/net | 2 +- vendor/gopkg.in/jarcoal/httpmock.v1 | 2 +- views.go | 30 +- views_test.go | 6 +- 79 files changed, 1844 insertions(+), 93 deletions(-) rename {static => assets/static}/alerts.js (100%) rename {static => assets/static}/autocomplete.js (100%) rename {static => assets/static}/base.css (100%) rename {static => assets/static}/colors.js (100%) rename {static => assets/static}/config.js (100%) rename {static => assets/static}/counter.js (100%) rename {static => assets/static}/favicon.ico (100%) rename {static => assets/static}/filters.js (100%) rename {static => assets/static}/grid.js (100%) rename {static => assets/static}/jquery.typing-0.2.0.js (100%) rename {static => assets/static}/lru.js (100%) rename {static/assets => assets/static/managed}/css/0.1.2-loaders.min.css (100%) rename {static/assets => assets/static/managed}/css/0.2.0-nprogress.min.css (100%) rename {static/assets => assets/static/managed}/css/0.8.0-bootstrap-tagsinput-typeahead.css (100%) rename {static/assets => assets/static/managed}/css/0.8.0-bootstrap-tagsinput.css (100%) rename {static/assets => assets/static/managed}/css/3.3.2-bootstrap-switch.min.css (100%) rename {static/assets => assets/static/managed}/css/3.3.7-bootstrap.min.css (100%) rename {static/assets => assets/static/managed}/css/4.7.0-font-awesome.min.css (100%) rename {static/assets => assets/static/managed}/css/assets.txt (100%) rename {static/assets => assets/static/managed}/fonts/FontAwesome.otf (100%) rename {static/assets => assets/static/managed}/fonts/fontawesome-webfont.eot (100%) rename {static/assets => assets/static/managed}/fonts/fontawesome-webfont.svg (100%) rename {static/assets => assets/static/managed}/fonts/fontawesome-webfont.ttf (100%) rename {static/assets => assets/static/managed}/fonts/fontawesome-webfont.woff (100%) rename {static/assets => assets/static/managed}/fonts/fontawesome-webfont.woff2 (100%) rename {static/assets => assets/static/managed}/js/0.1.2-loaders.css.min.js (100%) rename {static/assets => assets/static/managed}/js/0.11.1-typeahead.bundle.min.js (100%) rename {static/assets => assets/static/managed}/js/0.2.0-nprogress.min.js (100%) rename {static/assets => assets/static/managed}/js/0.3.10-favico.min.js (100%) rename {static/assets => assets/static/managed}/js/0.4.0-sha1.min.js (100%) rename {static/assets => assets/static/managed}/js/0.8.0-bootstrap-tagsinput.min.js (100%) rename {static/assets => assets/static/managed}/js/1.5.16-clipboard.min.js (100%) rename {static/assets => assets/static/managed}/js/1.8.3-underscore-min.js (100%) rename {static/assets => assets/static/managed}/js/2.1.3-js.cookie.min.js (100%) rename {static/assets => assets/static/managed}/js/2.17.1-moment.min.js (100%) rename {static/assets => assets/static/managed}/js/2.2.4-jquery.min.js (100%) rename {static/assets => assets/static/managed}/js/2.4.0-underscore.string.min.js (100%) rename {static/assets => assets/static/managed}/js/2.4.2-isInViewport.min.js (100%) rename {static/assets => assets/static/managed}/js/3.3.2-bootstrap-switch.min.js (100%) rename {static/assets => assets/static/managed}/js/3.3.7-bootstrap.min.js (100%) rename {static/assets => assets/static/managed}/js/3.9.1-raven.min.js (100%) rename {static/assets => assets/static/managed}/js/4.1.1-masonry.pkgd.min.js (100%) rename {static/assets => assets/static/managed}/js/5.4-haml.js (100%) rename {static/assets => assets/static/managed}/js/assets.txt (100%) rename {static/assets => assets/static/managed}/js/bootstrap-tagsinput.min.js.map (100%) rename {static/assets => assets/static/managed}/js/haml.map (100%) rename {static/assets => assets/static/managed}/js/jquery.min.map (100%) rename {static/assets => assets/static/managed}/js/js.cookie.min.js.map (100%) rename {static/assets => assets/static/managed}/js/raven.min.js.map (100%) rename {static/assets => assets/static/managed}/js/underscore-min.map (100%) rename {static => assets/static}/progress.js (100%) rename {static => assets/static}/querystring.js (100%) rename {static => assets/static}/summary.js (100%) rename {static => assets/static}/unsee.js (100%) rename {static => assets/static}/watchdog.js (100%) rename {templates => assets/templates}/errors.haml (100%) rename {templates => assets/templates}/groups.haml (100%) rename {templates => assets/templates}/help.html (99%) rename {templates => assets/templates}/index.html (95%) rename {templates => assets/templates}/js.html (100%) rename {templates => assets/templates}/modal.haml (100%) rename {templates => assets/templates}/summary.haml (100%) create mode 100644 bindata_assetfs.go create mode 160000 vendor/github.com/elazarl/go-bindata-assetfs create mode 160000 vendor/github.com/gin-contrib/static diff --git a/.gitmodules b/.gitmodules index afcb44adf..7de45851f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,54 +13,54 @@ [submodule "vendor/github.com/gin-gonic/gin"] path = vendor/github.com/gin-gonic/gin url = https://github.com/gin-gonic/gin -[submodule "vendor/github.com/golang/protobuf"] - path = vendor/github.com/golang/protobuf - url = https://github.com/golang/protobuf [submodule "vendor/github.com/hansrodtang/randomcolor"] path = vendor/github.com/hansrodtang/randomcolor url = https://github.com/hansrodtang/randomcolor [submodule "vendor/github.com/kelseyhightower/envconfig"] path = vendor/github.com/kelseyhightower/envconfig url = https://github.com/kelseyhightower/envconfig -[submodule "vendor/github.com/manucorporat/sse"] - path = vendor/github.com/manucorporat/sse - url = https://github.com/manucorporat/sse -[submodule "vendor/github.com/mattn/go-isatty"] - path = vendor/github.com/mattn/go-isatty - url = https://github.com/mattn/go-isatty [submodule "vendor/github.com/patrickmn/go-cache"] path = vendor/github.com/patrickmn/go-cache url = https://github.com/patrickmn/go-cache -[submodule "vendor/golang.org/x/net"] - path = vendor/golang.org/x/net - url = https://go.googlesource.com/net -[submodule "vendor/gopkg.in/go-playground/validator.v8"] - path = vendor/gopkg.in/go-playground/validator.v8 - url = https://gopkg.in/go-playground/validator.v8 -[submodule "vendor/gopkg.in/yaml.v2"] - path = vendor/gopkg.in/yaml.v2 - url = https://gopkg.in/yaml.v2 -[submodule "vendor/github.com/certifi/gocertifi"] - path = vendor/github.com/certifi/gocertifi - url = https://github.com/certifi/gocertifi [submodule "vendor/github.com/getsentry/raven-go"] path = vendor/github.com/getsentry/raven-go url = https://github.com/getsentry/raven-go [submodule "vendor/github.com/gin-gonic/contrib"] path = vendor/github.com/gin-gonic/contrib url = https://github.com/gin-gonic/contrib -[submodule "vendor/github.com/beorn7/perks"] - path = vendor/github.com/beorn7/perks - url = https://github.com/beorn7/perks -[submodule "vendor/github.com/matttproud/golang_protobuf_extensions"] - path = vendor/github.com/matttproud/golang_protobuf_extensions - url = https://github.com/matttproud/golang_protobuf_extensions [submodule "vendor/github.com/mcuadros/go-gin-prometheus"] path = vendor/github.com/mcuadros/go-gin-prometheus url = https://github.com/mcuadros/go-gin-prometheus [submodule "vendor/github.com/prometheus/client_golang"] path = vendor/github.com/prometheus/client_golang url = https://github.com/prometheus/client_golang +[submodule "vendor/gopkg.in/jarcoal/httpmock.v1"] + path = vendor/gopkg.in/jarcoal/httpmock.v1 + url = https://gopkg.in/jarcoal/httpmock.v1 +[submodule "vendor/github.com/elazarl/go-bindata-assetfs"] + path = vendor/github.com/elazarl/go-bindata-assetfs + url = https://github.com/elazarl/go-bindata-assetfs +[submodule "vendor/github.com/gin-contrib/static"] + path = vendor/github.com/gin-contrib/static + url = https://github.com/gin-contrib/static +[submodule "vendor/github.com/beorn7/perks"] + path = vendor/github.com/beorn7/perks + url = https://github.com/beorn7/perks +[submodule "vendor/github.com/certifi/gocertifi"] + path = vendor/github.com/certifi/gocertifi + url = https://github.com/certifi/gocertifi +[submodule "vendor/github.com/golang/protobuf"] + path = vendor/github.com/golang/protobuf + url = https://github.com/golang/protobuf +[submodule "vendor/github.com/manucorporat/sse"] + path = vendor/github.com/manucorporat/sse + url = https://github.com/manucorporat/sse +[submodule "vendor/github.com/mattn/go-isatty"] + path = vendor/github.com/mattn/go-isatty + url = https://github.com/mattn/go-isatty +[submodule "vendor/github.com/matttproud/golang_protobuf_extensions"] + path = vendor/github.com/matttproud/golang_protobuf_extensions + url = https://github.com/matttproud/golang_protobuf_extensions [submodule "vendor/github.com/prometheus/client_model"] path = vendor/github.com/prometheus/client_model url = https://github.com/prometheus/client_model @@ -70,6 +70,12 @@ [submodule "vendor/github.com/prometheus/procfs"] path = vendor/github.com/prometheus/procfs url = https://github.com/prometheus/procfs -[submodule "vendor/gopkg.in/jarcoal/httpmock.v1"] - path = vendor/gopkg.in/jarcoal/httpmock.v1 - url = https://gopkg.in/jarcoal/httpmock.v1 +[submodule "vendor/golang.org/x/net"] + path = vendor/golang.org/x/net + url = https://go.googlesource.com/net +[submodule "vendor/gopkg.in/go-playground/validator.v8"] + path = vendor/gopkg.in/go-playground/validator.v8 + url = https://gopkg.in/go-playground/validator.v8 +[submodule "vendor/gopkg.in/yaml.v2"] + path = vendor/gopkg.in/yaml.v2 + url = https://gopkg.in/yaml.v2 diff --git a/Dockerfile b/Dockerfile index 7849dd84c..4809874c1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.7.5-alpine3.5 +FROM golang:alpine3.5 ADD . /go/src/github.com/cloudflare/unsee @@ -8,9 +8,6 @@ RUN go install \ -ldflags "-X main.version=${VERSION:-dev}" \ github.com/cloudflare/unsee -RUN mv /go/src/github.com/cloudflare/unsee/static \ - /go/src/github.com/cloudflare/unsee/templates \ - /go/ && \ - rm -fr /go/src +RUN rm -fr /go/src CMD ["unsee"] diff --git a/Makefile b/Makefile index 3817f5f2e..e8a96b61b 100644 --- a/Makefile +++ b/Makefile @@ -6,16 +6,33 @@ ALERTMANAGER_URI := https://raw.githubusercontent.com/prymitive/alertmanager-dem # Listen port when running locally PORT := 8080 -SOURCES := $(wildcard *.go) $(wildcard */*.go) +SOURCES := $(wildcard *.go) $(wildcard */*.go) +ASSET_SOURCES := $(wildcard assets/*/* assets/*/*/*) + +GO_BINDATA_MODE := prod +ifdef DEBUG + GO_BINDATA_FLAGS = -debug + GO_BINDATA_MODE = debug +endif .DEFAULT_GOAL := $(NAME) .build/deps.ok: .gitmodules git submodule update --init --recursive + go get -u github.com/jteeuwen/go-bindata/... + go get -u github.com/elazarl/go-bindata-assetfs/... mkdir -p .build touch $@ -$(NAME): .build/deps.ok $(SOURCES) +.build/bindata_assetfs.%: + mkdir -p .build + rm -f .build/bindata_assetfs.* + touch $@ + +bindata_assetfs.go: .build/deps.ok .build/bindata_assetfs.$(GO_BINDATA_MODE) $(ASSET_SOURCES) + go-bindata-assetfs $(GO_BINDATA_FLAGS) -prefix assets -nometadata assets/templates/... assets/static/... + +$(NAME): .build/deps.ok bindata_assetfs.go $(SOURCES) go build -ldflags "-X main.version=$(VERSION)" .PHONY: run @@ -38,15 +55,15 @@ run-docker: docker-image .PHONY: lint lint: .build/deps.ok - @golint ./... | (grep -v ^vendor/ || true) + @golint ./... | (egrep -v "^vendor/|^bindata_assetfs.go" || true) .PHONY: test -test: lint +test: lint bindata_assetfs.go @go test -cover `go list ./... | grep -v /vendor/` #======================== asset helper targets ================================= -ASSETS_DIR := $(CURDIR)/static/assets +ASSETS_DIR := $(CURDIR)/assets/static/managed CDNJS_PREFIX := https://cdnjs.cloudflare.com/ajax/libs %.js: diff --git a/assets.go b/assets.go index 4add31cf1..8d6e49388 100644 --- a/assets.go +++ b/assets.go @@ -1,35 +1,97 @@ package main import ( + "errors" "fmt" - "io/ioutil" "strings" log "github.com/Sirupsen/logrus" + assetfs "github.com/elazarl/go-bindata-assetfs" + "html/template" + "net/http" ) -// ReadAssets will read assets.txt file in given directory and return a list +type binaryFileSystem struct { + fs http.FileSystem +} + +func (b *binaryFileSystem) Open(name string) (http.File, error) { + return b.fs.Open(name) +} + +func (b *binaryFileSystem) Exists(prefix string, filepath string) bool { + if p := strings.TrimPrefix(filepath, prefix); len(p) < len(filepath) { + if _, err := b.fs.Open(p); err != nil { + return false + } + return true + } + return false +} + +func newBinaryFileSystem(root string) *binaryFileSystem { + fs := &assetfs.AssetFS{ + Asset: Asset, + // Don't render directory index, return 404 for /static/ requests) + AssetDir: func(path string) ([]string, error) { return nil, errors.New("Not found") }, + Prefix: root, + } + return &binaryFileSystem{ + fs, + } +} + +// readAssets will read assets.txt file in given directory and return a list // of file names in that file // assets.txt contains a list of external js of css files that are mirrored // in static/assets directory that should be loaded in the browser // this way we don't have to maintain this list in the Makefile that does // the mirroring and in the template -func ReadAssets(kind string) []string { - filename := fmt.Sprintf("./static/assets/%s/assets.txt", kind) - content, err := ioutil.ReadFile(filename) +func readAssets(kind string) []string { + indexPath := fmt.Sprintf("static/managed/%s/assets.txt", kind) + assetIndex, err := Asset(indexPath) if err != nil { - log.Error(err.Error()) + log.Error(err) return []string{} } - - lines := strings.Split(string(content), "\n") - ret := []string{} - for _, l := range lines { + for _, l := range strings.Split(string(assetIndex), "\n") { if l != "" { ret = append(ret, l) } } - return ret } + +// load all templates from binary asset resource +// this function will iterate all files with given prefix (e.g. /templates/) +// and return Template instance with all templates loaded +func loadTemplates(prefix string) *template.Template { + var t *template.Template + for _, filename := range AssetNames() { + if strings.HasPrefix(filename, prefix) { + templateContent, err := Asset(filename) + if err != nil { + log.Fatal(err) + } + var tmpl *template.Template + if t == nil { + // if template wasn't yet initialized do it here + t = template.New(filename) + } + if filename == t.Name() { + tmpl = t + } else { + // if we already have an instance of template.Template then + // add a new file to it + tmpl = t.New(filename) + } + _, err = tmpl.Parse(string(templateContent)) + if err != nil { + log.Fatal(err) + return nil + } + } + } + return t +} diff --git a/static/alerts.js b/assets/static/alerts.js similarity index 100% rename from static/alerts.js rename to assets/static/alerts.js diff --git a/static/autocomplete.js b/assets/static/autocomplete.js similarity index 100% rename from static/autocomplete.js rename to assets/static/autocomplete.js diff --git a/static/base.css b/assets/static/base.css similarity index 100% rename from static/base.css rename to assets/static/base.css diff --git a/static/colors.js b/assets/static/colors.js similarity index 100% rename from static/colors.js rename to assets/static/colors.js diff --git a/static/config.js b/assets/static/config.js similarity index 100% rename from static/config.js rename to assets/static/config.js diff --git a/static/counter.js b/assets/static/counter.js similarity index 100% rename from static/counter.js rename to assets/static/counter.js diff --git a/static/favicon.ico b/assets/static/favicon.ico similarity index 100% rename from static/favicon.ico rename to assets/static/favicon.ico diff --git a/static/filters.js b/assets/static/filters.js similarity index 100% rename from static/filters.js rename to assets/static/filters.js diff --git a/static/grid.js b/assets/static/grid.js similarity index 100% rename from static/grid.js rename to assets/static/grid.js diff --git a/static/jquery.typing-0.2.0.js b/assets/static/jquery.typing-0.2.0.js similarity index 100% rename from static/jquery.typing-0.2.0.js rename to assets/static/jquery.typing-0.2.0.js diff --git a/static/lru.js b/assets/static/lru.js similarity index 100% rename from static/lru.js rename to assets/static/lru.js diff --git a/static/assets/css/0.1.2-loaders.min.css b/assets/static/managed/css/0.1.2-loaders.min.css similarity index 100% rename from static/assets/css/0.1.2-loaders.min.css rename to assets/static/managed/css/0.1.2-loaders.min.css diff --git a/static/assets/css/0.2.0-nprogress.min.css b/assets/static/managed/css/0.2.0-nprogress.min.css similarity index 100% rename from static/assets/css/0.2.0-nprogress.min.css rename to assets/static/managed/css/0.2.0-nprogress.min.css diff --git a/static/assets/css/0.8.0-bootstrap-tagsinput-typeahead.css b/assets/static/managed/css/0.8.0-bootstrap-tagsinput-typeahead.css similarity index 100% rename from static/assets/css/0.8.0-bootstrap-tagsinput-typeahead.css rename to assets/static/managed/css/0.8.0-bootstrap-tagsinput-typeahead.css diff --git a/static/assets/css/0.8.0-bootstrap-tagsinput.css b/assets/static/managed/css/0.8.0-bootstrap-tagsinput.css similarity index 100% rename from static/assets/css/0.8.0-bootstrap-tagsinput.css rename to assets/static/managed/css/0.8.0-bootstrap-tagsinput.css diff --git a/static/assets/css/3.3.2-bootstrap-switch.min.css b/assets/static/managed/css/3.3.2-bootstrap-switch.min.css similarity index 100% rename from static/assets/css/3.3.2-bootstrap-switch.min.css rename to assets/static/managed/css/3.3.2-bootstrap-switch.min.css diff --git a/static/assets/css/3.3.7-bootstrap.min.css b/assets/static/managed/css/3.3.7-bootstrap.min.css similarity index 100% rename from static/assets/css/3.3.7-bootstrap.min.css rename to assets/static/managed/css/3.3.7-bootstrap.min.css diff --git a/static/assets/css/4.7.0-font-awesome.min.css b/assets/static/managed/css/4.7.0-font-awesome.min.css similarity index 100% rename from static/assets/css/4.7.0-font-awesome.min.css rename to assets/static/managed/css/4.7.0-font-awesome.min.css diff --git a/static/assets/css/assets.txt b/assets/static/managed/css/assets.txt similarity index 100% rename from static/assets/css/assets.txt rename to assets/static/managed/css/assets.txt diff --git a/static/assets/fonts/FontAwesome.otf b/assets/static/managed/fonts/FontAwesome.otf similarity index 100% rename from static/assets/fonts/FontAwesome.otf rename to assets/static/managed/fonts/FontAwesome.otf diff --git a/static/assets/fonts/fontawesome-webfont.eot b/assets/static/managed/fonts/fontawesome-webfont.eot similarity index 100% rename from static/assets/fonts/fontawesome-webfont.eot rename to assets/static/managed/fonts/fontawesome-webfont.eot diff --git a/static/assets/fonts/fontawesome-webfont.svg b/assets/static/managed/fonts/fontawesome-webfont.svg similarity index 100% rename from static/assets/fonts/fontawesome-webfont.svg rename to assets/static/managed/fonts/fontawesome-webfont.svg diff --git a/static/assets/fonts/fontawesome-webfont.ttf b/assets/static/managed/fonts/fontawesome-webfont.ttf similarity index 100% rename from static/assets/fonts/fontawesome-webfont.ttf rename to assets/static/managed/fonts/fontawesome-webfont.ttf diff --git a/static/assets/fonts/fontawesome-webfont.woff b/assets/static/managed/fonts/fontawesome-webfont.woff similarity index 100% rename from static/assets/fonts/fontawesome-webfont.woff rename to assets/static/managed/fonts/fontawesome-webfont.woff diff --git a/static/assets/fonts/fontawesome-webfont.woff2 b/assets/static/managed/fonts/fontawesome-webfont.woff2 similarity index 100% rename from static/assets/fonts/fontawesome-webfont.woff2 rename to assets/static/managed/fonts/fontawesome-webfont.woff2 diff --git a/static/assets/js/0.1.2-loaders.css.min.js b/assets/static/managed/js/0.1.2-loaders.css.min.js similarity index 100% rename from static/assets/js/0.1.2-loaders.css.min.js rename to assets/static/managed/js/0.1.2-loaders.css.min.js diff --git a/static/assets/js/0.11.1-typeahead.bundle.min.js b/assets/static/managed/js/0.11.1-typeahead.bundle.min.js similarity index 100% rename from static/assets/js/0.11.1-typeahead.bundle.min.js rename to assets/static/managed/js/0.11.1-typeahead.bundle.min.js diff --git a/static/assets/js/0.2.0-nprogress.min.js b/assets/static/managed/js/0.2.0-nprogress.min.js similarity index 100% rename from static/assets/js/0.2.0-nprogress.min.js rename to assets/static/managed/js/0.2.0-nprogress.min.js diff --git a/static/assets/js/0.3.10-favico.min.js b/assets/static/managed/js/0.3.10-favico.min.js similarity index 100% rename from static/assets/js/0.3.10-favico.min.js rename to assets/static/managed/js/0.3.10-favico.min.js diff --git a/static/assets/js/0.4.0-sha1.min.js b/assets/static/managed/js/0.4.0-sha1.min.js similarity index 100% rename from static/assets/js/0.4.0-sha1.min.js rename to assets/static/managed/js/0.4.0-sha1.min.js diff --git a/static/assets/js/0.8.0-bootstrap-tagsinput.min.js b/assets/static/managed/js/0.8.0-bootstrap-tagsinput.min.js similarity index 100% rename from static/assets/js/0.8.0-bootstrap-tagsinput.min.js rename to assets/static/managed/js/0.8.0-bootstrap-tagsinput.min.js diff --git a/static/assets/js/1.5.16-clipboard.min.js b/assets/static/managed/js/1.5.16-clipboard.min.js similarity index 100% rename from static/assets/js/1.5.16-clipboard.min.js rename to assets/static/managed/js/1.5.16-clipboard.min.js diff --git a/static/assets/js/1.8.3-underscore-min.js b/assets/static/managed/js/1.8.3-underscore-min.js similarity index 100% rename from static/assets/js/1.8.3-underscore-min.js rename to assets/static/managed/js/1.8.3-underscore-min.js diff --git a/static/assets/js/2.1.3-js.cookie.min.js b/assets/static/managed/js/2.1.3-js.cookie.min.js similarity index 100% rename from static/assets/js/2.1.3-js.cookie.min.js rename to assets/static/managed/js/2.1.3-js.cookie.min.js diff --git a/static/assets/js/2.17.1-moment.min.js b/assets/static/managed/js/2.17.1-moment.min.js similarity index 100% rename from static/assets/js/2.17.1-moment.min.js rename to assets/static/managed/js/2.17.1-moment.min.js diff --git a/static/assets/js/2.2.4-jquery.min.js b/assets/static/managed/js/2.2.4-jquery.min.js similarity index 100% rename from static/assets/js/2.2.4-jquery.min.js rename to assets/static/managed/js/2.2.4-jquery.min.js diff --git a/static/assets/js/2.4.0-underscore.string.min.js b/assets/static/managed/js/2.4.0-underscore.string.min.js similarity index 100% rename from static/assets/js/2.4.0-underscore.string.min.js rename to assets/static/managed/js/2.4.0-underscore.string.min.js diff --git a/static/assets/js/2.4.2-isInViewport.min.js b/assets/static/managed/js/2.4.2-isInViewport.min.js similarity index 100% rename from static/assets/js/2.4.2-isInViewport.min.js rename to assets/static/managed/js/2.4.2-isInViewport.min.js diff --git a/static/assets/js/3.3.2-bootstrap-switch.min.js b/assets/static/managed/js/3.3.2-bootstrap-switch.min.js similarity index 100% rename from static/assets/js/3.3.2-bootstrap-switch.min.js rename to assets/static/managed/js/3.3.2-bootstrap-switch.min.js diff --git a/static/assets/js/3.3.7-bootstrap.min.js b/assets/static/managed/js/3.3.7-bootstrap.min.js similarity index 100% rename from static/assets/js/3.3.7-bootstrap.min.js rename to assets/static/managed/js/3.3.7-bootstrap.min.js diff --git a/static/assets/js/3.9.1-raven.min.js b/assets/static/managed/js/3.9.1-raven.min.js similarity index 100% rename from static/assets/js/3.9.1-raven.min.js rename to assets/static/managed/js/3.9.1-raven.min.js diff --git a/static/assets/js/4.1.1-masonry.pkgd.min.js b/assets/static/managed/js/4.1.1-masonry.pkgd.min.js similarity index 100% rename from static/assets/js/4.1.1-masonry.pkgd.min.js rename to assets/static/managed/js/4.1.1-masonry.pkgd.min.js diff --git a/static/assets/js/5.4-haml.js b/assets/static/managed/js/5.4-haml.js similarity index 100% rename from static/assets/js/5.4-haml.js rename to assets/static/managed/js/5.4-haml.js diff --git a/static/assets/js/assets.txt b/assets/static/managed/js/assets.txt similarity index 100% rename from static/assets/js/assets.txt rename to assets/static/managed/js/assets.txt diff --git a/static/assets/js/bootstrap-tagsinput.min.js.map b/assets/static/managed/js/bootstrap-tagsinput.min.js.map similarity index 100% rename from static/assets/js/bootstrap-tagsinput.min.js.map rename to assets/static/managed/js/bootstrap-tagsinput.min.js.map diff --git a/static/assets/js/haml.map b/assets/static/managed/js/haml.map similarity index 100% rename from static/assets/js/haml.map rename to assets/static/managed/js/haml.map diff --git a/static/assets/js/jquery.min.map b/assets/static/managed/js/jquery.min.map similarity index 100% rename from static/assets/js/jquery.min.map rename to assets/static/managed/js/jquery.min.map diff --git a/static/assets/js/js.cookie.min.js.map b/assets/static/managed/js/js.cookie.min.js.map similarity index 100% rename from static/assets/js/js.cookie.min.js.map rename to assets/static/managed/js/js.cookie.min.js.map diff --git a/static/assets/js/raven.min.js.map b/assets/static/managed/js/raven.min.js.map similarity index 100% rename from static/assets/js/raven.min.js.map rename to assets/static/managed/js/raven.min.js.map diff --git a/static/assets/js/underscore-min.map b/assets/static/managed/js/underscore-min.map similarity index 100% rename from static/assets/js/underscore-min.map rename to assets/static/managed/js/underscore-min.map diff --git a/static/progress.js b/assets/static/progress.js similarity index 100% rename from static/progress.js rename to assets/static/progress.js diff --git a/static/querystring.js b/assets/static/querystring.js similarity index 100% rename from static/querystring.js rename to assets/static/querystring.js diff --git a/static/summary.js b/assets/static/summary.js similarity index 100% rename from static/summary.js rename to assets/static/summary.js diff --git a/static/unsee.js b/assets/static/unsee.js similarity index 100% rename from static/unsee.js rename to assets/static/unsee.js diff --git a/static/watchdog.js b/assets/static/watchdog.js similarity index 100% rename from static/watchdog.js rename to assets/static/watchdog.js diff --git a/templates/errors.haml b/assets/templates/errors.haml similarity index 100% rename from templates/errors.haml rename to assets/templates/errors.haml diff --git a/templates/groups.haml b/assets/templates/groups.haml similarity index 100% rename from templates/groups.haml rename to assets/templates/groups.haml diff --git a/templates/help.html b/assets/templates/help.html similarity index 99% rename from templates/help.html rename to assets/templates/help.html index 9f65cacb8..1bb8b185d 100644 --- a/templates/help.html +++ b/assets/templates/help.html @@ -13,7 +13,7 @@ (◕︵◕) {{ range .CSSFiles }} - {{- end }} + {{- end }} diff --git a/templates/index.html b/assets/templates/index.html similarity index 95% rename from templates/index.html rename to assets/templates/index.html index 38c5b7fd7..9f0886520 100644 --- a/templates/index.html +++ b/assets/templates/index.html @@ -13,7 +13,7 @@ (◕︵◕) {{ range .CSSFiles }} - + {{- end }} @@ -144,10 +144,10 @@ {{ range .JSFiles }} - + {{- end }} - {{ template "js.html" .}} + {{ template "templates/js.html" .}}