From 7149519ab03263f6728db2e56f9b858e8c16f70d Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Fri, 7 Feb 2025 07:17:23 +0900 Subject: [PATCH 1/6] Setups build pipeline Signed-off-by: Takeshi Yoneda --- .github/workflows/commit.yaml | 47 +++++++++++++++++++++++++++++++++++ Dockerfile | 21 ++++++++++++++++ README.md | 18 ++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 Dockerfile diff --git a/.github/workflows/commit.yaml b/.github/workflows/commit.yaml index f8966c4..367cafc 100644 --- a/.github/workflows/commit.yaml +++ b/.github/workflows/commit.yaml @@ -60,3 +60,50 @@ jobs: - name: Run tests run: cargo test --verbose + + docker_build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login into GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v6 + with: + # TODO: setup caches. + platforms: linux/amd64,linux/arm64 + tags: ghcr.io/envoyproxy/dynamic-modules-examples:${{ github.sha }} + + - name: Push as latest + if: github.event_name == 'push' + run: + docker tag ghcr.io/envoyproxy/dynamic-modules-examples:${{ github.sha }} ghcr.io/envoyproxy/dynamic-modules-examples:latest + docker push ghcr.io/envoyproxy/dynamic-modules-examples:latest + + e2e_test: + name: E2E Test (${{ matrix.platform.arch }}) + runs-on: ${{ matrix.platform.os }} + strategy: + fail-fast: false + matrix: + platform: + - os: ubuntu-22.04 + arch: amd64 + - os: ubuntu-22.04-arm + arch: arm64 + + steps: + - run: echo 'TODO' diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1b6e9de --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +FROM --platform=$BUILDPLATFORM rust:1.84 AS rust_builder + +# We need libclang to do the bindgen. +RUN apt update && apt install -y clang + +WORKDIR /app + +# Cache dependencies by copying only the Cargo files and fetching them. +COPY ./rust/Cargo.toml ./rust/Cargo.lock ./ +RUN mkdir src && echo "" > src/lib.rs +RUN cargo fetch +RUN rm -rf src + +# Then, copy the entire source code and build. +COPY ./rust . +RUN cargo build + +# Finally, copy the built library to the final image. +FROM --platform=$BUILDPLATFORM envoyproxy/envoy@sha256:9ca0dcc84ec582b7ece0ccf6c24af76268d017c87376f69a0dc4a1a0ab55b4c4 AS envoy +ENV ENVOY_DYNAMIC_MODULES_SEARCH_PATH=/usr/local/lib +COPY --from=rust_builder /app/target/debug/librust_module.so /usr/local/lib/librust_module.so diff --git a/README.md b/README.md index a616ff2..01a92f4 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,24 @@ like Lua filters, Wasm filters, or External Processors. Currently, the only language supported is Rust, so this repository contains examples of dynamic modules written in Rust. Future examples will be added in other languages once the support is available. +## Build + + +To build and test the modules locally without Envoy, you can use `cargo` to build them. + +``` +cargo build --manifest-path rust/Cargo.toml +cargo test --manifest-path rust/Cargo.toml +``` + +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. + [78efd97]: https://github.com/envoyproxy/envoy/tree/78efd97 [Envoy]: https://github.com/envoyproxy/envoy [High Level Doc]: https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/advanced/dynamic_modules From 430c2ae9f59b0563f98c126894a502a98d17f69c Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Fri, 7 Feb 2025 07:20:10 +0900 Subject: [PATCH 2/6] more Signed-off-by: Takeshi Yoneda --- .github/workflows/commit.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/commit.yaml b/.github/workflows/commit.yaml index 367cafc..7f3f9fa 100644 --- a/.github/workflows/commit.yaml +++ b/.github/workflows/commit.yaml @@ -62,6 +62,7 @@ jobs: run: cargo test --verbose docker_build: + name: Build and Push multi-arch Docker image runs-on: ubuntu-latest steps: - name: Checkout @@ -85,6 +86,7 @@ jobs: with: # TODO: setup caches. platforms: linux/amd64,linux/arm64 + push: true tags: ghcr.io/envoyproxy/dynamic-modules-examples:${{ github.sha }} - name: Push as latest @@ -94,6 +96,7 @@ jobs: docker push ghcr.io/envoyproxy/dynamic-modules-examples:latest e2e_test: + needs: [docker_build] name: E2E Test (${{ matrix.platform.arch }}) runs-on: ${{ matrix.platform.os }} strategy: From e54497bcb0d97c0c531ebf7eec8b33927781bc02 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Fri, 7 Feb 2025 07:22:27 +0900 Subject: [PATCH 3/6] more Signed-off-by: Takeshi Yoneda --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 01a92f4..f9db23a 100644 --- a/README.md +++ b/README.md @@ -14,14 +14,19 @@ Future examples will be added in other languages once the support is available. ## Build +### Rust -To build and test the modules locally without Envoy, you can use `cargo` to build them. +To build and test the modules locally without Envoy, you can use `cargo` to build them just like any other Rust project: ``` cargo build --manifest-path rust/Cargo.toml cargo test --manifest-path rust/Cargo.toml ``` +where `--manifest-path` is not required if you are in the `rust` directory. + +### Envoy + Dynamic Modules Docker Image + To build the example modules and bundle them with Envoy, simply run ``` From f01b0a69c3e210566d71345689370c083aa00d47 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Fri, 7 Feb 2025 07:26:26 +0900 Subject: [PATCH 4/6] more Signed-off-by: Takeshi Yoneda --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index f9db23a..a67563a 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,9 @@ like Lua filters, Wasm filters, or External Processors. Currently, the only language supported is Rust, so this repository contains examples of dynamic modules written in Rust. Future examples will be added in other languages once the support is available. +This repository serves as a reference for developers who want to create their own dynamic modules for Envoy including +how to setup the project, how to build it, and how to test it, etc. + ## Build ### Rust From 6400a041fbe35735f57a5f416d02b162438dea77 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Fri, 7 Feb 2025 07:26:47 +0900 Subject: [PATCH 5/6] more Signed-off-by: Takeshi Yoneda --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a67563a..0158197 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ how to setup the project, how to build it, and how to test it, etc. ## Build -### Rust +### Rust Dynamic Modules To build and test the modules locally without Envoy, you can use `cargo` to build them just like any other Rust project: From 8c0bca5bb880a49ac38f96602333fe8716e224d0 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Fri, 7 Feb 2025 07:33:16 +0900 Subject: [PATCH 6/6] more Signed-off-by: Takeshi Yoneda --- README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 0158197..0322c42 100644 --- a/README.md +++ b/README.md @@ -15,19 +15,20 @@ Future examples will be added in other languages once the support is available. This repository serves as a reference for developers who want to create their own dynamic modules for Envoy including how to setup the project, how to build it, and how to test it, etc. -## Build +## Dvelopment ### Rust Dynamic Modules To build and test the modules locally without Envoy, you can use `cargo` to build them just like any other Rust project: ``` -cargo build --manifest-path rust/Cargo.toml -cargo test --manifest-path rust/Cargo.toml +cd rust +cargo build +cargo test +cargo cargo clippy -- -D warnings +cargo fmt --all -- --check ``` -where `--manifest-path` is not required if you are in the `rust` directory. - ### Envoy + Dynamic Modules Docker Image To build the example modules and bundle them with Envoy, simply run