A one-of-a-kind resume builder that keeps your privacy in mind. Completely secure, customizable, portable, open-source and free forever. Try it out today!
TypeScript agent-skillsaidsh-pluginhacktoberfestjavascriptmcp-serverreactresume-builderself-hostedtypescript
ci: promote existing Docker images for releases
Amruth Pillai8c91421a58f9
diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.ymlindex 3da8ab025..98b32b32b 100644--- a/.github/workflows/docker-build.yml+++ b/.github/workflows/docker-build.yml@@ -1,10 +1,10 @@-name: Build Docker Image+name: Publish Docker Imageon:workflow_dispatch:inputs:release:- description: Publish release aliases and redeploy production (false runs a cache-only build, then publishes a canary)+ description: Promote existing SHA image (branch updates latest; release tag also updates semver) and redeploy productiontype: booleandefault: falsepush:@@ -14,8 +14,9 @@ on:- "v*"concurrency:- group: ${{ github.workflow }}-${{ github.ref }}- cancel-in-progress: true+ # Preserve builds for every pushed commit, even when newer commits arrive.+ group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.sha }}+ cancel-in-progress: falseenv:GHCR_IMAGE: ghcr.io/${{ github.repository }}@@ -39,22 +40,25 @@ jobs:GIT_REF: ${{ github.ref }}RELEASE: ${{ inputs.release }}run: |+ nightly=false+ release=false+ canary=falseif [[ "$EVENT_NAME" == "push" && "$GIT_REF" == "refs/heads/main" ]]; then- echo "nightly=true" >> "$GITHUB_OUTPUT"- echo "release=false" >> "$GITHUB_OUTPUT"- echo "canary=false" >> "$GITHUB_OUTPUT"+ nightly=trueelif [[ "$EVENT_NAME" == "workflow_dispatch" && "$RELEASE" != "true" ]]; then- echo "nightly=false" >> "$GITHUB_OUTPUT"- echo "release=false" >> "$GITHUB_OUTPUT"- echo "canary=true" >> "$GITHUB_OUTPUT"+ canary=trueelse- echo "nightly=false" >> "$GITHUB_OUTPUT"- echo "release=true" >> "$GITHUB_OUTPUT"- echo "canary=false" >> "$GITHUB_OUTPUT"+ release=truefi+ {+ echo "nightly=$nightly"+ echo "release=$release"+ echo "canary=$canary"+ } >> "$GITHUB_OUTPUT"build:needs: mode+ if: ${{ needs.mode.outputs.release != 'true' }}strategy:fail-fast: false@@ -85,6 +89,10 @@ jobs:if: ${{ vars.USE_BLACKSMITH == 'true' }}uses: useblacksmith/checkout@v1+ - name: Resolve commit SHA+ id: source+ run: echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"+- name: Setup Docker Buildxif: ${{ vars.USE_BLACKSMITH != 'true' }}uses: docker/setup-buildx-action@v4@@ -143,20 +151,7 @@ jobs:with:images: ${{ steps.registries.outputs.images }}tags: |- type=sha,prefix=sha-,suffix=-${{ matrix.arch }}-- - name: Cache-only smoke build- if: ${{ needs.mode.outputs.canary == 'true' && vars.USE_BLACKSMITH != 'true' }}- uses: docker/build-push-action@v7- with: &cache-only-build- context: .- platforms: ${{ matrix.platform }}- outputs: type=cacheonly-- - name: Cache-only smoke build (Blacksmith)- if: ${{ needs.mode.outputs.canary == 'true' && vars.USE_BLACKSMITH == 'true' }}- uses: useblacksmith/build-push-action@v2- with: *cache-only-build+ type=raw,value=sha-${{ steps.source.outputs.sha }}-${{ matrix.arch }}- name: Build and Push by Digestid: build@@ -193,10 +188,12 @@ jobs:retention-days: 1merge:+ # Release runs skip build; failed builds must never publish partial indexes.+ if: ${{ !cancelled() && needs.mode.result == 'success' && (needs.build.result == 'success' || needs.build.result == 'skipped') }}needs:- mode- build- timeout-minutes: 30+ timeout-minutes: 45runs-on: ${{ vars.USE_BLACKSMITH == 'true' && 'blacksmith-2vcpu-ubuntu-2404' || 'ubuntu-latest' }}env:@@ -214,7 +211,9 @@ jobs:if: ${{ vars.USE_BLACKSMITH != 'true' }}uses: actions/checkout@v6with: &checkout-package-json- sparse-checkout: package.json+ sparse-checkout: |+ package.json+ tooling/dockersparse-checkout-cone-mode: false- name: Checkout Repository (Blacksmith)@@ -222,11 +221,37 @@ jobs:uses: useblacksmith/checkout@v1with: *checkout-package-json- - name: Get version from package.json+ - name: Resolve publishing version and commitid: version- run: echo "version=$(jq -r .version package.json)" >> "$GITHUB_OUTPUT"+ env:+ GIT_REF: ${{ github.ref }}+ run: |+ set -euo pipefail+ version=$(jq -r .version package.json)+ prerelease=false+ tagged=false+ if [[ "$GIT_REF" == refs/tags/v* ]]; then+ version="${GIT_REF#refs/tags/v}"+ if [[ ! "$version" =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-[0-9A-Za-z.-]+)?$ ]]; then+ echo "::error::Release tag must be vMAJOR.MINOR.PATCH, optionally with a prerelease suffix."+ exit 1+ fi+ if [[ "$version" != "$(jq -r .version package.json)" ]]; then+ echo "::error::Release tag version must match package.json; promotion cannot change the built app version."+ exit 1+ fi+ if [[ "$version" == *-* ]]; then prerelease=true; fi+ tagged=true+ fi+ {+ echo "version=$version"+ echo "sha=$(git rev-parse HEAD)"+ echo "prerelease=$prerelease"+ echo "tagged=$tagged"+ } >> "$GITHUB_OUTPUT"- name: Download digests+ if: ${{ needs.mode.outputs.release != 'true' }}uses: actions/download-artifact@v8with:path: /tmp/digests@@ -267,32 +292,45 @@ jobs:uses: docker/metadata-action@v6with:images: ${{ steps.registries.outputs.images }}+ flavor: latest=falsetags: |- type=sha,prefix=sha-+ type=raw,value=sha-${{ steps.version.outputs.sha }},enable=${{ needs.mode.outputs.release != 'true' }}type=raw,value=canary-${{ github.run_id }}-${{ github.run_attempt }},enable=${{ needs.mode.outputs.canary == 'true' }}type=raw,value=nightly,enable=${{ needs.mode.outputs.nightly == 'true' }}type=raw,value=nightly-{{date 'YYYYMMDDHHmmss' tz='UTC'}},enable=${{ needs.mode.outputs.nightly == 'true' }}- type=raw,value=latest,enable=${{ needs.mode.outputs.release == 'true' }}- type=raw,value=v${{ steps.version.outputs.version }},enable=${{ needs.mode.outputs.release == 'true' }}- type=raw,value=v${{ steps.semver.outputs.major }}.${{ steps.semver.outputs.minor }},enable=${{ needs.mode.outputs.release == 'true' }}- type=raw,value=v${{ steps.semver.outputs.major }},enable=${{ needs.mode.outputs.release == 'true' }}+ type=raw,value=latest,enable=${{ needs.mode.outputs.release == 'true' && steps.version.outputs.prerelease != 'true' }}+ type=raw,value=v${{ steps.version.outputs.version }},enable=${{ needs.mode.outputs.release == 'true' && steps.version.outputs.tagged == 'true' }}+ type=raw,value=v${{ steps.semver.outputs.major }}.${{ steps.semver.outputs.minor }},enable=${{ needs.mode.outputs.release == 'true' && steps.version.outputs.tagged == 'true' && steps.version.outputs.prerelease != 'true' }}+ type=raw,value=v${{ steps.semver.outputs.major }},enable=${{ needs.mode.outputs.release == 'true' && steps.version.outputs.tagged == 'true' && steps.version.outputs.prerelease != 'true' }}- name: Create manifest list and pushid: manifest+ if: ${{ needs.mode.outputs.release != 'true' }}working-directory: /tmp/digestsrun: |set -euo pipefailif [[ "${{ needs.mode.outputs.nightly }}" == "true" ]]; then- FINAL_TAG="nightly"+ FINAL_TAG="sha-${{ steps.version.outputs.sha }}"elif [[ "${{ needs.mode.outputs.canary }}" == "true" ]]; thenFINAL_TAG="canary-${{ github.run_id }}-${{ github.run_attempt }}"- else- FINAL_TAG="v${{ steps.version.outputs.version }}"fi+ if [[ "${{ needs.mode.outputs.nightly }}" == "true" ]]; then+ main_sha=$(git -C "$GITHUB_WORKSPACE" ls-remote origin refs/heads/main | cut -f1)+ if [[ "$main_sha" != "${{ steps.version.outputs.sha }}" ]]; then+ DOCKER_METADATA_OUTPUT_JSON=$(jq '.tags |= map(select(endswith(":nightly") | not))' <<< "$DOCKER_METADATA_OUTPUT_JSON")+ FINAL_TAG="sha-${{ steps.version.outputs.sha }}"+ fi+ fi++ mapfile -t tags < <(jq -r '.tags[]' <<< "$DOCKER_METADATA_OUTPUT_JSON")+ args=()+ for tag in "${tags[@]}"; do args+=(--tag "$tag"); done+ for digest in *; do args+=("${{ steps.registries.outputs.ghcr_image }}@sha256:$digest"); done+docker buildx imagetools create \- $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \+ "${args[@]}" \--annotation "index:org.opencontainers.image.licenses=MIT" \--annotation "index:org.opencontainers.image.title=Reactive Resume" \--annotation "index:org.opencontainers.image.description=A free and open-source resume builder." \@@ -300,37 +338,63 @@ jobs:--annotation "index:org.opencontainers.image.url=https://rxresu.me" \--annotation "index:org.opencontainers.image.documentation=https://docs.rxresu.me" \--annotation "index:org.opencontainers.image.source=https://github.com/${{ github.repository }}" \- --annotation "index:org.opencontainers.image.version=${{ steps.version.outputs.version }}" \- $(printf '${{ steps.registries.outputs.ghcr_image }}@sha256:%s ' *)+ --annotation "index:org.opencontainers.image.version=${{ steps.version.outputs.version }}"# Get the digest of the multi-arch manifest- GHCR_DIGEST=$(docker buildx imagetools inspect ${{ steps.registries.outputs.ghcr_image }}:${FINAL_TAG} --format '{{json .Manifest.Digest}}' | tr -d '"')+ GHCR_DIGEST=$(docker buildx imagetools inspect "${{ steps.registries.outputs.ghcr_image }}:${FINAL_TAG}" --format '{{json .Manifest.Digest}}' | tr -d '"')echo "final_tag=$FINAL_TAG" >> "$GITHUB_OUTPUT"echo "ghcr_digest=$GHCR_DIGEST" >> "$GITHUB_OUTPUT"if [[ "${{ steps.registries.outputs.dockerhub }}" == "true" ]]; then- DOCKER_DIGEST=$(docker buildx imagetools inspect ${{ steps.registries.outputs.docker_image }}:${FINAL_TAG} --format '{{json .Manifest.Digest}}' | tr -d '"')+ DOCKER_DIGEST=$(docker buildx imagetools inspect "${{ steps.registries.outputs.docker_image }}:${FINAL_TAG}" --format '{{json .Manifest.Digest}}' | tr -d '"')echo "docker_digest=$DOCKER_DIGEST" >> "$GITHUB_OUTPUT"fi+ - name: Promote existing SHA image+ id: promotion+ if: ${{ needs.mode.outputs.release == 'true' }}+ env:+ COMMIT_SHA: ${{ steps.version.outputs.sha }}+ GHCR_IMAGE: ${{ steps.registries.outputs.ghcr_image }}+ run: bash tooling/docker/promote.sh++ - name: Resolve published image+ id: published+ env:+ BUILD_TAG: ${{ steps.manifest.outputs.final_tag }}+ GHCR_DIGEST: ${{ steps.manifest.outputs.ghcr_digest || steps.promotion.outputs.ghcr_digest }}+ DOCKER_DIGEST: ${{ steps.manifest.outputs.docker_digest || steps.promotion.outputs.docker_digest }}+ VERSION: ${{ steps.version.outputs.version }}+ PRERELEASE: ${{ steps.version.outputs.prerelease }}+ run: |+ final_tag="$BUILD_TAG"+ if [[ -z "$final_tag" ]]; then+ if [[ "$PRERELEASE" == "true" ]]; then final_tag="v$VERSION"; else final_tag=latest; fi+ fi+ {+ echo "final_tag=$final_tag"+ echo "ghcr_digest=$GHCR_DIGEST"+ echo "docker_digest=$DOCKER_DIGEST"+ } >> "$GITHUB_OUTPUT"+- name: Install Cosignuses: sigstore/cosign-installer@v3- name: Sign images with Cosignrun: |# Sign GHCR image- cosign sign --yes ${{ steps.registries.outputs.ghcr_image }}@${{ steps.manifest.outputs.ghcr_digest }}+ cosign sign --yes ${{ steps.registries.outputs.ghcr_image }}@${{ steps.published.outputs.ghcr_digest }}if [[ "${{ steps.registries.outputs.dockerhub }}" == "true" ]]; then# Sign Docker Hub image- cosign sign --yes ${{ steps.registries.outputs.docker_image }}@${{ steps.manifest.outputs.docker_digest }}+ cosign sign --yes ${{ steps.registries.outputs.docker_image }}@${{ steps.published.outputs.docker_digest }}fi- name: Inspect imagerun: |- docker buildx imagetools inspect ${{ steps.registries.outputs.ghcr_image }}:${{ steps.manifest.outputs.final_tag }}+ docker buildx imagetools inspect ${{ steps.registries.outputs.ghcr_image }}:${{ steps.published.outputs.final_tag }}if [[ "${{ steps.registries.outputs.dockerhub }}" == "true" ]]; then- docker buildx imagetools inspect ${{ steps.registries.outputs.docker_image }}:${{ steps.manifest.outputs.final_tag }}+ docker buildx imagetools inspect ${{ steps.registries.outputs.docker_image }}:${{ steps.published.outputs.final_tag }}fi- name: Verify anonymous pulls on both architectures@@ -347,12 +411,12 @@ jobs:for image in "${images[@]}"; dofor platform in linux/amd64 linux/arm64; dodocker --config "$registry_config" pull --quiet --platform "$platform" \- "$image:${{ steps.manifest.outputs.final_tag }}"+ "$image:${{ steps.published.outputs.final_tag }}"donedone- name: Redeploy Stack- if: ${{ needs.mode.outputs.release == 'true' && env.DEPLOY == 'true' }}+ if: ${{ needs.mode.outputs.release == 'true' && steps.version.outputs.prerelease != 'true' && env.DEPLOY == 'true' }}uses: appleboy/ssh-action@v1with:key: ${{ secrets.SSH_KEY }}@@ -363,7 +427,7 @@ jobs:./manage_stack.sh up reactive_resume- name: Purge Cloudflare cache- if: ${{ needs.mode.outputs.release == 'true' && env.PURGE_CLOUDFLARE == 'true' }}+ if: ${{ needs.mode.outputs.release == 'true' && steps.version.outputs.prerelease != 'true' && env.PURGE_CLOUDFLARE == 'true' }}env:CLOUDFLARE_ZONE_ID: ${{ secrets.CLOUDFLARE_ZONE_ID }}CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}diff --git a/docs/agents/container-publishing.md b/docs/agents/container-publishing.mdindex 3e07f79eb..c7dc8bcc6 100644--- a/docs/agents/container-publishing.md+++ b/docs/agents/container-publishing.md@@ -19,21 +19,56 @@ no cache is persisted between workflow runs. On Blacksmith, the builder persistsDockerfile's pnpm cache mounts between runs, keyed per architecture (`Dockerfile-amd64`,`Dockerfile-arm64`).-| Trigger | Published aliases | Production deployment |-| --------------------------------------------- | --------------------------------------- | -------------------------------------------------- |-| Push to `main` | `sha-*`, `nightly`, timestamped nightly | No |-| Manual dispatch, default `release=false` | `sha-*`, `canary-<run-id>-<attempt>` | No |-| Push of a `v*` tag or explicit `release=true` | `sha-*`, `latest`, version/major/minor | When configured: SSH redeploy and Cloudflare purge |--Manual `release=true` republishes the version already in `package.json` and runs configured-production integrations. SSH redeployment requires `SSH_KEY`, `SSH_HOST`, and `SSH_USER`;-Cloudflare purging requires `CLOUDFLARE_ZONE_ID` and `CLOUDFLARE_API_TOKEN`. Each integration-is skipped if any of its required secrets is missing. Dispatch does not create a Git tag,-GitHub release, or version bump. Use this for an approved current-version rebuild;-it replaces the existing stable image aliases.--Manual canaries first run a cache-only build on each architecture, then publish, merge,-and sign images in the enabled registries. Run one with:+| Trigger | Action | Published aliases | Production deployment |+| ----------------------------------------------- | -------------------------- | ------------------------------------------------------ | -------------------------------------------------- |+| Push to `main` | Build AMD64 and ARM64 | `sha-<full-commit>`, `nightly`, timestamped nightly | No |+| Manual dispatch, default `release=false` | Build AMD64 and ARM64 | `sha-<full-commit>`, `canary-<run-id>-<attempt>` | No |+| Push of a stable `v*` tag | Promote existing SHA image | `latest`, version/major/minor (`v6.0.0`, `v6.0`, `v6`) | When configured: SSH redeploy and Cloudflare purge |+| Push of a prerelease `v*` tag | Promote existing SHA image | Prerelease version only (for example, `v6.0.0-rc.1`) | No |+| Manual dispatch, `release=true`, branch | Promote existing SHA image | `latest` | When configured: SSH redeploy and Cloudflare purge |+| Manual dispatch, `release=true`, stable tag | Promote existing SHA image | `latest`, version/major/minor (`v6.0.0`, `v6.0`, `v6`) | When configured: SSH redeploy and Cloudflare purge |+| Manual dispatch, `release=true`, prerelease tag | Promote existing SHA image | Prerelease version only | No |++Each main push builds its own full commit-SHA image; newer pushes do not cancel earlier+builds. An older build still publishes its SHA and timestamped nightly aliases, but only+the current main HEAD updates the moving `nightly` alias. Architecture-specific build+outputs use `sha-<full-commit>-amd64` and `sha-<full-commit>-arm64`.++Release tags must be `vMAJOR.MINOR.PATCH`, optionally with a prerelease suffix, and match+`package.json` at the tagged commit. Promotion resolves that commit's+`sha-<full-commit>` image independently in each enabled registry, validates both architectures,+and copies the complete image index within that registry. It adds no annotations and checks+that each resulting alias has the source digest. Embedded SBOM/provenance manifests and+existing digest-addressed signatures stay intact; the workflow also signs the promoted digest.++If the main build is still running, promotion waits up to 35 minutes for the source images.+Missing images or incomplete indexes fail before aliases move; promotion never falls back to+a rebuild. For an unpublished commit on a ref containing this workflow version, run a+manual `release=false` build at that ref first, then rerun promotion. Historical refs with+older workflow files still run their original workflow; their short SHA tags are not promotion+sources. Keep full SHA images in registry retention policies so commits remain promotable.++Manual `release=true` on main or another branch updates `latest` only, keeping semver+aliases tied to Git releases. To update `latest` to main without rebuilding:++```bash+gh workflow run docker-build.yml --repo reactive-resume/reactive-resume --ref main -f release=true+```++To re-promote an existing stable release, select its Git tag. This updates `latest` and+that release's full/minor/major semver aliases. The tag must match the built `package.json`+version. Prerelease tags update only their prerelease alias and skip production integrations.++```bash+gh workflow run docker-build.yml --repo reactive-resume/reactive-resume --ref v6.0.1 -f release=true+```++SSH redeployment requires `SSH_KEY`, `SSH_HOST`, and `SSH_USER`; Cloudflare purging requires+`CLOUDFLARE_ZONE_ID` and `CLOUDFLARE_API_TOKEN`. Each integration is skipped if any required+secret is missing. Dispatch does not create a Git tag, GitHub release, or version bump.++Manual canaries build, publish, merge, and sign images in enabled registries without+running production integrations:```bashgh workflow run docker-build.yml --repo reactive-resume/reactive-resume --ref main -f release=falsediff --git a/tooling/docker-publishing.test.ts b/tooling/docker-publishing.test.tsindex 6cec2c5b2..5a2b7c3f6 100644--- a/tooling/docker-publishing.test.ts+++ b/tooling/docker-publishing.test.ts@@ -1,5 +1,5 @@-import { execFileSync } from "node:child_process";-import { mkdtempSync, readFileSync, rmSync } from "node:fs";+import { execFileSync, spawnSync } from "node:child_process";+import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";import { tmpdir } from "node:os";import { join } from "node:path";import { expect, it } from "vitest";@@ -38,3 +38,146 @@ it("keeps smoke dispatches out of release publishing and production deployment",rmSync(directory, { recursive: true, force: true });}});++it("validates release tags against the built version and distinguishes prereleases", () => {+ const workflow = readFileSync(new URL("../.github/workflows/docker-build.yml", import.meta.url), "utf8");+ const script = workflow.match(+ / - name: Resolve publishing version and commit[\s\S]*? run: \|\n([\s\S]*?)(?=\n - name:)/,+ )?.[1];+ if (!script) throw new Error("Publishing version script is missing");+ const directory = mkdtempSync(join(tmpdir(), "docker-version-"));+ const commit = "a".repeat(40);++ try {+ writeFileSync(join(directory, "git"), `#!/usr/bin/env bash\necho ${commit}\n`, { mode: 0o755 });+ for (const [event, ref, version, prerelease, tagged, status] of [+ ["push", "refs/tags/v6.0.0", "6.0.0", "false", "true", 0],+ ["push", "refs/tags/v6.0.0-rc.1", "6.0.0-rc.1", "true", "true", 0],+ ["push", "refs/tags/v6.0.1", "6.0.0", "false", "true", 1],+ ["push", "refs/tags/v6.0", "6.0.0", "false", "true", 1],+ ["workflow_dispatch", "refs/heads/main", "6.0.0", "false", "false", 0],+ ["workflow_dispatch", "refs/heads/fix", "6.0.0", "false", "false", 0],+ ["workflow_dispatch", "refs/tags/v6.0.0", "6.0.0", "false", "true", 0],+ ["workflow_dispatch", "refs/tags/v6.0.0-rc.1", "6.0.0-rc.1", "true", "true", 0],+ ["workflow_dispatch", "refs/tags/v6.0.1", "6.0.0", "false", "true", 1],+ ] as const) {+ const output = join(directory, "output");+ writeFileSync(output, "");+ writeFileSync(join(directory, "package.json"), JSON.stringify({ version }));+ const result = spawnSync("bash", ["-eu", "-c", script], {+ cwd: directory,+ encoding: "utf8",+ env: {+ ...process.env,+ PATH: `${directory}:${process.env.PATH}`,+ EVENT_NAME: event,+ GIT_REF: ref,+ GITHUB_OUTPUT: output,+ },+ });+ expect(result.status, result.stderr).toBe(status);+ expect(readFileSync(output, "utf8")).toBe(+ status === 0 ? `version=${version}\nsha=${commit}\nprerelease=${prerelease}\ntagged=${tagged}\n` : "",+ );+ }+ } finally {+ rmSync(directory, { recursive: true, force: true });+ }+});++it.each([+ ["both registries", "", false, false, false, 0, 2],+ ["GHCR only", "", false, true, false, 0, 1],+ ["missing GHCR source", "ghcr.io/example/app", false, false, false, 1, 0],+ ["incomplete Docker Hub index", "", true, false, false, 1, 0],+ ["registry changes copied digest", "", false, false, true, 1, 1],+])("promotes complete SHA indexes: %s", (_name, missing, incomplete, ghcrOnly, changed, status, copies) => {+ const directory = mkdtempSync(join(tmpdir(), "docker-promotion-"));+ const ghcr = "ghcr.io/example/app";+ const hub = "docker.io/example/app";+ const commit = "a".repeat(40);+ const digest = `sha256:${"b".repeat(64)}`;+ const log = join(directory, "copies");+ const output = join(directory, "output");+ const index = (architectures: string[]) =>+ JSON.stringify({ manifests: architectures.map((architecture) => ({ platform: { os: "linux", architecture } })) });++ try {+ writeFileSync(log, "");+ writeFileSync(output, "");+ writeFileSync(join(directory, "complete.json"), index(["amd64", "arm64"]));+ writeFileSync(join(directory, "incomplete.json"), index(["amd64"]));+ writeFileSync(join(directory, "sleep"), "#!/usr/bin/env bash\nexit 0\n", { mode: 0o755 });+ // Registry fixture accepts only index inspection and digest-addressed copies.+ // Any build, pull/tag/push, or annotation mutation exits unsuccessfully.+ writeFileSync(+ join(directory, "docker"),+ `#!/usr/bin/env bash+set -euo pipefail+[[ "$1 $2" == "buildx imagetools" ]] || exit 2+case "$3" in+ inspect)+ [[ -z "$MISSING" || "$4" != "$MISSING:sha-$COMMIT_SHA" ]] || exit 1+ if [[ "$5" == "--raw" ]]; then+ if [[ "$INCOMPLETE" == true && "$4" == docker.io/* ]]; then+ cat "$FIXTURE/incomplete.json"+ else+ cat "$FIXTURE/complete.json"+ fi+ elif [[ "$CHANGED" == true && "$4" != *:sha-* ]]; then+ printf '"sha256:%064d"\\n' 0+ else+ printf '"%s"\\n' "$DIGEST"+ fi+ ;;+ create)+ shift 3+ tags=()+ while [[ "$1" == --tag ]]; do tags+=("$2"); shift 2; done+ [[ $# == 1 && "$1" == *@"$DIGEST" ]] || exit 2+ printf '%s\\n' "$*" "${"$"}{tags[@]}" >> "$COPY_LOG"+ ;;+ *) exit 2 ;;+esac+`,+ { mode: 0o755 },+ );+ const images = ghcrOnly ? [ghcr] : [hub, ghcr];+ const result = spawnSync("bash", [new URL("./docker/promote.sh", import.meta.url).pathname], {+ encoding: "utf8",+ env: {+ ...process.env,+ PATH: `${directory}:${process.env.PATH}`,+ COMMIT_SHA: commit,+ GHCR_IMAGE: ghcr,+ GITHUB_OUTPUT: output,+ DOCKER_METADATA_OUTPUT_JSON: JSON.stringify({+ tags: images.flatMap((image) => [`${image}:latest`, `${image}:v6.0.0`]),+ }),+ MISSING: missing,+ INCOMPLETE: String(incomplete),+ CHANGED: String(changed),+ FIXTURE: directory,+ DIGEST: digest,+ COPY_LOG: log,+ },+ });+ expect(result.status, result.stderr).toBe(status);+ const copied = readFileSync(log, "utf8").trim().split("\n").filter(Boolean);+ if (copies === 0) {+ expect(copied).toEqual([]);+ expect(readFileSync(output, "utf8")).toBe("");+ } else if (changed) {+ expect(copied).toHaveLength(3);+ expect(result.stdout).toContain("Digest changed while promoting");+ expect(readFileSync(output, "utf8")).toBe("");+ } else {+ expect(copied).toEqual(images.flatMap((image) => [`${image}@${digest}`, `${image}:latest`, `${image}:v6.0.0`]));+ expect(readFileSync(output, "utf8")).toBe(+ `${ghcrOnly ? "" : `docker_digest=${digest}\n`}ghcr_digest=${digest}\n`,+ );+ }+ } finally {+ rmSync(directory, { recursive: true, force: true });+ }+});diff --git a/tooling/docker/promote.sh b/tooling/docker/promote.shnew file mode 100644index 000000000..063a06fed--- /dev/null+++ b/tooling/docker/promote.sh@@ -0,0 +1,60 @@+#!/usr/bin/env bash+set -euo pipefail++# Retag complete indexes within each registry. No rebuilds or annotation changes:+# attestations stay embedded, and digest-addressed Cosign signatures stay valid.+source_tag="sha-${COMMIT_SHA:?}"+images=()+while IFS= read -r image; do+ images+=("$image")+done < <(jq -r '.tags | map(split(":")[0]) | unique[]' <<< "$DOCKER_METADATA_OUTPUT_JSON")+digests=()+deadline=$((SECONDS + 2100))++# Resolve every source before moving any aliases. A tag push can arrive while+# its main build is running, so allow up to 35 minutes for publication.+for image in "${images[@]}"; do+ digest=""+ for ((attempt = 1; attempt <= 71; attempt++)); do+ if digest=$(docker buildx imagetools inspect "$image:$source_tag" --format '{{json .Manifest.Digest}}' | jq -er .); then+ break+ fi+ if ((attempt == 71 || SECONDS >= deadline)); then+ echo "::error::Missing $image:$source_tag. Publish this commit with a main push or release=false dispatch, then rerun promotion."+ exit 1+ fi+ echo "Waiting for $image:$source_tag ($attempt/71)..."+ sleep 30+ done+ docker buildx imagetools inspect "$image@$digest" --raw | jq -e '+ [.manifests[].platform | select(.os == "linux") | .architecture] |+ (index("amd64") != null) and (index("arm64") != null)+ ' > /dev/null+ digests+=("$digest")+done++for index in "${!images[@]}"; do+ image="${images[$index]}"+ digest="${digests[$index]}"+ tags=()+ while IFS= read -r tag; do+ tags+=("$tag")+ done < <(jq -r --arg image "$image" '.tags[] | select(startswith($image + ":"))' <<< "$DOCKER_METADATA_OUTPUT_JSON")+ args=()+ for tag in "${tags[@]}"; do+ args+=(--tag "$tag")+ done+ docker buildx imagetools create "${args[@]}" "$image@$digest"+ for tag in "${tags[@]}"; do+ promoted=$(docker buildx imagetools inspect "$tag" --format '{{json .Manifest.Digest}}' | jq -er .)+ if [[ "$promoted" != "$digest" ]]; then+ echo "::error::Digest changed while promoting $tag: expected $digest, got $promoted"+ exit 1+ fi+ done+ if [[ "$image" == "$GHCR_IMAGE" ]]; then+ echo "ghcr_digest=$digest" >> "$GITHUB_OUTPUT"+ else+ echo "docker_digest=$digest" >> "$GITHUB_OUTPUT"+ fi+done