From 468ea920ddc4bb3ad98d28671bd36d420d6960c1 Mon Sep 17 00:00:00 2001 From: Tim Geoghegan Date: Fri, 5 May 2023 13:44:38 -0700 Subject: [PATCH] Enable `divviup-api` in Kind integration tests (#72) - set the API handler as the default should none of the handlers registered in `OriginHandler` match - build and publish a container image built with feature `integration-test` to GAR --- .github/workflows/docker-release.yml | 17 +++++++++++++++-- .github/workflows/docker.yml | 9 ++++++++- Dockerfile | 11 +++++++++-- src/handler.rs | 5 ++--- 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/.github/workflows/docker-release.yml b/.github/workflows/docker-release.yml index 676942af..2d2c5691 100644 --- a/.github/workflows/docker-release.yml +++ b/.github/workflows/docker-release.yml @@ -9,6 +9,12 @@ env: jobs: build-and-push: + strategy: + matrix: + image: [ + { name: "divviup_api", rust_features: "default" }, + { name: "divviup_api_integration_test", rust_features: "integration-testing" }, + ] permissions: id-token: write contents: read @@ -32,5 +38,12 @@ jobs: password: ${{ steps.gcp-auth.outputs.access_token }} - id: get_version run: echo VERSION=${GITHUB_REF/refs\/tags\//} >> $GITHUB_OUTPUT - - run: docker build --tag us-west2-docker.pkg.dev/janus-artifacts/divviup-api/divviup_api:${{ steps.get_version.outputs.VERSION }} --build-arg GIT_REVISION=${GIT_REVISION} . - - run: docker push us-west2-docker.pkg.dev/janus-artifacts/divviup-api/divviup_api:${{ steps.get_version.outputs.VERSION }} + - run: |- + docker build \ + --tag us-west2-docker.pkg.dev/janus-artifacts/divviup-api/${{ matrix.image.name }}:${{ steps.get_version.outputs.VERSION }} \ + --build-arg RUST_FEATURES=${{ matrix.image.rust_features }} \ + --build-arg GIT_REVISION=${GIT_REVISION} \ + . + - run: |- + docker push \ + us-west2-docker.pkg.dev/janus-artifacts/divviup-api/${{ matrix.image.name }}:${{ steps.get_version.outputs.VERSION }} diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 5b06ae20..890301dc 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -11,8 +11,15 @@ env: jobs: build: + strategy: + matrix: + rust-features: ["default", "integration-testing"] runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - run: echo "GIT_REVISION=$(git describe --always --dirty=-modified)" >> $GITHUB_ENV - - run: docker build --build-arg GIT_REVISION=${GIT_REVISION} . + - run: |- + docker build \ + --build-arg GIT_REVISION=${GIT_REVISION} \ + --build-arg RUST_FEATURES=${{ matrix.rust-features }} \ + . diff --git a/Dockerfile b/Dockerfile index 05314d2d..67e1beef 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,8 +9,15 @@ COPY build.rs /src/build.rs COPY migration /src/migration COPY src /src/src RUN cd app && npm ci -RUN --mount=type=cache,target=/usr/local/cargo/registry --mount=type=cache,target=/src/target cargo build --profile release -p migration && cp /src/target/release/migration /migration -RUN --mount=type=cache,target=/usr/local/cargo/registry --mount=type=cache,target=/src/target cargo build --profile release && cp /src/target/release/divviup_api_bin /divviup_api_bin +ARG RUST_FEATURES=default +RUN --mount=type=cache,target=/usr/local/cargo/registry \ + --mount=type=cache,target=/src/target \ + cargo build --profile release -p migration && \ + cp /src/target/release/migration /migration +RUN --mount=type=cache,target=/usr/local/cargo/registry \ + --mount=type=cache,target=/src/target \ + cargo build --profile release --features ${RUST_FEATURES} && \ + cp /src/target/release/divviup_api_bin /divviup_api_bin FROM alpine:3.17.3 ARG GIT_REVISION=unknown diff --git a/src/handler.rs b/src/handler.rs index d8c40dc9..6242fc7e 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -52,9 +52,8 @@ impl DivviupApi { caching_headers(), conn_id(), logger(), - origin_router() - .with_handler(config.app_url.as_ref(), static_assets(&config)) - .with_handler(config.api_url.as_ref(), api(&db, &config)), + origin_router().with_handler(config.app_url.as_ref(), static_assets(&config)), + api(&db, &config), ErrorHandler, )), db,