diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 35e8037e..abb2de22 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -130,6 +130,8 @@ jobs: - build env: publish: ${{contains(fromJSON('["push", "release"]'), github.event_name)}} + outputs: + version: ${{ steps.meta.outputs.version }} steps: - uses: actions/checkout@v7 @@ -184,3 +186,18 @@ jobs: if: ${{ fromJSON(env.publish) }} run: | docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} + + smoke-test: + name: Smoke test published image + needs: + - merge + if: github.event_name == 'release' + uses: ./.github/workflows/smoke-test.yml + with: + version: ${{ needs.merge.outputs.version }} + secrets: + CS_VAULT_CLIENT_ID: ${{ secrets.CS_VAULT_CLIENT_ID }} + CS_VAULT_CLIENT_KEY: ${{ secrets.CS_VAULT_CLIENT_KEY }} + CS_VAULT_CLIENT_ACCESS_KEY: ${{ secrets.CS_VAULT_CLIENT_ACCESS_KEY }} + CS_VAULT_WORKSPACE_CRN: ${{ secrets.CS_VAULT_WORKSPACE_CRN }} + SLACK_NOTIFICATION_WEBHOOK_URL: ${{ secrets.SLACK_NOTIFICATION_WEBHOOK_URL }} diff --git a/.github/workflows/smoke-test.yml b/.github/workflows/smoke-test.yml new file mode 100644 index 00000000..f575ddc8 --- /dev/null +++ b/.github/workflows/smoke-test.yml @@ -0,0 +1,97 @@ +name: Smoke test + +# Runs the integration suite against a published Proxy image instead of one built from source. +# `release.yml` calls it after a release's image is published. +# A pull request that changes this workflow runs it against the `latest` published image. +on: + workflow_call: + inputs: + version: + description: Published image version to test, such as 3.1.1 + required: true + type: string + secrets: + CS_VAULT_CLIENT_ID: + required: true + CS_VAULT_CLIENT_KEY: + required: true + CS_VAULT_CLIENT_ACCESS_KEY: + required: true + CS_VAULT_WORKSPACE_CRN: + required: true + SLACK_NOTIFICATION_WEBHOOK_URL: + required: false + pull_request: + branches: + - main + paths: + - '.github/workflows/smoke-test.yml' + +permissions: + contents: read + +env: + CARGO_TERM_COLOR: always + +jobs: + smoke-test: + name: Smoke test cipherstash/proxy:${{ inputs.version || 'latest' }} (PostgreSQL ${{ matrix.pg_version }}) + runs-on: blacksmith-16vcpu-ubuntu-2204 + strategy: + fail-fast: false + matrix: + pg_version: [14, 15, 16, 17] # PG 18 not currently supported + env: + PG_VERSION: ${{ matrix.pg_version }} + PROXY_IMAGE: cipherstash/proxy:${{ inputs.version || 'latest' }} + CS_ZEROKMS_HOST: https://us-east-1.aws.zerokms.cipherstashmanaged.net + CS_CTS_HOST: https://ap-southeast-2.aws.cts.cipherstashmanaged.net + timeout-minutes: 30 + + steps: + - uses: actions/checkout@v7 + - uses: ./.github/actions/setup-test + + - name: Decrypt secrets + uses: cipherstash/secrets-action@main + with: + secrets-file: .github/secrets.env.encrypted + env: + CS_CLIENT_ID: ${{ secrets.CS_VAULT_CLIENT_ID }} + CS_CLIENT_KEY: ${{ secrets.CS_VAULT_CLIENT_KEY }} + CS_CLIENT_ACCESS_KEY: ${{ secrets.CS_VAULT_CLIENT_ACCESS_KEY }} + CS_WORKSPACE_CRN: ${{ secrets.CS_VAULT_WORKSPACE_CRN }} + + - name: Show the image under test + run: | + docker pull --quiet "${PROXY_IMAGE}" + docker image inspect "${PROXY_IMAGE}" --format '{{index .RepoDigests 0}} {{.Created}}' + + - run: | + mise run postgres:up --extra-args "--detach --wait" + + - name: Run integration tests against the published image + env: + RUST_BACKTRACE: "1" + run: | + mise run --output prefix test:integration + + - name: Show proxy logs on failure + if: failure() + run: | + docker logs --timestamps proxy 2>&1 || true + docker logs --timestamps proxy-tls 2>&1 || true + + # The image is already published, so say so. Not the shared send-slack-notification + # action: it only fires on main, and a release run's ref is the tag. + - name: Notify Slack on failure + if: failure() && github.event_name == 'release' + uses: slackapi/slack-github-action@v1 + with: + payload: | + { + "text": ":alert::alert::alert:\n\nSmoke test failed for the published image `${{ env.PROXY_IMAGE }}`.\n\n<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|View run>", + "channel": "#engineering" + } + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_NOTIFICATION_WEBHOOK_URL }} diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 48154713..3181fc2c 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -380,7 +380,7 @@ Running Proxy in a container cross-compiles a binary for Linux and the current a We cross-compile binary outside the container because it's generally faster, due to packages already being cached, and slower network and disk IO in Docker. > [!IMPORTANT] -> **Proxy must always be built from source for testing.** The `proxy:up` task builds a binary from source (`build:binary`), packages it into a Docker image tagged `cipherstash/proxy:latest` (`build:docker`), then starts it via `docker compose up`. The `tests/docker-compose.yml` file uses `pull_policy: never` on the proxy services to ensure Docker never pulls the released image from Docker Hub. If you see an error like `pull access denied` or `image not found`, run `mise run build` first to build the local image. +> **Proxy is built from source for testing, unless `PROXY_IMAGE` is set** (see [Integration tests](#integration-tests)). The `proxy:up` task builds a binary from source (`build:binary`), packages it into a Docker image tagged `cipherstash/proxy:latest` (`build:docker`), then starts it via `docker compose up`. The `tests/docker-compose.yml` file uses `pull_policy: never` on the proxy services to ensure Docker never pulls the released image from Docker Hub. If you see an error like `pull access denied` or `image not found`, run `mise run build` first to build the local image. > The released-image RSS rig is the one exception: it measures published images on purpose, so it pulls them. > See [`packages/cipherstash-proxy-burn-in/README.md`](packages/cipherstash-proxy-burn-in/README.md). @@ -460,6 +460,17 @@ Integration tests are defined in `tests/tasks/test/`. Integration tests verify behaviour from a PostgreSQL client (`psql`), to Proxy (running in a container), to a PostgreSQL instance (running in a container). +By default `mise run proxy:up` builds the Proxy image from source, so the tests run against your working tree. +To run them against a published image instead, set `PROXY_IMAGE`: + +```bash +PROXY_IMAGE=cipherstash/proxy:3.1.1 mise run test:integration +``` + +`proxy:up` then pulls that image if it isn't already present locally, tags it as `cipherstash/proxy:latest`, the image `tests/docker-compose.yml` runs, and skips the build. +The test clients still come from your checkout, so check out the release's tag to test it with its own tests. +After a release is published, `release.yml` runs this suite against the new image in the `Smoke test published image` job. + The integration tests have several runtime dependencies: - Running PostgreSQL instances (that can be started with `mise run postgres:up`) @@ -545,7 +556,7 @@ This project uses `docker compose` to manage containers and networking. The configuration for those containers is in `tests/docker-compose.yml`. -The proxy services in `tests/docker-compose.yml` use `pull_policy: never` to ensure Docker never pulls the released `cipherstash/proxy:latest` image from Docker Hub. The image must be built locally from source via `mise run proxy:up` (or `mise run build`). This guarantees integration tests always run against the current source code. +The proxy services in `tests/docker-compose.yml` use `pull_policy: never` to ensure Docker never pulls the released `cipherstash/proxy:latest` image from Docker Hub. The image is built locally from source via `mise run proxy:up` (or `mise run build`), so integration tests run against the current source code. With `PROXY_IMAGE` set, `proxy:up` pulls that published image and tags it as `cipherstash/proxy:latest` instead. The integration tests use the `proxy:up` and `proxy:down` commands documented above to run containers in different configurations. diff --git a/mise.toml b/mise.toml index 80ef048c..4dccc3bb 100644 --- a/mise.toml +++ b/mise.toml @@ -71,11 +71,17 @@ set -e {% set target = target_arch ~ "-unknown-linux-gnu" %} {% set docker_platform = "linux/" ~ arch() | replace(from="x64", to="amd64") %} -# build a binary -mise run build:binary --target {{target}} - -# build a new container -mise run build:docker --platform {{docker_platform}} +if [ -n "${PROXY_IMAGE:-}" ]; then + # Test a published image instead of building from source. + # tests/docker-compose.yml never pulls, so tag the image as the one it runs. + # Pull only when missing: test:integration calls proxy:up many times. + echo "Using published image: ${PROXY_IMAGE}" + docker image inspect "${PROXY_IMAGE}" >/dev/null 2>&1 || docker pull --quiet "${PROXY_IMAGE}" + docker tag "${PROXY_IMAGE}" cipherstash/proxy:latest +else + mise run build:binary --target {{target}} + mise run build:docker --platform {{docker_platform}} +fi # Make the default invocation with `mise run proxy:up` work. # The default mise environment configuration works for Proxy running as a process, connecting via a port forward. diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml index 9c3e606b..3fe7ff26 100644 --- a/tests/docker-compose.yml +++ b/tests/docker-compose.yml @@ -48,10 +48,10 @@ services: proxy: image: cipherstash/proxy:latest - # Never pull from Docker Hub. The proxy image must be built from source - # via `mise run proxy:up` (which runs build:binary + build:docker). - # This ensures integration tests always run against the current source, - # not the released version on Docker Hub. + # Never pull from Docker Hub. `mise run proxy:up` builds this image from + # source (build:binary + build:docker), so integration tests run against + # the current source. With PROXY_IMAGE set, proxy:up instead pulls that + # published image and tags it as cipherstash/proxy:latest. pull_policy: never container_name: proxy ports: