Skip to content
Merged

1.37 #53

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 22 additions & 57 deletions .github/workflows/commit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ on:
branches: [ main ]

jobs:
rust:
name: Rust Build and Test (${{ matrix.platform.arch }}, ${{ matrix.platform.os }})
build_and_test:
name: Build and Test (${{ matrix.platform.arch }}, ${{ matrix.platform.os }})
runs-on: ${{ matrix.platform.os }}
defaults:
run:
working-directory: ./rust
strategy:
fail-fast: false
matrix:
Expand All @@ -28,6 +25,19 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
cache: false
go-version-file: go/go.mod

- uses: actions/cache@v4
with:
path: |
~/.cache/go-build
~/go/pkg/mod
~/go/bin
key: go-test-${{ hashFiles('**/go.mod', '**/go.sum') }}

- name: Cache Cargo registry
uses: actions/cache@v4
with:
Expand All @@ -51,58 +61,13 @@ jobs:
override: true
components: clippy, rustfmt

- name: Check formatting
run: cargo fmt -- --check

- name: Run Clippy linter
run: cargo clippy -- -D warnings

- name: Build project
run: cargo build --verbose

- name: Run tests
run: cargo test --verbose

go:
name: Go Build and Test (${{ matrix.platform.arch }}, ${{ matrix.platform.os }})
runs-on: ${{ matrix.platform.os }}
defaults:
run:
working-directory: ./go
strategy:
fail-fast: false
matrix:
platform:
- os: ubuntu-22.04
arch: amd64
- os: ubuntu-22.04-arm
arch: arm64
- os: macos-latest
arch: arm64

steps:
- name: Checkout repository
uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
cache: false
go-version-file: go/go.mod

- uses: actions/cache@v4
with:
path: |
~/.cache/go-build
~/go/pkg/mod
~/go/bin
key: go-test-${{ hashFiles('**/go.mod', '**/go.sum') }}

- run: CGO_ENABLED=0 go test ./... -v
- run: go build -buildmode=c-shared -o main.so
- run: go tool golangci-lint run
- run: make check
- run: make test
- run: make build
- run: make integration-test

docker_build_and_integration_test:
name: Build and Run Integration Tests
name: Integration Test with Docker Image
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down Expand Up @@ -162,9 +127,9 @@ jobs:
cache-from: type=gha
cache-to: type=gha,mode=max

integration_test_on_main:
docker_build_and_integration_test_on_main:
needs: [docker_build_and_integration_test]
name: Integration Test (${{ matrix.platform.arch }})
name: Integration Test with Docker Image (${{ matrix.platform.arch }})
# This will only run on push events to the main branch.
# Mainly to check the multi-arch image by running the
# integration tests on both architectures.
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ RUN cp /build/target/x86_64-unknown-linux-gnu/debug/librust_module.so /build/amd
##### Build the Go library #####

# We use zig to cross-compile the Go library for both x86_64 and aarch64 architectures.
FROM --platform=$BUILDPLATFORM golang:1.24.2 AS go_builder
FROM --platform=$BUILDPLATFORM golang:1.25.6 AS go_builder
# Install zig.
ARG ZIG_VERSION=0.14.0
RUN apt update && apt install -y curl xz-utils
Expand All @@ -46,7 +46,7 @@ RUN CC="zig cc -target aarch64-linux-gnu" CXX="zig c++ -target aarch64-linux-gnu
RUN CC="zig cc -target x86_64-linux-gnu" CXX="zig c++ -target x86_64-linux-gnu" CGO_ENABLED=1 GOARCH=amd64 go build -buildmode=c-shared -o /build/amd64_libgo_module.so .

##### Build the final image #####
FROM envoyproxy/envoy:v1.36.2 AS envoy
FROM envoyproxy/envoy:v1.37.0 AS envoy
ARG TARGETARCH
ENV ENVOY_DYNAMIC_MODULES_SEARCH_PATH=/usr/local/lib
COPY --from=rust_builder /build/${TARGETARCH}_librust_module.so /usr/local/lib/librust_module.so
Expand Down
1 change: 0 additions & 1 deletion ENVOY_VERSION

This file was deleted.

108 changes: 108 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
CYAN := \033[36m
GREEN := \033[32m
YELLOW := \033[33m
RESET := \033[0m
BOLD := \033[1m

define print_task
printf "$(BOLD)$(CYAN)[TASK]$(RESET) $(BOLD)%s$(RESET)\n" "$(1)"
endef
define print_subtask
printf " $(YELLOW)→$(RESET) %s\n" "$(1)"
endef
define print_success
printf " $(GREEN)✓$(RESET) %s\n" "$(1)"
endef

## help: Show this help info.
.PHONY: help
help:
@echo "Envoy Dynamic Modules.\n"
@echo "Usage:\n make \033[36m<Target>\033[0m \n\nTargets:"
@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)

# This runs all necessary steps to prepare for a commit.
.PHONY: precommit
precommit: ## Run all necessary steps to prepare for a commit.
precommit: precommit-go precommit-rust

.PHONY: precommit-go
precommit-go: ## This runs the linter, formatter, and tidy on the Go codebase.
@$(call print_task,Tidying Go modules)
@find . -name "go.mod" \
| grep go.mod \
| xargs -I {} bash -c 'dirname {}' \
| xargs -I {} bash -c 'cd {} && $(call print_subtask,Tidying {}) && go mod tidy -v;'
@$(call print_success,Tidying completed)
@$(call print_task,Running linter)
@$(call print_subtask,Checking ./...)
@cd go && go tool golangci-lint run --build-tags==cgo ./...
@$(call print_success,Linting completed)
@$(call print_task,Formatting code)
@$(call print_subtask,Running gofmt)
@cd go && find . -type f -name '*.go' | xargs gofmt -s -w
@$(call print_subtask,Running gofumpt)
@cd go && find . -type f -name '*.go' | xargs go tool gofumpt -l -w
@$(call print_subtask,Running gci)
@cd go && go tool gci write -s standard -s default -s "prefix(github.com/envoyproxy/dynamic-modules-examples)" `find . -name '*.go'`
@$(call print_success,Formatting completed)

.PHONY: precommt-rust
precommit-rust: ## This runs the linter, formatter, and tidy on the Rust codebase.
@$(call print_task,Running Rust precommit steps)
@$(call print_subtask,Running cargo fmt)
@cd rust && cargo fmt --all -- --check
@$(call print_subtask,Running cargo clippy)
@cd rust && cargo clippy -- -D warnings
@$(call print_success,Rust precommit steps completed)

# This runs precommit and checks for any differences in the codebase, failing if there are any.
.PHONY: check
check: precommit ## Run all necessary steps to prepare for a commit and check for any differences in the codebase.
@$(call print_task,Checking for uncommitted changes)
@if [ ! -z "`git status -s`" ]; then \
echo "$(BOLD)$(YELLOW)The following differences will fail CI until committed:$(RESET)"; \
git diff --exit-code; \
echo "$(BOLD)$(YELLOW)Please ensure you have run 'make precommit' and committed the changes.$(RESET)"; \
exit 1; \
fi
@$(call print_success,No uncommitted changes found)

.PHONY: test
test: test-rust test-rust ## Run all tests for the codebase.
.PHONY: test-go
test-go:## Run the unit tests for the Go codebase. This doesn't run the integration tests like test-* targets.
@$(call print_task,Running Go tests)
@cd go && go test -v ./...
@$(call print_success,Go unit tests completed)
.PHONY: test-rust
test-rust: ## Run the unit tests for the Rust codebase.
@$(call print_task,Running Rust tests)
@cd rust && cargo test
@$(call print_success,Rust unit tests completed)

.PHONY: build
build: build-go build-rust ## Build all dynamic modules.

.PHONY: build-go
build-go: ## Build the Go dynamic module.
@$(call print_task,Building Go dynamic module)
@cd go && go build -buildmode=c-shared -o libgo_module.so .
@$(call print_success,Go dynamic module built at go/libgo_module.so)
@$(call print_task,Copying Go dynamic module for easier use with Envoy)
@cp go/libgo_module.so integration/libgo_module.so

.PHONY: build-rust
build-rust: ## Build the Rust dynamic module.
@$(call print_task,Building Rust dynamic module)
@cd rust && cargo build
@$(call print_success,Rust dynamic module built at rust/target/debug/librust_module.so)
@$(call print_task,Copying Rust dynamic module for easier use with Envoy)
@cp rust/target/debug/librust_module.dylib integration/librust_module.so || true
@cp rust/target/debug/librust_module.so integration/librust_module.so || true

.PHONY: integration-test
integration-test: build-go build-rust ## Run the integration tests.
@$(call print_task,Running integration tests)
@cd integration && go test -v ./...
@$(call print_success,Integration tests completed)
67 changes: 7 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Dynamic Modules Examples

> Envoy Version: [dc2d3098ae5641555f15c71d5bb5ce0060a8015c] v1.36.2
> Envoy Version: v1.37.0
>
> Since dynamic modules are tied with a specific Envoy version, this repository is based on the specific commit of Envoy.
> For examples for a specific Envoy version, please check out `release/v<version>` branches:
Expand Down Expand Up @@ -29,67 +29,14 @@ The tracking issue for dynamic modules in general is [here](https://github.com/e

## Development

### Rust Dynamic Module

To build and test the modules locally without Envoy, you can use `cargo` to build them just like any other Rust project:

```
cd rust
cargo build
cargo test
cargo clippy -- -D warnings
cargo fmt --all -- --check
```

### Go Dynamic Module
To build and test the modules locally without Envoy, you can use `go` to build them just like any other Go project:

```
cd go
go test ./... -v
go build -buildmode=c-shared -o libgo_module.so .
go tool golangci-lint run
find . -type f -name '*.go' | xargs go tool gofumpt -l -w
```

### Build Envoy + Example Dynamic Module Docker Image

To build the example modules and bundle them with Envoy, simply run

```
docker buildx build . -t envoy-with-dynamic-modules:latest [--platform linux/amd64,linux/arm64]
```

where `--platform` is optional and can be used to build for multiple platforms.

### Run Envoy + Example Dynamic Module Docker Image

The example Envoy configuration yaml is in [`integration/envoy.yaml`](integration/envoy.yaml) which is also used
to run the integration tests. Assuming you built the Docker image with the tag `envoy-with-dynamic-modules:latest`, you can run Envoy with the following command:

```
docker run --network host -v $(pwd):/examples -w /examples/integration envoy-with-dynamic-modules:latest --config-path ./envoy.yaml
```

Then execute, for example, the following command to test the passthrough and access log filters:

```
curl localhost:1062/uuid
```

### Run integration tests with the built example Envoy + Dynamic Module Docker Image.

The integration tests are in the `integration` directory. Assuming you built the Docker image with the tag `envoy-with-dynamic-modules:latest`, you can run the integration tests with the following command:
```
cd integration
go test . -v -count=1
```

If you want to explicitly specify the docker image, use `ENVOY_IMAGE` environment variable:
```
ENVOY_IMAGE=foo-bar-image:latest go test . -v -count=1
# Run all unit tests
make test
# Build all dynamic modules
make build
# Run integration tests with Envoy via func-e (no local installation required)
make integration-test
```

[dc2d3098ae5641555f15c71d5bb5ce0060a8015c]: https://github.com/envoyproxy/envoy/tree/dc2d3098ae5641555f15c71d5bb5ce0060a8015c
[Envoy]: https://github.com/envoyproxy/envoy
[High Level Doc]: https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/advanced/dynamic_modules
Loading
Loading