From 4ede609cbece205aea54ee93a773df18f4f8cae4 Mon Sep 17 00:00:00 2001 From: JesperTerkelsen <99995+JesperTerkelsen@users.noreply.github.com> Date: Sun, 15 Nov 2026 06:28:41 +0000 Subject: [PATCH] feat(component-build): accept a prebuilt artifact and let callers skip cache mounts --- .github/workflows/component-build.yml | 21 ++++++++++++++++++--- .github/workflows/deploy-generic-v2.yml | 12 ++++++++++++ CLAUDE.md | 3 +++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/.github/workflows/component-build.yml b/.github/workflows/component-build.yml index ef6270b4..06d10edf 100644 --- a/.github/workflows/component-build.yml +++ b/.github/workflows/component-build.yml @@ -50,6 +50,16 @@ on: required: false type: string description: 'Git SHA to checkout and build from. Defaults to the triggering commit SHA.' + prebuilt-artifact: + required: false + type: string + default: '' + description: "Name of an artifact an earlier job in the run uploaded, downloaded into the root of the build context before the Docker build, such as a binary compiled on the runner. Artifacts don't keep file modes, so the Dockerfile should COPY it with --chmod." + dockerfile-cache-mounts: + required: false + type: boolean + default: true + description: "Restore and save the Dockerfile's RUN --mount=type=cache contents on ARC. Turn it off when the build skips the stages that use them, such as with a prebuilt-artifact." secrets: AWS_ACCOUNT_ID: required: true @@ -128,6 +138,11 @@ jobs: uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 with: ref: ${{ inputs.git-sha || github.sha }} + - name: Download prebuilt artifact + if: ${{ inputs.prebuilt-artifact != '' }} + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8 + with: + name: ${{ inputs.prebuilt-artifact }} - name: Configure AWS credentials via assumed role uses: aws-actions/configure-aws-credentials@e7f100cf4c008499ea8adda475de1042d6975c7b # v6 with: @@ -151,7 +166,7 @@ jobs: uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4 - name: Restore Dockerfile cache mounts id: cache-mounts - if: ${{ (inputs.use-arc-runners && github.event.repository.private) && env.S3_CACHE != 'true' }} + if: ${{ (inputs.use-arc-runners && github.event.repository.private) && inputs.dockerfile-cache-mounts && env.S3_CACHE != 'true' }} uses: actions/cache@caa296126883cff596d87d8935842f9db880ef25 # v5 with: &cache-mounts path: ${{ runner.temp }}/buildkit-cache-mounts @@ -160,7 +175,7 @@ jobs: buildkit-cache-mounts-${{ inputs.docker-file-name }}- - name: Restore Dockerfile cache mounts (S3) id: cache-mounts-s3 - if: ${{ env.S3_CACHE == 'true' }} + if: ${{ inputs.dockerfile-cache-mounts && env.S3_CACHE == 'true' }} uses: runs-on/cache@88d90644011a3a9957fd141a106f5a94f9794203 # v5.0.7 env: RUNS_ON_S3_BUCKET_CACHE: monta-github-ci-cache @@ -171,7 +186,7 @@ jobs: AWS_REGION: eu-west-1 with: *cache-mounts - name: Inject Dockerfile cache mounts into the builder - if: ${{ (inputs.use-arc-runners && github.event.repository.private) }} + if: ${{ (inputs.use-arc-runners && github.event.repository.private) && inputs.dockerfile-cache-mounts }} uses: reproducible-containers/buildkit-cache-dance@5422eac04292c961a382e0f584ea0f03ad9da723 # v3.4.0 with: dockerfile: ${{ inputs.docker-file-name }} diff --git a/.github/workflows/deploy-generic-v2.yml b/.github/workflows/deploy-generic-v2.yml index 6a4e35c8..cf039f69 100644 --- a/.github/workflows/deploy-generic-v2.yml +++ b/.github/workflows/deploy-generic-v2.yml @@ -75,6 +75,16 @@ on: required: false type: string description: 'Git SHA to checkout and build from. Defaults to the triggering commit SHA.' + prebuilt-artifact: + required: false + type: string + default: '' + description: "Name of an artifact an earlier job in the run uploaded, downloaded into the root of the build context before the Docker build. Needs the caller to run that job first: pass it in the same workflow run (see component-build.yml)." + dockerfile-cache-mounts: + required: false + type: boolean + default: true + description: "Restore and save the Dockerfile's RUN --mount=type=cache contents on ARC. Turn it off when the build skips the stages that use them." argocd-resource-name: required: false type: string @@ -179,6 +189,8 @@ jobs: additional-build-args: ${{ inputs.additional-build-args }} ecr-repository-name: ${{ inputs.ecr-repository-name }} git-sha: ${{ inputs.git-sha }} + prebuilt-artifact: ${{ inputs.prebuilt-artifact }} + dockerfile-cache-mounts: ${{ inputs.dockerfile-cache-mounts }} secrets: AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }} SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} diff --git a/CLAUDE.md b/CLAUDE.md index 9a70a638..6279ee57 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -5,6 +5,9 @@ - **Latest SHA**: 84fb68d (check for newer commits) - **Changes**: new `pnpm-dependency-submission.yml` and `pnpm-dependency-graph` action for pnpm 12 lockfiles +## Recent Changes (2026-11-15) +1. **`prebuilt-artifact` and `dockerfile-cache-mounts` on `component-build.yml` and `deploy-generic-v2.yml`**: a caller can compile on the runner in a job of its own (with a runner-side compile cache, such as `actions/setup-go` plus `runs-on/cache`), upload the result as an artifact and pass its name as `prebuilt-artifact`; the build job downloads it into the root of the build context before `docker build`, so the Dockerfile only `COPY --chmod=755`s it (artifacts drop file modes). `dockerfile-cache-mounts: false` skips restoring, injecting and saving the Dockerfile's cache mounts, which such a Dockerfile no longer uses: on infra-portal they cost ~70 s to restore and inject and, saved, ~135 s to extract and upload. Both default to the old behaviour. + ## Recent Changes (2026-11-14) 1. **Dockerfile cache mounts live outside the checkout and, on S3, are saved every build**: `component-build.yml` restores the cache mounts into `${{ runner.temp }}/buildkit-cache-mounts` (and cache-dance's scratch dir into `runner.temp`) instead of `buildkit-cache-mounts` in the checkout. With the folder in the checkout, a Dockerfile that runs `COPY . .` without a `.dockerignore` shipped the whole restored cache (1.3 GB for infra-portal's Go caches) as build context, baked it into a layer and compressed it into the registry cache on every build. On the S3 backend the key also ends in the commit SHA, so every build saves its caches and the next one restores the newest saved for the Dockerfile (the existing prefix restore key). Before, the key changed only with the lockfiles, so the Go build cache (and Gradle's) went stale with every commit: infra-portal's `go build` took ~130 s with the cache restored, against ~11 s locally with a fresh one. The `actions/cache` backend keeps the lockfile-only key, since per-commit saves would churn the 10 GB GitHub cache quota.