From 66df4f63373659a1e66ef596d4d347c9fab75e1d Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Wed, 2 Sep 2026 00:06:52 +1000 Subject: [PATCH] ci(deploy): cache image layers and cancel superseded deploy runs Both images built via plain docker build/push with no cache, so every push to main rebuilt archie-agent's full toolchain (apt packages, golangci-lint, gofumpt, buf, uv+python, npm globals) from scratch -- several minutes, even when none of those inputs changed. Switch to docker/build-push-action with GHA-backed layer caching per image. Also add a concurrency group so a burst of pushes (e.g. a fix commit immediately followed by its release commit) cancels the superseded deploy rather than running three in parallel for capacity none of them can use -- only the last one's :latest push matters anyway. --- .github/workflows/deploy.yml | 52 +++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 12 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 1a022606e..71ec442e0 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -8,6 +8,16 @@ on: branches: [main] tags: ["archied/v*", "archie/v*"] +# Rapid successive pushes to main (a release commit right after its +# preceding fix, say) previously queued a full gate+build for each one, +# several minutes apiece, with no caching -- so a burst of pushes left +# three deploys racing in parallel for the same runner capacity. Only the +# last one's images matter (both jobs push :latest), so cancel a +# superseded run rather than let it fight for resources it can't use. +concurrency: + group: deploy-${{ github.ref }} + cancel-in-progress: true + permissions: contents: read packages: write @@ -103,10 +113,14 @@ jobs: with: fetch-depth: 0 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Log in to GHCR run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin - - name: Build and push archied + - name: Resolve component versions + id: versions run: | GATEWAY_TAG="$(git tag --points-at HEAD --list 'archied/v*' | sort -V | tail -1)" RUNTIME_TAG="$(git tag --points-at HEAD --list 'archie/v*' | sort -V | tail -1)" @@ -114,16 +128,30 @@ jobs: RUNTIME_VERSION="${RUNTIME_TAG#archie/}" [ -n "$GATEWAY_VERSION" ] || GATEWAY_VERSION=dev [ -n "$RUNTIME_VERSION" ] || RUNTIME_VERSION=dev - docker build \ - --build-arg GATEWAY_VERSION="$GATEWAY_VERSION" \ - --build-arg RUNTIME_VERSION="$RUNTIME_VERSION" \ - -f Dockerfile.archied -t ghcr.io/samcharles93/archied:latest . - docker push ghcr.io/samcharles93/archied:latest + echo "gateway=$GATEWAY_VERSION" >> "$GITHUB_OUTPUT" + echo "runtime=$RUNTIME_VERSION" >> "$GITHUB_OUTPUT" + + - name: Build and push archied + uses: docker/build-push-action@v6 + with: + context: . + file: Dockerfile.archied + push: true + tags: ghcr.io/samcharles93/archied:latest + build-args: | + GATEWAY_VERSION=${{ steps.versions.outputs.gateway }} + RUNTIME_VERSION=${{ steps.versions.outputs.runtime }} + cache-from: type=gha,scope=archied + cache-to: type=gha,mode=max,scope=archied - name: Build and push archie-agent - run: | - RUNTIME_TAG="$(git tag --points-at HEAD --list 'archie/v*' | sort -V | tail -1)" - RUNTIME_VERSION="${RUNTIME_TAG#archie/}" - [ -n "$RUNTIME_VERSION" ] || RUNTIME_VERSION=dev - docker build --build-arg RUNTIME_VERSION="$RUNTIME_VERSION" -f Dockerfile -t ghcr.io/samcharles93/archie-agent:latest . - docker push ghcr.io/samcharles93/archie-agent:latest + uses: docker/build-push-action@v6 + with: + context: . + file: Dockerfile + push: true + tags: ghcr.io/samcharles93/archie-agent:latest + build-args: | + RUNTIME_VERSION=${{ steps.versions.outputs.runtime }} + cache-from: type=gha,scope=archie-agent + cache-to: type=gha,mode=max,scope=archie-agent