Skip to content

Commit 5c7d838

Browse files
authored
chore(ci): tag production promotions with release-<sha> for rollback retention (#9061)
* chore(ci): tag production promotions with release-<sha> for rollback retention * improvement(ci): share one promote-image script across repos
1 parent f2d7826 commit 5c7d838

3 files changed

Lines changed: 20 additions & 6 deletions

File tree

‎.github/scripts/promote-app-image.sh‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ REGISTRY="${1:?registry required}"
55
REPOSITORY="${2:?repository required}"
66
SOURCE_TAG="${3:?source tag required}"
77
DEPLOY_TAG="${4:?deploy tag required}"
8+
RELEASE_TAG="${5:-}"
89
: "${GITHUB_OUTPUT:?GitHub output file required}"
910
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
1011
PREVIOUS=$(bash "$SCRIPT_DIR/get-ecr-image-digest.sh" "$REPOSITORY" "$DEPLOY_TAG" --allow-missing)
1112
EPOCH=$(date +%s)
12-
docker buildx imagetools create -t "$REGISTRY/$REPOSITORY:$DEPLOY_TAG" "$REGISTRY/$REPOSITORY:$SOURCE_TAG"
13+
bash "$SCRIPT_DIR/promote-image.sh" "$REGISTRY" "$REPOSITORY" "$SOURCE_TAG" "$DEPLOY_TAG" "$RELEASE_TAG"
1314
DIGEST=$(bash "$SCRIPT_DIR/get-ecr-image-digest.sh" "$REPOSITORY" "$DEPLOY_TAG")
1415
CHANGED=true
1516
if [ "$DIGEST" = "$PREVIOUS" ]; then CHANGED=false; fi

‎.github/scripts/promote-image.sh‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
# Point a deploy tag (and, for production, its release-<sha> alias) at a built image.
3+
# One imagetools call writes both tags, so they always share one list digest.
4+
set -euo pipefail
5+
REGISTRY="${1:?registry required}"
6+
REPOSITORY="${2:?repository required}"
7+
SOURCE_TAG="${3:?source tag required}"
8+
DEPLOY_TAG="${4:?deploy tag required}"
9+
RELEASE_TAG="${5:-}"
10+
TAG_ARGS=(-t "$REGISTRY/$REPOSITORY:$DEPLOY_TAG")
11+
if [ -n "$RELEASE_TAG" ]; then TAG_ARGS+=(-t "$REGISTRY/$REPOSITORY:$RELEASE_TAG"); fi
12+
docker buildx imagetools create "${TAG_ARGS[@]}" "$REGISTRY/$REPOSITORY:$SOURCE_TAG"

‎.github/workflows/ci.yml‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -520,8 +520,11 @@ jobs:
520520
run: |
521521
REGISTRY="${{ steps.login-ecr.outputs.registry }}"
522522
523+
RELEASE_TAG=""
523524
if [ "${{ github.ref }}" = "refs/heads/main" ]; then
524525
ECR_TAG="latest"
526+
# ECR lifecycle retains release- aliases as prod rollback targets.
527+
RELEASE_TAG="release-${SOURCE_TAG}"
525528
elif [ "${{ github.ref }}" = "refs/heads/dev" ]; then
526529
ECR_TAG="dev"
527530
else
@@ -540,13 +543,11 @@ jobs:
540543
# Move the app last so a preceding tag failure cannot start app rollout
541544
# and then skip the downstream Trigger promotion job.
542545
for repo in $ECR_REPOS; do
543-
echo "🚀 Promoting ${repo}:${SOURCE_TAG} to ${ECR_TAG}"
546+
echo "🚀 Promoting ${repo}:${SOURCE_TAG} to ${ECR_TAG}${RELEASE_TAG:+ and ${RELEASE_TAG}}"
544547
if [ "$repo" = "$APP_REPO" ]; then
545-
bash .github/scripts/promote-app-image.sh "$REGISTRY" "$APP_REPO" "$SOURCE_TAG" "$ECR_TAG"
548+
bash .github/scripts/promote-app-image.sh "$REGISTRY" "$APP_REPO" "$SOURCE_TAG" "$ECR_TAG" "$RELEASE_TAG"
546549
else
547-
docker buildx imagetools create \
548-
-t "${REGISTRY}/${repo}:${ECR_TAG}" \
549-
"${REGISTRY}/${repo}:${SOURCE_TAG}"
550+
bash .github/scripts/promote-image.sh "$REGISTRY" "$repo" "$SOURCE_TAG" "$ECR_TAG" "$RELEASE_TAG"
550551
fi
551552
done
552553

0 commit comments

Comments
 (0)