Skip to content

Commit

Permalink
Merge pull request #885 from fabiolb/feature/move_to_go_embed_for_static
Browse files Browse the repository at this point in the history
Moved admin UI assets to use go embed
  • Loading branch information
KTruesdellENA authored Jul 14, 2022
2 parents 8b2066c + c7f9e43 commit 4d81cab
Show file tree
Hide file tree
Showing 32 changed files with 141 additions and 1,058 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ jobs:
build:
strategy:
matrix:
go-version: [ 1.18.x, 1.17.x ]
os: [ ubuntu-latest ]
go: [ '1.18.4', '1.17.12' ]
runs-on: ${{matrix.os}}
steps:
- name: Install Go
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
go-version: ${{ matrix.go }}
- name: Set Hosts
run: |
echo "127.0.0.1 example.com example2.com" | sudo tee -a /etc/hosts
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Test
run: |
export PATH=$PATH:$HOME/bin
Expand Down
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
FROM golang:1.18-alpine3.15 AS build
FROM golang:1.17-alpine3.16 AS build

ARG consul_version=1.8.2
ARG consul_version=1.12.3
ADD https://releases.hashicorp.com/consul/${consul_version}/consul_${consul_version}_linux_amd64.zip /usr/local/bin
RUN cd /usr/local/bin && unzip consul_${consul_version}_linux_amd64.zip

ARG vault_version=1.5.0
ARG vault_version=1.11.0
ADD https://releases.hashicorp.com/vault/${vault_version}/vault_${vault_version}_linux_amd64.zip /usr/local/bin
RUN cd /usr/local/bin && unzip vault_${vault_version}_linux_amd64.zip

Expand All @@ -14,7 +14,7 @@ COPY . .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go test -mod=vendor -trimpath -ldflags "-s -w" ./...
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -mod=vendor -trimpath -ldflags "-s -w"

FROM alpine:3.15
FROM alpine:3.16
RUN apk update && apk add --no-cache ca-certificates
COPY --from=build /src/fabio /usr/bin
ADD fabio.properties /etc/fabio/fabio.properties
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile-goreleaser
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM alpine:3.15
FROM alpine:3.16
RUN apk update && apk add --no-cache ca-certificates
COPY fabio /usr/bin
ADD fabio.properties /etc/fabio/fabio.properties
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ GOVERSION ?= $(shell go version | awk '{print $$3;}')
GORELEASER ?= $(shell which goreleaser)

# pin versions for CI builds
CI_CONSUL_VERSION ?= 1.8.4
CI_VAULT_VERSION ?= 1.5.2
CI_CONSUL_VERSION ?= 1.12.3
CI_VAULT_VERSION ?= 1.11.0
CI_HUGO_VERSION ?= 0.101.0

BETA_OSES = linux darwin
Expand All @@ -31,7 +31,7 @@ all: test

# help prints a help screen
help:
@echo "generate - go generate"
@echo "generate - go generate (use it when updating admin ui assets)"
@echo "build - go build"
@echo "install - go install"
@echo "test - go test"
Expand All @@ -50,7 +50,7 @@ generate: clean-adm

# build compiles fabio and the test dependencies
.PHONY: build
build: generate gofmt
build: gofmt
go build $(GOFLAGS)

# test builds and runs the tests
Expand Down
11 changes: 1 addition & 10 deletions admin/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ import (

"github.com/fabiolb/fabio/admin/api"
"github.com/fabiolb/fabio/admin/ui"
_ "github.com/fabiolb/fabio/admin/ui/statik"
"github.com/fabiolb/fabio/config"
"github.com/fabiolb/fabio/proxy"
"github.com/rakyll/statik/fs"
)

