Skip to content

Commit 74e8aca

Browse files
authored
Add Dockerfile for boe create for cshared libs, configure test.short to skip long runing tests and other tech debt (#445)
This PR contains several build and test-related fixes and tech debt addressing. I did them incrementally in this PR as many were tightly related, but I'm happy to split up into different PRs if that's preferred. * The `Dockerfile` generated for the Go plugins was for the `goplugin` build, but the Makefile main build is now cshared. This PR provides a Dockerfile for each case, switches the default one to `cshared`, and adds the needed Makefile targets. * Related to #442: The Dockerfile for `cshared` in this PR may need to be updated if that PR is merged first. cc @codefromthecrypt * Adds the `config.schema.json` to the extension images along with the manifest and adds missing tests for verifying the contents of extensions. * For Go extensions, adds the `cshared` bool to the OCI annotations. CShared extensions and plugin extensions are downloaded to different locations, and knowing the "flavor" is needed by `boe download` before it can inspect the package contents. cc @wbpcode * Adds `make help` support for all the generated Makefiles to help users easily understand what is available. * Adds support for the `-test.short` flag when running Go tests. By default, PR e2e tests will run with the "short" flag to skip long-running tests, but e2e tests for `main` and release branches will run all tests. Added a helper `internaltesting.MaybeSkipLongRunningTest` to easily mark tests as long running and to have them skipped easily. * Prints the boe logs upon e2e test failures. * Logs command execution errors to the boe log file (previously, only normal info/debug messages were logged). * Unify Go verison for Dockerfiles and generated files to reduce the number of places it needs to be updated. --------- Signed-off-by: Ignasi Barrera <ignasi@tetrate.io>
1 parent 20c7f11 commit 74e8aca

43 files changed

Lines changed: 569 additions & 232 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/cli.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ jobs:
9797
run:
9898
working-directory: ./cli
9999
env:
100-
GO_TEST_ARGS: -v
100+
# For PRs, skip the long running tests. For pushes to main or release branches, run all tests.
101+
GO_TEST_ARGS: ${{ github.event_name == 'pull_request' && '-v -test.short' || '-v' }}
101102
TEST_BOE_REGISTRY: ghcr.io/tetratelabs/built-on-envoy
102103
TEST_BOE_REGISTRY_USERNAME: ${{ github.actor }}
103104
TEST_BOE_REGISTRY_PASSWORD: ${{ secrets.GITHUB_TOKEN }}

cli/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ ENV GOMODCACHE=/var/boe/go/pkg/mod \
3030

3131
ARG TARGETOS
3232
ARG TARGETARCH
33-
ARG GO_VERSION=1.26.3
33+
ARG GO_VERSION
3434

3535
# Install Go
3636
RUN curl -fsSL https://go.dev/dl/go${GO_VERSION}.${TARGETOS}-${TARGETARCH}.tar.gz \

cli/Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ GO_TEST_ARGS ?=
2323

2424
# Use a specific go tool invocation that uses the tools module for linters and other tools so that
2525
# the main go.mod is not polluted with tool dependencies.
26-
ROOT := $(shell git rev-parse --show-toplevel)
27-
GO_TOOL := go tool -modfile=$(ROOT)/tools/go.mod
26+
ROOT := $(shell git rev-parse --show-toplevel)
27+
GO_VERSION := $(shell sed -ne 's/^go //gp' $(ROOT)/go.mod)
28+
GO_TOOL := go tool -modfile=$(ROOT)/tools/go.mod
2829

2930
# Base OCI image annotations (shared by all image types)
3031
BASE_OCI_ANNOTATIONS := \
@@ -138,6 +139,7 @@ build_image: ## Build the Docker image
138139
docker buildx build \
139140
--output type=docker,oci-mediatypes=true \
140141
--provenance=false \
142+
--build-arg GO_VERSION="$(GO_VERSION)" \
141143
$(BASE_OCI_ANNOTATIONS) \
142144
-t $(OCI_REGISTRY)/$(NAME):$(TAG) \
143145
-f ./Dockerfile .
@@ -151,6 +153,7 @@ push_image: create_builder ## Push the Docker image to the registry
151153
--builder $(BUILDER_NAME) \
152154
--output type=registry,oci-mediatypes=true$(registry_output) \
153155
--provenance=false \
156+
--build-arg GO_VERSION="$(GO_VERSION)" \
154157
$(MULTI_OCI_ANNOTATIONS) \
155158
-t $(OCI_REGISTRY)/$(NAME):$(TAG) \
156159
-f ./Dockerfile .

cli/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,5 @@ cli/
7474

7575
| Variable | Description | Example |
7676
|----------|-------------|---------|
77-
| `GO_TEST_ARGS` | Extra args for `go test` | `make test GO_TEST_ARGS="-run TestRun -v"` |
77+
| `GO_TEST_ARGS` | Extra args for `go test` | `make test GO_TEST_ARGS="-test.short -run TestRun -v"` |
7878
| `TAG` | Docker image tag | `make build_image TAG=v1.0.0` |

cli/cmd/create.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"slices"
1818
"text/template"
1919

20+
"github.com/tetratelabs/built-on-envoy/cli/internal"
2021
"github.com/tetratelabs/built-on-envoy/cli/internal/extensions"
2122
"github.com/tetratelabs/built-on-envoy/cli/internal/xdg"
2223
)
@@ -83,6 +84,7 @@ func createGoExtension(logger *slog.Logger, dirs *xdg.Directories, path, name, c
8384
"Name": name,
8485
"LibComposerVersion": composerVersion,
8586
"DataHome": dirs.DataHome,
87+
"GoVersion": internal.GoVersion,
8688
}
8789

