diff --git a/.forgejo/workflows/build.yaml b/.forgejo/workflows/build.yaml index 4e28568..b995366 100644 --- a/.forgejo/workflows/build.yaml +++ b/.forgejo/workflows/build.yaml @@ -63,18 +63,25 @@ jobs: run: | set -euo pipefail image_ref="$REGISTRY_HOST/ashwin/nxtgauge-ai-assistant:$SHA" + metadata_file="/tmp/ai-assistant-metadata.json" docker buildx build --push \ + --metadata-file "$metadata_file" \ -t "$image_ref" \ -t "$REGISTRY_HOST/ashwin/nxtgauge-ai-assistant:latest" \ -f Dockerfile \ . + digest="$(grep -o '"containerimage\.digest"[[:space:]]*:[[:space:]]*"sha256:[^"]*"' "$metadata_file" | grep -o 'sha256:[^"]*')" + test -n "$digest" + echo "IMAGE_DIGEST=$digest" >> "$GITHUB_ENV" + - name: Update GitOps env: GITOPS_REPO: https://ci.nxtgauge.com/ashwin/nxtgauge-gitops.git GITOPS_TOKEN: ${{ secrets.GITOPS_TOKEN }} SHA: ${{ github.sha }} + DIGEST: ${{ env.IMAGE_DIGEST }} run: | set -euo pipefail apk add --no-cache git @@ -89,13 +96,15 @@ jobs: git clone -b main "$GITOPS_REPO" "$GITOPS_DIR" cd "$GITOPS_DIR" - # release-patch.yaml carries a Flux $imagepolicy marker comment on - # this line - Flux's own image-automation-controller would - # eventually rewrite it too, but committing here makes the new - # tag live immediately instead of waiting on Flux's poll interval. - sed -i -E "s|(image: ci\.nxtgauge\.com/ashwin/nxtgauge-ai-assistant:)[a-f0-9]+|\1$SHA|" apps/nxtgauge-ai-assistant/overlays/prod/release-patch.yaml + # release-patch.yaml pins by digest (@sha256:...), not by mutable + # tag - Flux's ImageUpdateAutomation previously raced this file via + # a $imagepolicy marker comment and always won because its + # alphabetical tag ordering sorted "latest" above any hex SHA, + # clobbering this step's commits every ~2 minutes. The marker was + # removed from the file so this CI step is now the sole writer. + sed -i -E "s#image: ci\.nxtgauge\.com/ashwin/nxtgauge-ai-assistant(:[a-f0-9]+|@sha256:[a-f0-9]+)#image: ci.nxtgauge.com/ashwin/nxtgauge-ai-assistant@${DIGEST}#" apps/nxtgauge-ai-assistant/overlays/prod/release-patch.yaml git config user.name "forgejo-actions[bot]" git config user.email "forgejo-actions@ci.nxtgauge.com" git add apps/nxtgauge-ai-assistant/overlays/prod/release-patch.yaml - git diff --quiet || (git commit -m "chore(gitops): deploy ai-assistant@${SHA}" && git push) + git diff --quiet || (git commit -m "chore(gitops): deploy ai-assistant@${SHA} (${DIGEST})" && git push)