Unverified Commit 6c698b8b authored by Dmitry Tokarev's avatar Dmitry Tokarev Committed by GitHub
Browse files

fix: Docker push retries (#6456)


Signed-off-by: default avatarDmitry Tokarev <dtokarev@nvidia.com>
parent 7a6283e9
...@@ -51,9 +51,11 @@ runs: ...@@ -51,9 +51,11 @@ runs:
ECR_HOSTNAME: ${{ inputs.aws_account_id }}.dkr.ecr.${{ inputs.aws_default_region }}.amazonaws.com ECR_HOSTNAME: ${{ inputs.aws_account_id }}.dkr.ecr.${{ inputs.aws_default_region }}.amazonaws.com
run: | run: |
set -euo pipefail set -euo pipefail
if [[ ${CONDITIONAL_TAG} != '' ]]; then source "${{ github.action_path }}/retry_push.sh"
docker tag ${LOCAL_IMAGE} ${ECR_HOSTNAME}/${CONDITIONAL_TAG}
docker push ${ECR_HOSTNAME}/${CONDITIONAL_TAG} if [[ -n "${CONDITIONAL_TAG}" ]]; then
docker tag "${LOCAL_IMAGE}" "${ECR_HOSTNAME}/${CONDITIONAL_TAG}"
retry_push "${ECR_HOSTNAME}/${CONDITIONAL_TAG}"
fi fi
while IFS= read -r TAG; do while IFS= read -r TAG; do
if [ -z "$TAG" ]; then if [ -z "$TAG" ]; then
...@@ -61,7 +63,7 @@ runs: ...@@ -61,7 +63,7 @@ runs:
fi fi
echo "Tagging and pushing: ${ECR_HOSTNAME}/${TAG}" echo "Tagging and pushing: ${ECR_HOSTNAME}/${TAG}"
docker tag "${LOCAL_IMAGE}" "${ECR_HOSTNAME}/${TAG}" docker tag "${LOCAL_IMAGE}" "${ECR_HOSTNAME}/${TAG}"
docker push "${ECR_HOSTNAME}/${TAG}" retry_push "${ECR_HOSTNAME}/${TAG}"
done <<< "$PUSH_TAGS" done <<< "$PUSH_TAGS"
- name: ACR Tag and Push - name: ACR Tag and Push
shell: bash shell: bash
...@@ -72,11 +74,13 @@ runs: ...@@ -72,11 +74,13 @@ runs:
AZURE_ACR_HOSTNAME: ${{ inputs.azure_acr_hostname }} AZURE_ACR_HOSTNAME: ${{ inputs.azure_acr_hostname }}
run: | run: |
set -euo pipefail set -euo pipefail
source "${{ github.action_path }}/retry_push.sh"
while IFS= read -r TAG; do while IFS= read -r TAG; do
if [ -z "$TAG" ]; then if [ -z "$TAG" ]; then
continue continue
fi fi
echo "Tagging and pushing: ${AZURE_ACR_HOSTNAME}/${TAG}" echo "Tagging and pushing: ${AZURE_ACR_HOSTNAME}/${TAG}"
docker tag "${LOCAL_IMAGE}" "${AZURE_ACR_HOSTNAME}/${TAG}" docker tag "${LOCAL_IMAGE}" "${AZURE_ACR_HOSTNAME}/${TAG}"
docker push "${AZURE_ACR_HOSTNAME}/${TAG}" retry_push "${AZURE_ACR_HOSTNAME}/${TAG}"
done <<< "$PUSH_TAGS" done <<< "$PUSH_TAGS"
# Retry docker push with exponential backoff.
# Safe under `set -e`: the `if` conditional context prevents a failed
# `docker push` from triggering an immediate exit.
retry_push() {
local image="$1"
local max_attempts=3
local wait_seconds=10
local attempt=1
while true; do
if docker push "$image"; then
return 0
fi
echo "Push failed for $image (attempt ${attempt}/${max_attempts})." >&2
if (( attempt >= max_attempts )); then
echo "Push failed after ${max_attempts} attempts: $image" >&2
return 1
fi
echo "Retrying in ${wait_seconds}s..."
sleep "$wait_seconds"
attempt=$((attempt + 1))
wait_seconds=$((wait_seconds * 2))
if (( wait_seconds > 120 )); then
wait_seconds=120
fi
done
}
...@@ -109,7 +109,7 @@ runs: ...@@ -109,7 +109,7 @@ runs:
RETRY_DELAY=10 RETRY_DELAY=10
for attempt in $(seq 1 $MAX_RETRIES); do for attempt in $(seq 1 $MAX_RETRIES); do
echo "Attempt ${attempt}/${MAX_RETRIES}..." echo "Attempt ${attempt}/${MAX_RETRIES}..."
if skopeo copy --all "${SOURCE_REF}" "${TARGET_REF}"; then if skopeo copy --all --retry-times 3 "${SOURCE_REF}" "${TARGET_REF}"; then
echo "target_image_ref=${{ inputs.target_registry }}/${TARGET_IMAGE}:${TARGET_TAG}" >> $GITHUB_OUTPUT echo "target_image_ref=${{ inputs.target_registry }}/${TARGET_IMAGE}:${TARGET_TAG}" >> $GITHUB_OUTPUT
echo "✅ Image copied successfully" echo "✅ Image copied successfully"
exit 0 exit 0
......
...@@ -90,7 +90,7 @@ on: ...@@ -90,7 +90,7 @@ on:
description: 'Timeout in minutes for the copy to ACR step' description: 'Timeout in minutes for the copy to ACR step'
required: false required: false
type: number type: number
default: 5 default: 10
secrets: secrets:
AWS_DEFAULT_REGION: AWS_DEFAULT_REGION:
required: true required: true
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment