Skip to content

Commit

Permalink
Changes from statik to go:embed for examples serving
Browse files Browse the repository at this point in the history
There's currently a glitch because go.mod isn't allowed in the go:embed
path.

Fixes #126
See golang/go#41191 (comment)
  • Loading branch information
Adrian Cole committed Mar 24, 2021
1 parent 5d8ef0e commit cd4c268
Show file tree
Hide file tree
Showing 22 changed files with 51 additions and 143 deletions.
2 changes: 0 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ jobs:
GOMAXPROCS: "3"
steps:
- checkout
- run: make init
- run: ./ci/install-lint
- run: ./ci/lint

Expand All @@ -41,7 +40,6 @@ jobs:
resource_class: medium+
steps:
- checkout
- run: make init
- run: ./ci/install-envoy
- run: ./ci/test
- run:
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/commit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ jobs:
- name: "Install Go"
uses: actions/setup-go@v2
with:
go-version: '1.13.3'

- name: "Init on first use"
run: make init
go-version: '1.16.2'

- name: "Build `getenvoy` and `e2e` binaries"
run: make bin
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: "Set up Go"
uses: actions/setup-go@v2
with:
go-version: '1.13.3'
go-version: '1.16.2'

- name: "Login into DockerHub"
uses: azure/docker-login@v1
Expand Down Expand Up @@ -75,7 +75,7 @@ jobs:
- name: "Install Go"
uses: actions/setup-go@v2
with:
go-version: '1.13.3'
go-version: '1.16.2'

- name: "Build `e2e` binaries"
run: make build/bin/linux/amd64/e2e build/bin/darwin/amd64/e2e
Expand Down
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@ vendor
dist
/getenvoy
/build/

# code generated by `github.com/rakyll/statik`
statik.go
.idea
3 changes: 0 additions & 3 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
project_name: getenvoy
env:
- GO111MODULE=on
before:
hooks:
- make init
builds:
- binary: getenvoy
ldflags: "-s -w -X github.com/tetratelabs/getenvoy/pkg/version.version={{.Version}}"
Expand Down
15 changes: 4 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ GETENVOY_OUT_PATH = $(BIN_DIR)/$(1)/$(2)/getenvoy

define GEN_GETENVOY_BUILD_TARGET
.PHONY: $(call GETENVOY_OUT_PATH,$(1),$(2))
$(call GETENVOY_OUT_PATH,$(1),$(2)): generate
$(call GETENVOY_OUT_PATH,$(1),$(2)):
CGO_ENABLED=0 GOOS=$(1) GOARCH=$(2) go build $(GO_LD_FLAGS) -o $(call GETENVOY_OUT_PATH,$(1),$(2)) ./cmd/getenvoy/main.go
endef
$(foreach os,$(GOOSES),$(foreach arch,$(GOARCHS),$(eval $(call GEN_GETENVOY_BUILD_TARGET,$(os),$(arch)))))
Expand All @@ -71,17 +71,10 @@ $(call E2E_OUT_PATH,$(1),$(2)):
endef
$(foreach os,$(GOOSES),$(foreach arch,$(GOARCHS),$(eval $(call GEN_E2E_BUILD_TARGET,$(os),$(arch)))))

.PHONY: init
init: generate

.PHONY: deps
deps:
go mod download

.PHONY: generate
generate: deps
go generate ./pkg/...

.PHONY: build
build: $(call GETENVOY_OUT_PATH,$(GOOS),$(GOARCH))

Expand All @@ -94,12 +87,12 @@ release.dryrun:
goreleaser release --skip-publish --snapshot --rm-dist

.PHONY: test
test: generate
test:
docker-compose up -d
go test $(GO_TEST_OPTS) $(GO_TEST_EXTRA_OPTS) $(TEST_PKG_LIST)

.PHONY: test.ci
test.ci: generate
test.ci:
go test $(GO_TEST_OPTS) $(GO_TEST_EXTRA_OPTS) $(TEST_PKG_LIST)

.PHONY: e2e
Expand All @@ -123,7 +116,7 @@ endef
$(foreach os,$(GOOSES),$(foreach arch,$(GOARCHS),$(eval $(call GEN_BIN_GOOS_GOARCH_TARGET,$(os),$(arch)))))

.PHONY: coverage
coverage: generate
coverage:
mkdir -p "$(shell dirname "$(COVERAGE_PROFILE)")"
go test $(GO_COVERAGE_OPTS) $(GO_COVERAGE_EXTRA_OPTS) -coverprofile="$(COVERAGE_PROFILE)" $(COVERAGE_PKG_LIST)
go tool cover -html="$(COVERAGE_PROFILE)" -o "$(COVERAGE_REPORT)"
Expand Down
23 changes: 23 additions & 0 deletions data/extension/init/templates.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package init
// ^^ last path in the directory relative from the project root data/extension/init

import (
"embed"
"io/fs"
)

// templatesFs includes only the relative path of "templates".
//
// Assets must be in this directory because go:embed doesn't support navigation outside (ex. ../)
// See https://pkg.go.dev/embed#hdr-Directives
//go:embed templates/*
var templatesFs embed.FS

// GetTemplates returns the templates directory as a filesystem
func GetTemplates() fs.FS {
fs, err := fs.Sub(templatesFs, "templates")
if err != nil {
panic(err) // unexpected or a typo
}
return fs
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package init

import (
"github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm"
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package init

import (
"bufio"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package init

import (
"testing"
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package init

import (
"github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package init

import (
"testing"
Expand Down
10 changes: 3 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module github.com/tetratelabs/getenvoy

go 1.13
// This project uses go:embed, so requires minimally go 1.16
go 1.16

require (
bitbucket.org/creachadair/shell v0.0.6
Expand All @@ -16,7 +17,7 @@ require (
github.com/go-ole/go-ole v1.2.4 // indirect
github.com/golang/protobuf v1.3.5
github.com/gotestyourself/gotestyourself v2.2.0+incompatible // indirect
github.com/manifoldco/promptui v0.0.0-00010101000000-000000000000
github.com/manifoldco/promptui v0.8.0
github.com/mattn/go-isatty v0.0.12
github.com/mattn/go-shellwords v1.0.10
github.com/mholt/archiver v3.1.1+incompatible
Expand All @@ -27,7 +28,6 @@ require (
github.com/opencontainers/selinux v1.8.0 // indirect
github.com/otiai10/copy v1.2.0
github.com/pkg/errors v0.9.1
github.com/rakyll/statik v0.0.0-00010101000000-000000000000
github.com/schollz/progressbar/v2 v2.13.2
github.com/shirou/gopsutil v0.0.0-20190731134726-d80c43f9c984
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749
Expand All @@ -47,7 +47,3 @@ replace github.com/Azure/go-autorest/autorest => github.com/Azure/go-autorest/au
replace github.com/docker/docker => github.com/docker/docker v17.12.1-ce+incompatible

replace github.com/hashicorp/consul => github.com/hashicorp/consul v1.3.1

replace github.com/manifoldco/promptui => github.com/yskopets/promptui v0.7.1-0.20200429230902-361491009c11

replace github.com/rakyll/statik => github.com/yskopets/statik v0.1.8-0.20200501213002-c2d8dcc79889
Loading

0 comments on commit cd4c268

Please sign in to comment.