Skip to content

Commit 8563d25

Browse files
authored
fix(ci): predict the promoted app digest instead of trusting a read right after the retag (#9416)
* fix(ci): predict the promoted app digest instead of trusting a read right after the retag * fix(ci): bound the promoted-tag wait by elapsed time and each ECR read by a timeout
1 parent 02197b5 commit 8563d25

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

‎.github/scripts/get-ecr-image-digest.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ if [ -n "$ALLOW_MISSING" ] && [ "$ALLOW_MISSING" != '--allow-missing' ]; then
99
exit 1
1010
fi
1111
export AWS_PAGER=''
12-
aws ecr batch-get-image --repository-name "$REPOSITORY" --image-ids imageTag="$TAG" --output json |
12+
aws --cli-connect-timeout 10 --cli-read-timeout 20 ecr batch-get-image --repository-name "$REPOSITORY" --image-ids imageTag="$TAG" --output json |
1313
ALLOW_MISSING="$ALLOW_MISSING" python3 -c '
1414
import json, os, re, sys
1515
response = json.load(sys.stdin)

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,22 @@ RELEASE_TAG="${5:-}"
99
: "${GITHUB_OUTPUT:?GitHub output file required}"
1010
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
1111
PREVIOUS=$(bash "$SCRIPT_DIR/get-ecr-image-digest.sh" "$REPOSITORY" "$DEPLOY_TAG" --allow-missing)
12+
# A tag read straight after the move can still return the previous image, which
13+
# reports a moved tag as unchanged. The dry run prints the exact manifest the
14+
# move pushes (plus a trailing newline), so its hash is the digest the tag will
15+
# point at, known before the move.
16+
MANIFEST=$(docker buildx imagetools create --dry-run -t "$REGISTRY/$REPOSITORY:$DEPLOY_TAG" "$REGISTRY/$REPOSITORY:$SOURCE_TAG")
17+
DIGEST="sha256:$(printf '%s' "$MANIFEST" | sha256sum | cut -d' ' -f1)"
1218
EPOCH=$(date +%s)
1319
bash "$SCRIPT_DIR/promote-image.sh" "$REGISTRY" "$REPOSITORY" "$SOURCE_TAG" "$DEPLOY_TAG" "$RELEASE_TAG"
14-
DIGEST=$(bash "$SCRIPT_DIR/get-ecr-image-digest.sh" "$REPOSITORY" "$DEPLOY_TAG")
20+
deadline=$(( $(date +%s) + 60 ))
21+
until [ "$(bash "$SCRIPT_DIR/get-ecr-image-digest.sh" "$REPOSITORY" "$DEPLOY_TAG" --allow-missing)" = "$DIGEST" ]; do
22+
if [ "$(date +%s)" -ge "$deadline" ]; then
23+
echo "ERROR: $DEPLOY_TAG did not resolve to the pushed $DIGEST within 60s; cutover cannot be correlated" >&2
24+
exit 1
25+
fi
26+
sleep 3
27+
done
1528
CHANGED=true
1629
if [ "$DIGEST" = "$PREVIOUS" ]; then CHANGED=false; fi
1730
{

0 commit comments

Comments
 (0)