// Server provides the HTTP server for the admin UI and API.
Expand Down Expand Up @@ -68,14 +66,7 @@ func (s *Server) handler() http.Handler {
mux.Handle("/routes", &ui.RoutesHandler{Color: s.Color, Title: s.Title, Version: s.Version})
mux.HandleFunc("/health", handleHealth)

statikFS, err := fs.New()
if err != nil {
// This error is always a result of invalid, generated zip data. That
// should never happen and would let TestAdminServerAccess fail before
// fabio is released.
panic(err)
}
mux.Handle("/assets/", http.StripPrefix("/assets/", http.FileServer(statikFS)))
mux.Handle("/assets/", http.FileServer(http.FS(ui.Static)))
mux.HandleFunc("/favicon.ico", http.NotFound)

mux.Handle("/", http.RedirectHandler("/routes", http.StatusSeeOther))
Expand Down
2 changes: 0 additions & 2 deletions admin/ui/assets/cdnjs.cloudflare.com/.gitignore

This file was deleted.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions admin/ui/assets/code.jquery.com/.gitignore

This file was deleted.

2 changes: 2 additions & 0 deletions admin/ui/assets/code.jquery.com/jquery-3.6.0.min.js

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions admin/ui/assets/fonts/.gitignore

This file was deleted.

Binary file added admin/ui/assets/fonts/MaterialIcons-Regular.eot
Binary file not shown.
Binary file added admin/ui/assets/fonts/MaterialIcons-Regular.ttf
Binary file not shown.
Binary file added admin/ui/assets/fonts/MaterialIcons-Regular.woff
Binary file not shown.
Binary file added admin/ui/assets/fonts/MaterialIcons-Regular.woff2
Binary file not shown.
36 changes: 36 additions & 0 deletions admin/ui/assets/fonts/material-icons.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
@font-face {
font-family: 'Material Icons';
font-style: normal;
font-weight: 400;
src: url(MaterialIcons-Regular.eot); /* For IE6-8 */
src: local('Material Icons'),
local('MaterialIcons-Regular'),
url(MaterialIcons-Regular.woff2) format('woff2'),
url(MaterialIcons-Regular.woff) format('woff'),
url(MaterialIcons-Regular.ttf) format('truetype');
}

.material-icons {
font-family: 'Material Icons';
font-weight: normal;
font-style: normal;
font-size: 24px; /* Preferred icon size */
display: inline-block;
line-height: 1;
text-transform: none;
letter-spacing: normal;
word-wrap: normal;
white-space: nowrap;
direction: ltr;

/* Support for all WebKit browsers. */
-webkit-font-smoothing: antialiased;
/* Support for Safari and Chrome. */
text-rendering: optimizeLegibility;

/* Support for Firefox. */
-moz-osx-font-smoothing: grayscale;

/* Support for IE. */
font-feature-settings: 'liga';
}
5 changes: 3 additions & 2 deletions admin/ui/generate.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package ui

//go:generate rm -rf assets/code.jquery.com
//go:generate rm -rf assets/cdnjs.cloudflare.com
//go:generate wget -pP assets https://code.jquery.com/jquery-3.6.0.min.js
//go:generate wget -pP assets https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js
//go:generate wget -pP assets https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css

// https://google.github.io/material-design-icons/#setup-method-2-self-hosting
//go:generate rm -rf assets/fonts
//go:generate wget -nH -nd -pP assets/fonts https://raw.githubusercontent.com/google/material-design-icons/3.0.1/iconfont/MaterialIcons-Regular.ttf
//go:generate wget -nH -nd -pP assets/fonts https://raw.githubusercontent.com/google/material-design-icons/3.0.1/iconfont/MaterialIcons-Regular.eot
//go:generate wget -nH -nd -pP assets/fonts https://raw.githubusercontent.com/google/material-design-icons/3.0.1/iconfont/MaterialIcons-Regular.woff
//go:generate wget -nH -nd -pP assets/fonts https://raw.githubusercontent.com/google/material-design-icons/3.0.1/iconfont/MaterialIcons-Regular.woff2
//go:generate wget -nH -nd -pP assets/fonts https://raw.githubusercontent.com/google/material-design-icons/3.0.1/iconfont/material-icons.css

//go:generate go run ../../vendor/github.com/rakyll/statik/statik.go -f -src assets
6 changes: 6 additions & 0 deletions admin/ui/static.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package ui

import "embed"

//go:embed assets/*
var Static embed.FS
12 changes: 0 additions & 12 deletions admin/ui/statik/statik.go

This file was deleted.

3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ require (
github.com/pierrec/lz4 v2.5.2+incompatible // indirect
github.com/pkg/profile v1.5.0
github.com/prometheus/client_golang v1.4.0
github.com/rakyll/statik v0.1.7
github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 // indirect
github.com/rogpeppe/fastuuid v1.2.0
github.com/sergi/go-diff v1.2.0
Expand All @@ -59,4 +58,4 @@ require (
gopkg.in/yaml.v2 v2.3.0 // indirect
)

go 1.13
go 1.16
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,6 @@ github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
github.com/prometheus/procfs v0.0.8 h1:+fpWZdT24pJBiqJdAwYBjPSk+5YmQzYNPYzQsdzLkt8=
github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A=
github.com/rakyll/statik v0.1.7 h1:OF3QCZUuyPxuGEP7B4ypUa7sB/iHtqOTDYZXGM8KOdQ=
github.com/rakyll/statik v0.1.7/go.mod h1:AlZONWzMtEnMs7W4e/1LURLiI49pIMmp6V9Unghqrcc=
github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 h1:MkV+77GLUNo5oJ0jf870itWm3D0Sjh7+Za9gazKc5LQ=
github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/rogpeppe/fastuuid v1.2.0 h1:Ppwyp6VYCF1nvBTXL3trRso7mXMlRrw9ooo375wvi2s=
Expand All @@ -272,8 +270,6 @@ github.com/ryanuber/go-glob v1.0.0 h1:iQh3xXAumdQ+4Ufa5b25cRpC5TYKlno6hsv6Cb3pkB
github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 h1:nn5Wsu0esKSJiIVhscUtVbo7ada43DJhG55ua/hjS5I=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
Expand Down
9 changes: 0 additions & 9 deletions tools.go

This file was deleted.

1 change: 0 additions & 1 deletion vendor/github.com/rakyll/statik/.gitignore

This file was deleted.

16 changes: 0 additions & 16 deletions vendor/github.com/rakyll/statik/.travis.yml

This file was deleted.

Loading

0 comments on commit 4d81cab

Please sign in to comment.