|
4 | 4 | workflow_dispatch: |
5 | 5 | inputs: |
6 | 6 | source_image: |
7 | | - description: 'Source image from registry.ddbuild.io (e.g., registry.ddbuild.io/ci/datadog-agent/serverless-init:1.7.8)' |
| 7 | + description: 'Source image from registry.datadoghq.com (e.g., registry.datadoghq.com/serverless-init:1.7.8)' |
8 | 8 | required: true |
9 | 9 | type: string |
10 | 10 | version: |
|
49 | 49 | username: ${{ github.actor }} |
50 | 50 | password: ${{ secrets.GITHUB_TOKEN }} |
51 | 51 |
|
| 52 | + - name: Wait for image availability |
| 53 | + run: | |
| 54 | + SOURCE_IMAGE="${{ inputs.source_image }}" |
| 55 | + MAX_ATTEMPTS=20 |
| 56 | + RETRY_DELAY=30 |
| 57 | + # Maximum wait time: 20 attempts × 30s = 600s (10 minutes) |
| 58 | +
|
| 59 | + echo "⏳ Waiting for image to be available: ${SOURCE_IMAGE}" |
| 60 | + echo "Will check every ${RETRY_DELAY}s for up to $((MAX_ATTEMPTS * RETRY_DELAY))s" |
| 61 | +
|
| 62 | + for i in $(seq 1 $MAX_ATTEMPTS); do |
| 63 | + echo "Attempt $i/$MAX_ATTEMPTS: Checking if image exists..." |
| 64 | +
|
| 65 | + if crane manifest ${SOURCE_IMAGE} >/dev/null 2>&1; then |
| 66 | + echo "✅ Image is available!" |
| 67 | + exit 0 |
| 68 | + fi |
| 69 | +
|
| 70 | + if [ $i -lt $MAX_ATTEMPTS ]; then |
| 71 | + echo "⏳ Image not yet available, waiting ${RETRY_DELAY}s..." |
| 72 | + sleep $RETRY_DELAY |
| 73 | + fi |
| 74 | + done |
| 75 | +
|
| 76 | + echo "❌ Image did not become available after $((MAX_ATTEMPTS * RETRY_DELAY))s" |
| 77 | + exit 1 |
| 78 | +
|
52 | 79 | - name: Copy image to GHCR |
53 | 80 | run: | |
54 | 81 | SOURCE_IMAGE="${{ inputs.source_image }}" |
|
65 | 92 | echo " - ${DEST_BASE}:${VERSION}${IMAGE_SUFFIX}" |
66 | 93 | echo " - ${DEST_BASE}:v${PIPELINE_ID}${IMAGE_SUFFIX}" |
67 | 94 |
|
68 | | - # Copy with version tag |
69 | | - crane copy ${SOURCE_IMAGE} ${DEST_BASE}:${VERSION}${IMAGE_SUFFIX} |
| 95 | + # Copy with version tag (with retry logic) |
| 96 | + # Maximum retry duration: 3 attempts with 10s delays between retries |
| 97 | + # This workflow is triggered in parallel with the publish attempt to registry.datadoghq.com |
| 98 | + # Registry.datadoghq.com should normally need about ~30 seconds to recieve the new image |
| 99 | + MAX_COPY_ATTEMPTS=3 |
| 100 | + COPY_RETRY_DELAY=10 |
| 101 | +
|
| 102 | + for i in $(seq 1 $MAX_COPY_ATTEMPTS); do |
| 103 | + echo "Copying image (attempt $i/$MAX_COPY_ATTEMPTS)..." |
| 104 | +
|
| 105 | + if crane copy ${SOURCE_IMAGE} ${DEST_BASE}:${VERSION}${IMAGE_SUFFIX}; then |
| 106 | + echo "✅ Image copied successfully!" |
| 107 | + break |
| 108 | + fi |
| 109 | +
|
| 110 | + if [ $i -lt $MAX_COPY_ATTEMPTS ]; then |
| 111 | + echo "⚠️ Copy failed, retrying in ${COPY_RETRY_DELAY}s..." |
| 112 | + sleep $COPY_RETRY_DELAY |
| 113 | + else |
| 114 | + echo "❌ Failed to copy image after $MAX_COPY_ATTEMPTS attempts" |
| 115 | + exit 1 |
| 116 | + fi |
| 117 | + done |
70 | 118 |
|
71 | 119 | # Tag for pipeline ID |
72 | 120 | crane tag ${DEST_BASE}:${VERSION}${IMAGE_SUFFIX} v${PIPELINE_ID}${IMAGE_SUFFIX} |
|
0 commit comments