diff --git a/.github/actions/merge-image/action.yml b/.github/actions/merge-image/action.yml index 09c905c8a..1e8f61bb4 100644 --- a/.github/actions/merge-image/action.yml +++ b/.github/actions/merge-image/action.yml @@ -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 @@ -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 @@ -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}} @@ -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') + [[ "$digest" =~ ^sha256:[0-9a-f]{64}$ ]] || { echo "Unexpected digest: $digest" >&2; exit 1; } + echo "digest=$digest" >> "$GITHUB_OUTPUT" diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index 96f264058..c796cdb2e 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -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 @@ -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: @@ -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: