Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions .github/actions/merge-image/action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: merge-image
description: Combines the per-platform images pushed by `build-app` into a single multi-arch manifest and tags it.
description: Combines the per-platform images pushed by `build-app` into a single multi-arch manifest and tags it. There is no per-build tag; deploys pin the manifest digest output here.
inputs:
registry:
required: true
Expand All @@ -17,6 +17,10 @@ inputs:
required: false
default: 'false'
description: If true, also tags the image as `latest` (set when the pushed tag is the newest release)
outputs:
digest:
description: Digest of the multi-arch manifest (`sha256:...`)
value: ${{ steps.digest.outputs.digest }}

runs:
using: composite
Expand Down Expand Up @@ -63,7 +67,6 @@ runs:
type=raw,value=latest,enable=${{ inputs.latest == 'true' }}
type=ref,event=branch
type=ref,event=pr
type=sha,prefix=,format=long
type=semver,pattern={{major}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') && !startsWith(github.ref, 'refs/tags/0.') }}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}.{{minor}}.{{patch}}
Expand All @@ -88,3 +91,16 @@ runs:
IMAGE: ${{ steps.image.outputs.name }}
VERSION: ${{ steps.meta.outputs.version }}
run: docker buildx imagetools inspect "$IMAGE:$VERSION"

# Every tag above is mutable (branch, semver, latest), so deploys reference the digest instead.
- name: Resolve manifest digest
id: digest
shell: bash
env:
IMAGE: ${{ steps.image.outputs.name }}
VERSION: ${{ steps.meta.outputs.version }}
run: |
set -euo pipefail
digest=$(docker buildx imagetools inspect "$IMAGE:$VERSION" --format '{{json .Manifest}}' | jq -r '.digest')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Capture the digest before resolving the mutable tag

When two pushes to the same deploy branch overlap, this re-resolves $VERSION—the branch tag both runs push—after the current manifest was created, so the other run can move the tag first and this run may dispatch the other commit’s digest (or a mixed set across the three images). Capture the digest from this invocation of imagetools create instead; Docker documents --metadata-file for returning the create result’s digest (Docker CLI reference).

Useful? React with 👍 / 👎.

[[ "$digest" =~ ^sha256:[0-9a-f]{64}$ ]] || { echo "Unexpected digest: $digest" >&2; exit 1; }
echo "digest=$digest" >> "$GITHUB_OUTPUT"
44 changes: 33 additions & 11 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,34 +99,56 @@ jobs:
registry-username: ${{ github.actor }}
registry-password: ${{ secrets.GITHUB_TOKEN }}

# Not a matrix: matrix jobs can't expose a per-entry output, and deploys need every image's digest.
merge:
name: Merge (${{ matrix.image }})
name: Merge images
needs: [build]
runs-on: ubuntu-latest
if: needs.build.outputs.push-image == 'true'
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
image: [api, live-control-gateway, cron]
outputs:
api-digest: ${{ steps.api.outputs.digest }}
gateway-digest: ${{ steps.gateway.outputs.digest }}
cron-digest: ${{ steps.cron.outputs.digest }}

steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Merge ${{ matrix.image }}
- name: Merge api
id: api
uses: ./.github/actions/merge-image
with:
registry: ${{ env.REGISTRY }}
image: api
registry-username: ${{ github.actor }}
registry-password: ${{ secrets.GITHUB_TOKEN }}
latest: ${{ inputs.latest || false }}

- name: Merge live-control-gateway
id: gateway
uses: ./.github/actions/merge-image
with:
registry: ${{ env.REGISTRY }}
image: live-control-gateway
registry-username: ${{ github.actor }}
registry-password: ${{ secrets.GITHUB_TOKEN }}
latest: ${{ inputs.latest || false }}

- name: Merge cron
id: cron
uses: ./.github/actions/merge-image
with:
registry: ${{ env.REGISTRY }}
image: ${{ matrix.image }}
image: cron
registry-username: ${{ github.actor }}
registry-password: ${{ secrets.GITHUB_TOKEN }}
latest: ${{ inputs.latest || false }}

# Deploys reference the commit SHA tag. It is derived from the commit alone, so re-running a
# single job produces the same tag instead of pointing at an image that was never built.
# Deploys pin each image's manifest digest rather than a tag: no per-build tags are created,
# and re-running a deploy job alone sends the same digests.
deploy-prod-workflow:
runs-on: ubuntu-latest
needs: merge
Expand All @@ -139,7 +161,7 @@ jobs:
repo: openshock/kubernetes-cluster-gitops
event-type: update-backend-prod
client-payload: |
{"tag": "${{ github.sha }}"}
{"digests": {"api": "${{ needs.merge.outputs.api-digest }}", "live-control-gateway": "${{ needs.merge.outputs.gateway-digest }}", "cron": "${{ needs.merge.outputs.cron-digest }}"}}
token: ${{ secrets.GITOPS_PAT }}

deploy-staging:
Expand All @@ -155,7 +177,7 @@ jobs:
repo: openshock/kubernetes-cluster-gitops
event-type: update-backend-staging
client-payload: |
{"tag": "${{ github.sha }}"}
{"digests": {"api": "${{ needs.merge.outputs.api-digest }}", "live-control-gateway": "${{ needs.merge.outputs.gateway-digest }}", "cron": "${{ needs.merge.outputs.cron-digest }}"}}
token: ${{ secrets.GITOPS_PAT }}

deploy-dev:
Expand Down