ci: harden GHCR release publishing (#2573)
This commit is contained in:
@@ -28,6 +28,8 @@ on:
|
||||
- "scripts/release/package-npm-runtime.sh"
|
||||
- "scripts/release/publish-npm.sh"
|
||||
- "scripts/release/publish-npm.test.mjs"
|
||||
- "scripts/release/retry-ghcr-command.sh"
|
||||
- "scripts/release/retry-ghcr-command.test.sh"
|
||||
pull_request:
|
||||
branches: [main]
|
||||
paths:
|
||||
@@ -55,6 +57,8 @@ on:
|
||||
- "scripts/release/package-npm-runtime.sh"
|
||||
- "scripts/release/publish-npm.sh"
|
||||
- "scripts/release/publish-npm.test.mjs"
|
||||
- "scripts/release/retry-ghcr-command.sh"
|
||||
- "scripts/release/retry-ghcr-command.test.sh"
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
@@ -95,6 +99,9 @@ jobs:
|
||||
- name: Test runtime bundle contract
|
||||
run: bash scripts/release/runtime-bundle.test.sh
|
||||
|
||||
- name: Test GHCR retry helper
|
||||
run: bash scripts/release/retry-ghcr-command.test.sh
|
||||
|
||||
- name: Test npm release helpers
|
||||
run: node --test scripts/release/nightly-version.test.mjs scripts/release/nightly-release.test.mjs scripts/release/npm-view-version.test.mjs scripts/release/publish-npm.test.mjs
|
||||
|
||||
|
||||
+142
-66
@@ -1447,29 +1447,44 @@ jobs:
|
||||
with:
|
||||
images: ghcr.io/kdlbs/kandev
|
||||
|
||||
# The inline Buildx command uses the GHA cache backend directly. This
|
||||
# helper exposes ACTIONS_RUNTIME_TOKEN and ACTIONS_CACHE_URL, which
|
||||
# docker/build-push-action normally prepares for its own invocation.
|
||||
- uses: crazy-max/ghaction-github-runtime@04d248b84655b509d8c44dc1d6f990c879747487 # v4.0.0
|
||||
|
||||
- name: Build and push (amd64 staging tag)
|
||||
id: build
|
||||
uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7.3.0
|
||||
with:
|
||||
context: ./ctx
|
||||
file: ./Dockerfile
|
||||
push: true
|
||||
platforms: linux/amd64
|
||||
tags: ${{ env.STAGING_IMAGE }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
# provenance/sbom would attach an extra attestation manifest, which
|
||||
# turns `imagetools inspect --raw` into an OCI index and breaks the
|
||||
# size gate's `.layers[].size` query. The final multi-arch tags
|
||||
# don't preserve attestations through `imagetools create` anyway,
|
||||
# so disabling here doesn't change user-facing image content.
|
||||
provenance: false
|
||||
sbom: false
|
||||
cache-from: type=gha,scope=base-amd64
|
||||
cache-to: type=gha,mode=max,scope=base-amd64
|
||||
env:
|
||||
DOCKER_LABELS: ${{ steps.meta.outputs.labels }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
metadata_file="$RUNNER_TEMP/docker-metadata.json"
|
||||
label_args=()
|
||||
while IFS= read -r label; do
|
||||
[ -z "$label" ] && continue
|
||||
label_args+=(--label "$label")
|
||||
done <<<"$DOCKER_LABELS"
|
||||
|
||||
bash scripts/release/retry-ghcr-command.sh \
|
||||
docker buildx build \
|
||||
--file ./Dockerfile \
|
||||
--platform linux/amd64 \
|
||||
--push \
|
||||
--tag "$STAGING_IMAGE" \
|
||||
"${label_args[@]}" \
|
||||
--provenance=false \
|
||||
--sbom=false \
|
||||
--cache-from type=gha,scope=base-amd64 \
|
||||
--cache-to type=gha,mode=max,scope=base-amd64 \
|
||||
--metadata-file "$metadata_file" \
|
||||
./ctx
|
||||
|
||||
digest="$(jq -er '."containerimage.digest"' "$metadata_file")"
|
||||
echo "digest=$digest" >> "$GITHUB_OUTPUT"
|
||||
|
||||
docker-arm64:
|
||||
name: Build & push container image (arm64)
|
||||
needs: [prepare, build-bundles]
|
||||
needs: [prepare, build-bundles, docker-amd64]
|
||||
if: >-
|
||||
${{ !cancelled() &&
|
||||
github.event_name == 'workflow_dispatch' &&
|
||||
@@ -1477,7 +1492,8 @@ jobs:
|
||||
!inputs.dry_run &&
|
||||
!inputs.desktop_validation_only &&
|
||||
needs.prepare.result == 'success' &&
|
||||
needs.build-bundles.result == 'success'
|
||||
needs.build-bundles.result == 'success' &&
|
||||
needs.docker-amd64.result == 'success'
|
||||
}}
|
||||
runs-on: ubuntu-24.04-arm
|
||||
permissions:
|
||||
@@ -1520,20 +1536,37 @@ jobs:
|
||||
with:
|
||||
images: ghcr.io/kdlbs/kandev
|
||||
|
||||
- uses: crazy-max/ghaction-github-runtime@04d248b84655b509d8c44dc1d6f990c879747487 # v4.0.0
|
||||
|
||||
- name: Build and push (arm64 staging tag)
|
||||
id: build
|
||||
uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7.3.0
|
||||
with:
|
||||
context: ./ctx
|
||||
file: ./Dockerfile
|
||||
push: true
|
||||
platforms: linux/arm64
|
||||
tags: ${{ env.STAGING_IMAGE }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
provenance: false
|
||||
sbom: false
|
||||
cache-from: type=gha,scope=base-arm64
|
||||
cache-to: type=gha,mode=max,scope=base-arm64
|
||||
env:
|
||||
DOCKER_LABELS: ${{ steps.meta.outputs.labels }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
metadata_file="$RUNNER_TEMP/docker-metadata.json"
|
||||
label_args=()
|
||||
while IFS= read -r label; do
|
||||
[ -z "$label" ] && continue
|
||||
label_args+=(--label "$label")
|
||||
done <<<"$DOCKER_LABELS"
|
||||
|
||||
bash scripts/release/retry-ghcr-command.sh \
|
||||
docker buildx build \
|
||||
--file ./Dockerfile \
|
||||
--platform linux/arm64 \
|
||||
--push \
|
||||
--tag "$STAGING_IMAGE" \
|
||||
"${label_args[@]}" \
|
||||
--provenance=false \
|
||||
--sbom=false \
|
||||
--cache-from type=gha,scope=base-arm64 \
|
||||
--cache-to type=gha,mode=max,scope=base-arm64 \
|
||||
--metadata-file "$metadata_file" \
|
||||
./ctx
|
||||
|
||||
digest="$(jq -er '."containerimage.digest"' "$metadata_file")"
|
||||
echo "digest=$digest" >> "$GITHUB_OUTPUT"
|
||||
|
||||
docker-manifest:
|
||||
name: Assemble multi-arch base manifest
|
||||
@@ -1553,6 +1586,11 @@ jobs:
|
||||
contents: read
|
||||
packages: write
|
||||
steps:
|
||||
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
|
||||
with:
|
||||
ref: ${{ needs.prepare.outputs.ref }}
|
||||
persist-credentials: false
|
||||
|
||||
- name: Docker meta
|
||||
id: meta
|
||||
uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.0
|
||||
@@ -1591,7 +1629,9 @@ jobs:
|
||||
[ -z "$tag" ] && continue
|
||||
tag_args+=(--tag "$tag")
|
||||
done <<<"$TAGS"
|
||||
docker buildx imagetools create "${tag_args[@]}" "$AMD64_REF" "$ARM64_REF"
|
||||
bash scripts/release/retry-ghcr-command.sh \
|
||||
docker buildx imagetools create \
|
||||
"${tag_args[@]}" "$AMD64_REF" "$ARM64_REF"
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Universal image — same per-arch native split, on top of the base image
|
||||
@@ -1638,29 +1678,42 @@ jobs:
|
||||
with:
|
||||
images: ghcr.io/kdlbs/kandev
|
||||
|
||||
- uses: crazy-max/ghaction-github-runtime@04d248b84655b509d8c44dc1d6f990c879747487 # v4.0.0
|
||||
|
||||
- name: Build and push (universal amd64 staging tag)
|
||||
id: build
|
||||
uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7.3.0
|
||||
with:
|
||||
context: .
|
||||
file: Dockerfile.universal
|
||||
push: true
|
||||
platforms: linux/amd64
|
||||
build-args: |
|
||||
BASE_IMAGE=ghcr.io/kdlbs/kandev:${{ needs.prepare.outputs.tag }}
|
||||
tags: ${{ env.STAGING_IMAGE }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
# provenance/sbom off so `imagetools inspect --raw` on the staging
|
||||
# tag returns the plain image manifest, not an OCI index — required
|
||||
# by the size gate in docker-universal-manifest.
|
||||
provenance: false
|
||||
sbom: false
|
||||
cache-from: type=gha,scope=universal-amd64
|
||||
cache-to: type=gha,mode=max,scope=universal-amd64
|
||||
env:
|
||||
DOCKER_LABELS: ${{ steps.meta.outputs.labels }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
metadata_file="$RUNNER_TEMP/docker-metadata.json"
|
||||
label_args=()
|
||||
while IFS= read -r label; do
|
||||
[ -z "$label" ] && continue
|
||||
label_args+=(--label "$label")
|
||||
done <<<"$DOCKER_LABELS"
|
||||
|
||||
bash scripts/release/retry-ghcr-command.sh \
|
||||
docker buildx build \
|
||||
--file Dockerfile.universal \
|
||||
--platform linux/amd64 \
|
||||
--push \
|
||||
--build-arg BASE_IMAGE="ghcr.io/kdlbs/kandev:${{ needs.prepare.outputs.tag }}" \
|
||||
--tag "$STAGING_IMAGE" \
|
||||
"${label_args[@]}" \
|
||||
--provenance=false \
|
||||
--sbom=false \
|
||||
--cache-from type=gha,scope=universal-amd64 \
|
||||
--cache-to type=gha,mode=max,scope=universal-amd64 \
|
||||
--metadata-file "$metadata_file" \
|
||||
.
|
||||
|
||||
digest="$(jq -er '."containerimage.digest"' "$metadata_file")"
|
||||
echo "digest=$digest" >> "$GITHUB_OUTPUT"
|
||||
|
||||
docker-universal-arm64:
|
||||
name: Build & push universal image (arm64)
|
||||
needs: [prepare, docker-manifest]
|
||||
needs: [prepare, docker-manifest, docker-universal-amd64]
|
||||
if: >-
|
||||
${{ !cancelled() &&
|
||||
github.event_name == 'workflow_dispatch' &&
|
||||
@@ -1668,7 +1721,8 @@ jobs:
|
||||
!inputs.dry_run &&
|
||||
!inputs.desktop_validation_only &&
|
||||
needs.prepare.result == 'success' &&
|
||||
needs.docker-manifest.result == 'success'
|
||||
needs.docker-manifest.result == 'success' &&
|
||||
needs.docker-universal-amd64.result == 'success'
|
||||
}}
|
||||
runs-on: ubuntu-24.04-arm
|
||||
permissions:
|
||||
@@ -1699,22 +1753,38 @@ jobs:
|
||||
with:
|
||||
images: ghcr.io/kdlbs/kandev
|
||||
|
||||
- uses: crazy-max/ghaction-github-runtime@04d248b84655b509d8c44dc1d6f990c879747487 # v4.0.0
|
||||
|
||||
- name: Build and push (universal arm64 staging tag)
|
||||
id: build
|
||||
uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7.3.0
|
||||
with:
|
||||
context: .
|
||||
file: Dockerfile.universal
|
||||
push: true
|
||||
platforms: linux/arm64
|
||||
build-args: |
|
||||
BASE_IMAGE=ghcr.io/kdlbs/kandev:${{ needs.prepare.outputs.tag }}
|
||||
tags: ${{ env.STAGING_IMAGE }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
provenance: false
|
||||
sbom: false
|
||||
cache-from: type=gha,scope=universal-arm64
|
||||
cache-to: type=gha,mode=max,scope=universal-arm64
|
||||
env:
|
||||
DOCKER_LABELS: ${{ steps.meta.outputs.labels }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
metadata_file="$RUNNER_TEMP/docker-metadata.json"
|
||||
label_args=()
|
||||
while IFS= read -r label; do
|
||||
[ -z "$label" ] && continue
|
||||
label_args+=(--label "$label")
|
||||
done <<<"$DOCKER_LABELS"
|
||||
|
||||
bash scripts/release/retry-ghcr-command.sh \
|
||||
docker buildx build \
|
||||
--file Dockerfile.universal \
|
||||
--platform linux/arm64 \
|
||||
--push \
|
||||
--build-arg BASE_IMAGE="ghcr.io/kdlbs/kandev:${{ needs.prepare.outputs.tag }}" \
|
||||
--tag "$STAGING_IMAGE" \
|
||||
"${label_args[@]}" \
|
||||
--provenance=false \
|
||||
--sbom=false \
|
||||
--cache-from type=gha,scope=universal-arm64 \
|
||||
--cache-to type=gha,mode=max,scope=universal-arm64 \
|
||||
--metadata-file "$metadata_file" \
|
||||
.
|
||||
|
||||
digest="$(jq -er '."containerimage.digest"' "$metadata_file")"
|
||||
echo "digest=$digest" >> "$GITHUB_OUTPUT"
|
||||
|
||||
docker-universal-manifest:
|
||||
name: Gate size + promote universal manifest
|
||||
@@ -1739,6 +1809,11 @@ jobs:
|
||||
AMD64_REF: ghcr.io/kdlbs/kandev@${{ needs.docker-universal-amd64.outputs.digest }}
|
||||
ARM64_REF: ghcr.io/kdlbs/kandev@${{ needs.docker-universal-arm64.outputs.digest }}
|
||||
steps:
|
||||
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
|
||||
with:
|
||||
ref: ${{ needs.prepare.outputs.ref }}
|
||||
persist-credentials: false
|
||||
|
||||
- uses: docker/setup-buildx-action@bb05f3f5519dd87d3ba754cc423b652a5edd6d2c # v4.2.0
|
||||
|
||||
- name: Login to GHCR
|
||||
@@ -1778,7 +1853,8 @@ jobs:
|
||||
- name: Promote staging to final tags
|
||||
run: |
|
||||
set -euo pipefail
|
||||
docker buildx imagetools create \
|
||||
bash scripts/release/retry-ghcr-command.sh \
|
||||
docker buildx imagetools create \
|
||||
--tag "ghcr.io/kdlbs/kandev:${{ needs.prepare.outputs.version }}-universal" \
|
||||
--tag "ghcr.io/kdlbs/kandev:${{ needs.prepare.outputs.tag }}-universal" \
|
||||
--tag "ghcr.io/kdlbs/kandev:universal" \
|
||||
|
||||
Reference in New Issue
Block a user