8890
// Map of output filename to template filename
@@ -93,6 +95,7 @@ func createGoExtension(logger *slog.Logger, dirs *xdg.Directories, path, name, c
9395
"Makefile": "templates/create/go/Makefile.tmpl",
9496
"go.mod": "templates/create/go/go.mod.tmpl",
9597
"Dockerfile": "templates/create/go/Dockerfile.tmpl",
98+
"Dockerfile.plugin": "templates/create/go/Dockerfile.plugin.tmpl",
9699
"Dockerfile.code": "templates/create/go/Dockerfile.code.tmpl",
97100
".dockerignore": "templates/create/go/dockerignore.tmpl",
98101
"embedded/host.go": "templates/create/go/host.go.tmpl",
@@ -160,7 +163,8 @@ func createExtProcExtension(logger *slog.Logger, path, name string) error {
160163
repoPath := filepath.Join(path, name)
161164

162165
data := map[string]string{
163-
"Name": name,
166+
"Name": name,
167+
"GoVersion": internal.GoVersion,
164168
}
165169

166170
files := map[string]string{

cli/cmd/create_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/stretchr/testify/assert"
2121
"github.com/stretchr/testify/require"
2222

23+
"github.com/tetratelabs/built-on-envoy/cli/internal"
2324
internaltesting "github.com/tetratelabs/built-on-envoy/cli/internal/testing"
2425
"github.com/tetratelabs/built-on-envoy/cli/internal/xdg"
2526
)
@@ -96,8 +97,10 @@ func TestCreateGo_Run(t *testing.T) {
9697
"Makefile",
9798
"go.mod",
9899
"Dockerfile",
100+
"Dockerfile.plugin",
99101
"Dockerfile.code",
100102
".dockerignore",
103+
"main/main.go",
101104
"embedded/host.go",
102105
"standalone/main.go",
103106
}
@@ -118,6 +121,18 @@ func TestCreateGo_Run(t *testing.T) {
118121
require.NoError(t, err)
119122
assert.Contains(t, string(plugin), "x-"+name)
120123
assert.Contains(t, string(plugin), "WellKnownHttpFilterConfigFactories")
124+
125+
// verify go.mod content
126+
// #nosec G304
127+
gomod, err := os.ReadFile(filepath.Join(repoPath, "go.mod"))
128+
require.NoError(t, err)
129+
assert.Contains(t, string(gomod), `go `+internal.GoVersion)
130+
131+
// verify Dockerfile content
132+
// #nosec G304
133+
dockerfile, err := os.ReadFile(filepath.Join(repoPath, "Dockerfile"))
134+
require.NoError(t, err)
135+
assert.Contains(t, string(dockerfile), "FROM golang:"+internal.GoVersion)
121136
}
122137
}
123138

cli/cmd/root.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ type CLI struct {
5050
StateHome string `name:"state-home" env:"BOE_STATE_HOME" help:"Persistent state and logs directory. Defaults to ~/.local/state/boe" type:"path" default:"~/.local/state/boe"`
5151
RuntimeDir string `name:"runtime-dir" env:"BOE_RUNTIME_DIR" help:"Ephemeral runtime files directory. Defaults to /tmp/boe-$UID" type:"path"`
5252
BoeLogLevel string `name:"boe-log-level" env:"BOE_LOG_LEVEL" help:"Log level for the CLI. Defaults to debug" enum:"debug,info,warn,error" default:"debug"`
53+
54+
Logger *slog.Logger `kong:"-"` // Internal field for the logger
5355
}
5456

5557
// BeforeApply is called by Kong before applying defaults to set XDG directory defaults.
@@ -72,11 +74,12 @@ func (c *CLI) BeforeApply(ctx *kong.Context) error {
7274
}
7375
ctx.Bind(dirs)
7476

75-
logger, err := initLogger(dirs, c.BoeLogLevel)
77+
var err error
78+
c.Logger, err = initLogger(dirs, c.BoeLogLevel)
7679
if err != nil {
7780
return fmt.Errorf("failed to initialize logger: %w", err)
7881
}
79-
ctx.Bind(logger)
82+
ctx.Bind(c.Logger)
8083

8184
return nil
8285
}

