Statically compile assets into binary
This commit is contained in:
parent
f188f3357d
commit
034ab0da0c
10
Makefile
10
Makefile
|
@ -14,6 +14,10 @@
|
|||
GO := GO15VENDOREXPERIMENT=1 go
|
||||
pkgs = $(shell $(GO) list ./... | grep -v /vendor/)
|
||||
|
||||
ifdef DEBUG
|
||||
bindata_flags = -debug
|
||||
endif
|
||||
|
||||
all: format build test
|
||||
|
||||
test:
|
||||
|
@ -28,9 +32,13 @@ vet:
|
|||
@echo ">> vetting code"
|
||||
@$(GO) vet $(pkgs)
|
||||
|
||||
build:
|
||||
build: assets
|
||||
@echo ">> building binaries"
|
||||
@./scripts/build.sh
|
||||
|
||||
assets:
|
||||
@echo ">> writing assets"
|
||||
@$(GO) get -u github.com/jteeuwen/go-bindata/...
|
||||
@go-bindata $(bindata_flags) -pkg ui -o ui/bindata.go ui/...
|
||||
|
||||
.PHONY: all format build test vet docker
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en" ng-app="am">
|
||||
<head>
|
||||
<script src="/static/jquery.min.js"></script>
|
||||
<script src="/static/moment.min.js"></script>
|
||||
<script src="/lib/jquery.min.js"></script>
|
||||
<script src="/lib/moment.min.js"></script>
|
||||
|
||||
<script src="/static/angular.min.js"></script>
|
||||
<script src="/static/angular-sanitize.min.js"></script>
|
||||
<script src="/static/angular-route.min.js"></script>
|
||||
<script src="/static/angular-resource.min.js"></script>
|
||||
<script src="/static/angular-moment.min.js"></script>
|
||||
<script src="/lib/angular.min.js"></script>
|
||||
<script src="/lib/angular-sanitize.min.js"></script>
|
||||
<script src="/lib/angular-route.min.js"></script>
|
||||
<script src="/lib/angular-resource.min.js"></script>
|
||||
<script src="/lib/angular-moment.min.js"></script>
|
||||
|
||||
<script src="/app/js/app.js"></script>
|
||||
|
||||
<link rel="stylesheet" href="/static/kube.min.css">
|
||||
<link rel="stylesheet" href="/lib/kube.min.css">
|
||||
<link rel="stylesheet" href="/app/css/main.css">
|
||||
|
||||
<title>AlertManager – Prometheus</title>
|
||||
|
|
51
web.go
51
web.go
|
@ -14,30 +14,47 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"bytes"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/prometheus/common/log"
|
||||
"github.com/prometheus/common/route"
|
||||
|
||||
"github.com/prometheus/alertmanager/ui"
|
||||
)
|
||||
|
||||
func serveAsset(w http.ResponseWriter, req *http.Request, fp string) {
|
||||
info, err := ui.AssetInfo(fp)
|
||||
if err != nil {
|
||||
log.Warn("Could not get file: ", err)
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
file, err := ui.Asset(fp)
|
||||
if err != nil {
|
||||
if err != io.EOF {
|
||||
log.With("file", fp).Warn("Could not get file: ", err)
|
||||
}
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
http.ServeContent(w, req, info.Name(), info.ModTime(), bytes.NewReader(file))
|
||||
}
|
||||
|
||||
// RegisterWeb registers handlers to serve files for the web interface.
|
||||
func RegisterWeb(r *route.Router) {
|
||||
|
||||
r.Get("/app/*filepath", route.FileServe("ui/app/"))
|
||||
r.Get("/static/*filepath", route.FileServe("ui/lib/"))
|
||||
|
||||
r.Get("/app/*filepath", func(w http.ResponseWriter, req *http.Request) {
|
||||
fp := route.Param(route.Context(req), "filepath")
|
||||
serveAsset(w, req, filepath.Join("ui/app", fp))
|
||||
})
|
||||
r.Get("/lib/*filepath", func(w http.ResponseWriter, req *http.Request) {
|
||||
fp := route.Param(route.Context(req), "filepath")
|
||||
serveAsset(w, req, filepath.Join("ui/lib", fp))
|
||||
})
|
||||
r.Get("/", func(w http.ResponseWriter, req *http.Request) {
|
||||
f, err := os.Open("ui/app/index.html")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
b, err := ioutil.ReadAll(f)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
w.Write(b)
|
||||
serveAsset(w, req, "ui/app/index.html")
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue