Skip to content

Commit b8c0ad2

Browse files
author
Adrian Cole
committed
Changes from statik to go:embed for examples serving
This reduces build complexity by eliminating a generation step with go:embed. This implicitly reduces tech debt even more because not only were we using a stalled project, statik, but also a fork of it. go:embed is not perfect, as it disallows the file name go.mod. The workaround is to rename it to go.mod_ per golang/go#45197. While this is imperfect an if-statement is a far better punch than a dependency on a fork of a stalled project which also requires a codegen step. Signed-off-by: Adrian Cole <[email protected]>
1 parent 6dbeacb commit b8c0ad2

File tree

21 files changed

+116
-68
lines changed

21 files changed

+116
-68
lines changed

.github/workflows/commit.yaml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ jobs:
4242
docker_buildx: false # Install is flakey. When it, we can install it via docker/setup-buildx-action@v1
4343
timeout-minutes: 20 # fail fast if MacOS install takes too long
4444

45-
- name: "Init on first use"
46-
run: make init
47-
4845
- name: "Verify clean check-in"
4946
run: make check
5047

@@ -79,9 +76,6 @@ jobs:
7976
with:
8077
go-version: '1.16.2'
8178

82-
- name: "Init on first use"
83-
run: make init
84-
8579
- name: "Build the `getenvoy` binary"
8680
run: make bin
8781

@@ -115,6 +109,11 @@ jobs:
115109
- name: "Checkout"
116110
uses: actions/checkout@v2
117111

112+
- name: "Install Go"
113+
uses: actions/setup-go@v2
114+
with:
115+
go-version: '1.16.2'
116+
118117
- name: "Re-use the `getenvoy` binary pre-built by the upstream job"
119118
uses: actions/download-artifact@v2
120119
with:

.github/workflows/release.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ jobs:
9696
- name: "Checkout"
9797
uses: actions/checkout@v2
9898