cli/cmd/templates/create/ext_proc/Dockerfile.tmpl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# Dockerfile (e.g., Dockerfile.custom) instead of editing this file.
99

1010
# Build the manager binary
11-
FROM golang:1.26.3 AS builder
11+
FROM golang:{{ .GoVersion }} AS builder
1212

1313
WORKDIR /workspace
1414
COPY . .
@@ -24,4 +24,8 @@ FROM scratch AS final
2424
# include in the image.
2525
COPY --from=builder /workspace/manifest.yaml /
2626
COPY --from=builder /workspace/out/ext_proc-server /
27+
# Use a wildcard to copy config.schema.json if it exists, since COPY will fail if the file does not exist and we want to
28+
# allow for optional presence of this file.
29+
COPY --from=builder /workspace/config.schema.json* /
30+
2731
ENTRYPOINT [ "/ext_proc-server" ]

cli/cmd/templates/create/ext_proc/Makefile.tmpl

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# If you need to customize the build process, consider using environment variables
33
# or wrapper scripts instead of editing this file.
44

5+
default: build
6+
57
# This IMAGE_NONCE will be appended to the final image tag if set.
68
# It is intended to be used in CI environments to ensure that each image
79
# built gets a unique tag.
@@ -57,7 +59,7 @@ SOURCE_ARTIFACT := --annotation "io.tetratelabs.built-on-envoy.extension.artifac
5759
comma := ,
5860
MULTI_OCI_ANNOTATIONS := \
5961
$(subst --annotation ",--annotation "index$(comma)manifest:,$(BASE_OCI_ANNOTATIONS)) \
60-
--annotation "index,manifest:io.tetratelabs.built-on-envoy.extension.artifact=binary"
62+
$(subst --annotation ",--annotation "index$(comma)manifest:,$(BINARY_ARTIFACT))
6163
6264
BUILDER_NAME := boe-builder
6365
.PHONY: create_builder
@@ -67,29 +69,33 @@ create_builder:
6769
--driver docker-container --driver-opt network=host \
6870
--buildkitd-flags '--allow-insecure-entitlement network.host' --use
6971
70-
.PHONY: test
71-
test:
72-
go test ./...
72+
##@ Build
7373
7474
.PHONY: build
75-
build:
75+
build: ## Compile the extproc server binary
7676
CGO_ENABLED=0 go build -a -ldflags="-s -w" -o ./out/ext_proc-server .
7777
78-
.PHONY: clean
79-
clean:
80-
rm -f ./out/ext_proc-server
78+
.PHONY: test
79+
test: ## Run the tests
80+
go test ./...
8181
8282
.PHONY: install
83-
install: build
83+
install: build ## Install the built extproc extension to the local BOE data directory
8484
@echo "Installing $(NAME)..."
8585
mkdir -p $(BOE_DATA_HOME)/extensions/extproc/$(NAME)/$(VERSION); \
8686
cp ./out/ext_proc-server $(BOE_DATA_HOME)/extensions/extproc/$(NAME)/$(VERSION)/ext_proc-server;
8787
@echo "Installed to $(BOE_DATA_HOME)/extensions/extproc/$(NAME)"
8888
89+
.PHONY: clean
90+
clean: ## Clean up the build artifacts
91+
rm -f ./out/ext_proc-server
92+
93+
##@ Packaging
94+
8995
# For single local platform build, we will add the OS and ARCH to the image tag to avoid confusion.
9096
# And we will not push it to the registry by default.
9197
.PHONY: build_image
92-
build_image:
98+
build_image: ## Build the OCI image for the extproc server
9399
docker buildx build \
94100
--output type=docker,oci-mediatypes=true \
95101
--provenance=false \
@@ -102,7 +108,7 @@ build_image:
102108
# both amd64 and arm64 architectures, and push it to the registry.
103109
PLATFORMS ?= linux/arm64,linux/amd64
104110
.PHONY: push_image
105-
push_image: create_builder ## Build and push docker image for the plugin for cross-platform support
111+
push_image: create_builder ## Build and push OCI image for the extproc server
106112
@echo "Building and pushing image..."
107113
docker buildx build --platform=$(PLATFORMS) \
108114
--builder $(BUILDER_NAME) \
@@ -115,7 +121,7 @@ push_image: create_builder ## Build and push docker image for the plugin for cr
115121
# Package source code into an image and push it to the registry.
116122
CODE_IMAGE := $(HUB)/extension-src-$(NAME):$(VERSION)$(IMAGE_NONCE)
117123
.PHONY: push_code
118-
push_code: create_builder ## Build and push source code image
124+
push_code: create_builder ## Build and push the OCI image with the extension source code
119125
@echo "Building and pushing source code image..."
120126
docker buildx build \
121127
--builder $(BUILDER_NAME) \
@@ -125,3 +131,12 @@ push_code: create_builder ## Build and push source code image
125131
$(SOURCE_ARTIFACT) \
126132
--tag $(CODE_IMAGE) \
127133
-f ./Dockerfile.code .
134+
135+
136+
##@ Help
137+
138+
.PHONY: help
139+
help: ## Show this help info
140+
@echo "Built On Envoy. Discover, run, and build custom filters with zero friction.\n"
141+
@echo "Usage:\n make \033[36m<Target>\033[0m \n\nTargets:"
142+
@awk 'BEGIN {FS = ":.*##"; printf ""} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

cli/cmd/templates/create/ext_proc/go.mod.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module {{ .Name }}
22

3-
go 1.26.3
3+
go {{ .GoVersion }}
44

55
require (
66
github.com/envoyproxy/go-control-plane/envoy v1.37.0

0 commit comments

Comments
 (0)