99+
- name: "Install Go"
100+
uses: actions/setup-go@v2
101+
with:
102+
go-version: '1.16.2'
103+
99104
- name: "Get tag name"
100105
run: | # Trim "v" prefix in the release tag
101106
RELEASE_TAG=${GITHUB_REF#refs/*/}

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,3 @@ dist
33
/getenvoy
44
/build/
55
.idea
6-
7-
# code generated by `github.com/rakyll/statik`
8-
statik.go

.golangci.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,6 @@ issues:
134134
- gosec
135135
- lll
136136

137-
# Exclude lll issues for long lines with go:generate
138-
- linters:
139-
- lll
140-
source: "^//go:generate "
141-
142137
# Independently from option `exclude` we use default exclude patterns,
143138
# it can be disabled by this option. To list all
144139
# excluded by default patterns execute `golangci-lint run --help`.

.goreleaser.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
project_name: getenvoy
1616
env:
1717
- GO111MODULE=on
18-
before:
19-
hooks:
20-
- make init
2118
builds:
2219
- binary: getenvoy
2320
ldflags: "-s -w -X github.com/tetratelabs/getenvoy/pkg/version.version={{.Version}}"

Makefile

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,15 @@ GETENVOY_OUT_PATH = $(BIN_DIR)/$(1)/$(2)/getenvoy
6666

6767
define GEN_GETENVOY_BUILD_TARGET
6868
.PHONY: $(call GETENVOY_OUT_PATH,$(1),$(2))
69-
$(call GETENVOY_OUT_PATH,$(1),$(2)): generate
69+
$(call GETENVOY_OUT_PATH,$(1),$(2)):
7070
CGO_ENABLED=0 GOOS=$(1) GOARCH=$(2) go build $(GO_LD_FLAGS) -o $(call GETENVOY_OUT_PATH,$(1),$(2)) ./cmd/getenvoy/main.go
7171
endef
7272
$(foreach os,$(GOOSES),$(foreach arch,$(GOARCHS),$(eval $(call GEN_GETENVOY_BUILD_TARGET,$(os),$(arch)))))
7373

74-
.PHONY: init
75-
init: generate
76-
7774
.PHONY: deps
7875
deps:
7976
go mod download
8077

81-
.PHONY: generate
82-
generate: deps
83-
go generate ./pkg/...
84-
8578
.PHONY: build
8679
build: $(call GETENVOY_OUT_PATH,$(GOOS),$(GOARCH))
8780

@@ -94,7 +87,7 @@ release.dryrun:
9487
goreleaser release --skip-publish --snapshot --rm-dist
9588

9689
.PHONY: test
97-
test: generate
90+
test:
9891
docker-compose up -d
9992
go test $(GO_TEST_OPTS) $(GO_TEST_EXTRA_OPTS) $(TEST_PKG_LIST)
10093

@@ -119,7 +112,7 @@ endef
119112
$(foreach os,$(GOOSES),$(foreach arch,$(GOARCHS),$(eval $(call GEN_BIN_GOOS_GOARCH_TARGET,$(os),$(arch)))))
120113

121114
.PHONY: coverage
122-
coverage: generate
115+
coverage:
123116
mkdir -p "$(shell dirname "$(COVERAGE_PROFILE)")"
124117
go test $(GO_COVERAGE_OPTS) $(GO_COVERAGE_EXTRA_OPTS) -coverprofile="$(COVERAGE_PROFILE)" $(COVERAGE_PKG_LIST)
125118
go tool cover -html="$(COVERAGE_PROFILE)" -o "$(COVERAGE_REPORT)"
@@ -176,8 +169,7 @@ builders.pull: $(foreach lang,$(BUILDERS_LANGS), pull/builder/$(lang))
176169

177170
LINT_OPTS ?= --timeout 5m
178171
.PHONY: lint
179-
# generate must be called while generated source is still used
180-
lint: generate $(GOLANGCI_LINT) $(SHFMT) $(LICENSER) .golangci.yml ## Run the linters
172+
lint: $(GOLANGCI_LINT) $(SHFMT) $(LICENSER) .golangci.yml ## Run the linters
181173
@echo "--- lint ---"
182174
@$(SHFMT) -d .
183175
@$(LICENSER) verify -r .

data/example/init/templates.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2021 Tetrate
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package init
16+
17+
import (
18+
"embed"
19+
"io/fs"
20+
)
21+
22+
// templatesFs includes only the relative path of "templates".
23+
//
24+
// Assets must be in this directory because go:embed doesn't support navigation outside (ex. ../)
25+
// See https://pkg.go.dev/embed#hdr-Directives
26+
//go:embed templates/*
27+
var templatesFs embed.FS
28+
29+
// GetTemplates returns the templates directory as a filesystem
30+
func GetTemplates() fs.FS {
31+
f, err := fs.Sub(templatesFs, "templates")
32+
if err != nil {
33+
panic(err) // unexpected or a typo
34+
}
35+
return f
36+
}

data/extension/init/templates.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2021 Tetrate
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package init
16+
17+
import (
18+
"embed"
19+
"io/fs"
20+
)
21+
22+
// templatesFs includes only the relative path of "templates".
23+
//
24+
// Assets must be in this directory because go:embed doesn't support navigation outside (ex. ../)
25+
// See https://pkg.go.dev/embed#hdr-Directives
26+
//go:embed templates/*
27+
var templatesFs embed.FS
28+
29+
// GetTemplates returns the templates directory as a filesystem
30+
func GetTemplates() fs.FS {
31+
f, err := fs.Sub(templatesFs, "templates")
32+
if err != nil {
33+
panic(err) // unexpected or a typo
34+
}
35+
return f
36+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
# We rename .cargo to cargo because go:embed doesn't recurse hidden directories
2+
.cargo
13
Cargo.lock
24
target/
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
build/
2+
3+
# We rename go.mod to go.mod_ to workaround https://github.com/golang/go/issues/45197
4+
go.mod

go.mod

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module github.com/tetratelabs/getenvoy
22

3+
// This project uses go:embed, so requires minimally go 1.16
34
go 1.16
45

56
require (
@@ -16,7 +17,7 @@ require (
1617
github.com/go-ole/go-ole v1.2.4 // indirect
1718
github.com/golang/protobuf v1.3.5
1819
github.com/gotestyourself/gotestyourself v2.2.0+incompatible // indirect
19-
github.com/manifoldco/promptui v0.0.0-00010101000000-000000000000
20+
github.com/manifoldco/promptui v0.8.0
2021
github.com/mattn/go-isatty v0.0.12
2122
github.com/mattn/go-shellwords v1.0.10
2223
github.com/mholt/archiver v3.1.1+incompatible
@@ -27,7 +28,6 @@ require (
2728
github.com/opencontainers/selinux v1.8.0 // indirect
2829
github.com/otiai10/copy v1.2.0
2930
github.com/pkg/errors v0.9.1
30-
github.com/rakyll/statik v0.0.0-00010101000000-000000000000
3131
github.com/schollz/progressbar/v2 v2.13.2
3232
github.com/shirou/gopsutil v0.0.0-20190731134726-d80c43f9c984
3333
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749
@@ -36,6 +36,7 @@ require (
3636
github.com/tetratelabs/getenvoy-package v0.0.0-20190730071641-da31aed4333e
3737
github.com/tetratelabs/log v0.0.0-20190710134534-eb04d1e84fb8
3838
github.com/tetratelabs/multierror v1.1.0
39+
github.com/tetratelabs/proxy-wasm-go-sdk v0.12.0
3940
istio.io/api v0.0.0-20200227213531-891bf31f3c32
4041
istio.io/istio v0.0.0-20200304114959-c3c353285578
4142
rsc.io/letsencrypt v0.0.3 // indirect
@@ -46,7 +47,3 @@ replace github.com/Azure/go-autorest/autorest => github.com/Azure/go-autorest/au
4647
replace github.com/docker/docker => github.com/docker/docker v17.12.1-ce+incompatible
4748

4849
replace github.com/hashicorp/consul => github.com/hashicorp/consul v1.3.1
49-
50-
replace github.com/manifoldco/promptui => github.com/yskopets/promptui v0.7.1-0.20200429230902-361491009c11
51-
52-
replace github.com/rakyll/statik => github.com/yskopets/statik v0.1.8-0.20200501213002-c2d8dcc79889

go.sum

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,8 @@ github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe/go.mod h1:C1wdFJiN
514514
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
515515
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
516516
github.com/mailru/easyjson v0.7.0/go.mod h1:KAzv3t3aY1NaHWoQz1+4F1ccyAH66Jk7yos7ldAVICs=
517+
github.com/manifoldco/promptui v0.8.0 h1:R95mMF+McvXZQ7j1g8ucVZE1gLP3Sv6j9vlF9kyRqQo=
518+
github.com/manifoldco/promptui v0.8.0/go.mod h1:n4zTdgP0vr0S3w7/O/g98U+e0gwLScEXGwov2nIKuGQ=
517519
github.com/marstr/guid v1.1.0/go.mod h1:74gB1z2wpxxInTG6yaqA7KrtM0NZ+RbrcqDvYHefzho=
518520
github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4=
519521
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
@@ -738,6 +740,7 @@ github.com/stretchr/testify v0.0.0-20151208002404-e3a8ff8ce365/go.mod h1:a8OnRci
738740
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
739741
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
740742
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
743+
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
741744
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
742745
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
743746
github.com/syndtr/gocapability v0.0.0-20170704070218-db04d3cc01c8/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
@@ -747,6 +750,8 @@ github.com/tetratelabs/log v0.0.0-20190710134534-eb04d1e84fb8 h1:a7FN/XPymdzttMa
747750
github.com/tetratelabs/log v0.0.0-20190710134534-eb04d1e84fb8/go.mod h1:w+dEBsxcYEFg0I6whrgkMzjD8GBBQgmDq9hykB30pt8=
748751
github.com/tetratelabs/multierror v1.1.0 h1:cKmV/Pbf42K5wp8glxa2YIausbxIraPN8fzru9Pn1Cg=
749752
github.com/tetratelabs/multierror v1.1.0/go.mod h1:kH3SzI/z+FwEbV9bxQDx4GiIgE2djuyb8wiB2DaUBnY=
753+
github.com/tetratelabs/proxy-wasm-go-sdk v0.12.0 h1:n2foXJoViPNPz5Jr3bHMc8a4WXBuXwQ3bKJYpfXZUPE=
754+
github.com/tetratelabs/proxy-wasm-go-sdk v0.12.0/go.mod h1:y1ZQT4bQEBnR8Do4nSOzb3roczzPvcAp8UrF6NEYWNY=
750755
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
751756
github.com/tinylib/msgp v1.0.2/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDWklFE=
752757
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
@@ -775,10 +780,6 @@ github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:
775780
github.com/yashtewari/glob-intersection v0.0.0-20180206001645-7af743e8ec84/go.mod h1:HptNXiXVDcJjXe9SqMd0v2FsL9f8dz4GnXgltU6q/co=
776781
github.com/yl2chen/cidranger v0.0.0-20180214081945-928b519e5268 h1:lkoOjizoHqOcEFsvYGE5c8Ykdijjnd0R3r1yDYHzLno=
777782
github.com/yl2chen/cidranger v0.0.0-20180214081945-928b519e5268/go.mod h1:mq0zhomp/G6rRTb0dvHWXRHr/2+Qgeq5hMXfJ670+i4=
778-
github.com/yskopets/promptui v0.7.1-0.20200429230902-361491009c11 h1:MlzMpHq1fRfH1RYzfQ7Ch7JjdGnBq/m29jJtPOExWuw=
779-
github.com/yskopets/promptui v0.7.1-0.20200429230902-361491009c11/go.mod h1:n4zTdgP0vr0S3w7/O/g98U+e0gwLScEXGwov2nIKuGQ=
780-
github.com/yskopets/statik v0.1.8-0.20200501213002-c2d8dcc79889 h1:f62aKW+gryXYYtNut+3b6i5n1ioXCXJWpDgA11l6Pak=
781-
github.com/yskopets/statik v0.1.8-0.20200501213002-c2d8dcc79889/go.mod h1:AlZONWzMtEnMs7W4e/1LURLiI49pIMmp6V9Unghqrcc=
782783
github.com/yuin/gopher-lua v0.0.0-20180316054350-84ea3a3c79b3/go.mod h1:aEV29XrmTYFr3CiRxZeGHpkvbwq+prZduBqMaascyCU=
783784
github.com/yvasiyarov/go-metrics v0.0.0-20140926110328-57bccd1ccd43 h1:+lm10QQTNSBd8DVTNGHx7o/IKu9HYDvLMffDhbyLccI=
784785
github.com/yvasiyarov/go-metrics v0.0.0-20140926110328-57bccd1ccd43/go.mod h1:aX5oPXxHm3bOH+xeAttToC8pqch2ScQN/JoXYupl6xs=

pkg/extension/example/init/registry/default.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,19 @@
1414

1515
package registry
1616

17-
//go:generate go run github.com/rakyll/statik -p=templates -m -ns=example/init/templates -src=../../../../../data/example/init/templates -a -include=* -f
18-
1917
import (
18+
"net/http"
2019
"path"
2120

22-
"github.com/rakyll/statik/fs"
23-
24-
// force execution of auto generated code
25-
_ "github.com/tetratelabs/getenvoy/pkg/extension/example/init/registry/templates"
21+
exampleTemplates "github.com/tetratelabs/getenvoy/data/example/init"
2622
"github.com/tetratelabs/getenvoy/pkg/extension/workspace/config/extension"
2723
)
2824

25+
var templatesFs = exampleTemplates.GetTemplates()
26+
2927
func newDefaultRegistry() registry {
30-
fileSystem, err := fs.NewWithNamespace("example/init/templates")
31-
if err != nil {
32-
// must be caught by unit tests
33-
panic(err)
34-
}
3528
return &fsRegistry{
36-
fs: fileSystem,
29+
fs: http.FS(templatesFs),
3730
namingScheme: func(category extension.Category, example string) string {
3831
return "/" + path.Join(category.String(), example)
3932
},

pkg/extension/init/init.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,14 @@ func (s *scaffolder) walk(sourceDirName, destinationDirName string) (errs error)
102102

103103
func (s *scaffolder) visit(sourceDirName, destinationDirName string, sourceFileInfo os.FileInfo) (errs error) {
104104
baseOutputFileName := sourceFileInfo.Name()
105-
// We rename go.mod to go.mod_ to workaround https://github.com/golang/go/issues/45197
106-
if baseOutputFileName == "go.mod_" {
107-
baseOutputFileName = "go.mod" // rename workaround for https://github.com/golang/go/issues/45197
105+
// This works around go:embed limitations via renaming per https://github.com/golang/go/issues/45197
106+
// This logic should be moved to a decorating http.FileSystem when one exists.
107+
if baseOutputFileName == "go.mod_" { // go.mod is a forbidden name
108+
baseOutputFileName = "go.mod"
109+
}
110+
if destinationDirName == "cargo" { // go:embed doesn't recurse hidden directories
111+
destinationDirName = ".cargo"
108112
}
109-
110113
relOutputFileName := filepath.Join(destinationDirName, baseOutputFileName)
111114
outputFileName := filepath.Join(s.opts.OutputDir, relOutputFileName)
112115
if err := osutil.EnsureDirExists(filepath.Dir(outputFileName)); err != nil {

pkg/extension/init/source.go

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,13 @@
1414

1515
package init
1616

17-
//go:generate go run github.com/rakyll/statik -p=templates -m -ns=extension/init/templates -src=../../../data/extension/init/templates -a -include=* -f
18-
1917
import (
18+
"net/http"
2019
"path"
2120
"sync"
2221

23-
"github.com/rakyll/statik/fs"
24-
22+
extensionTemplates "github.com/tetratelabs/getenvoy/data/extension/init"
2523
"github.com/tetratelabs/getenvoy/pkg/extension/workspace/config/extension"
26-
27-
// force execution of auto generated code
28-
_ "github.com/tetratelabs/getenvoy/pkg/extension/init/templates"
2924
)
3025

3126
var (
@@ -34,17 +29,14 @@ var (
3429
templatesOnce sync.Once
3530
)
3631

32+
var templatesFs = extensionTemplates.GetTemplates()
33+
3734
// getTemplateSource returns a source of extension templates.
3835
func getTemplateSource() templateSource {
3936
// do lazy init to avoid zip decompression unless absolutely necessary
4037
templatesOnce.Do(func() {
41-
fileSystem, err := fs.NewWithNamespace("extension/init/templates")
42-
if err != nil {
43-
// must be caught by unit tests
44-
panic(err)
45-
}
4638
templates = &fsTemplateSource{
47-
fs: fileSystem,
39+
fs: http.FS(templatesFs),
4840
namingScheme: func(language extension.Language, category extension.Category, template string) string {
4941
return "/" + path.Join(language.String(), category.String(), template)
5042
},

0 commit comments

Comments
 (0)