|
| 1 | +name: Mirror Base Images to GHCR |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + # Run nightly at 2 AM UTC |
| 6 | + - cron: '0 2 * * *' |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + force_pull: |
| 10 | + description: 'Force pull even if image exists' |
| 11 | + required: false |
| 12 | + default: false |
| 13 | + type: boolean |
| 14 | + |
| 15 | +jobs: |
| 16 | + mirror-images: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + permissions: |
| 19 | + packages: write |
| 20 | + contents: read |
| 21 | + strategy: |
| 22 | + matrix: |
| 23 | + image: |
| 24 | + - source: rapidsai/devcontainers:25.10-cpp-cuda12.9 |
| 25 | + target_name: rapidsai-devcontainers-25.10-cpp-cuda12.9 |
| 26 | + - source: pytorch/pytorch:2.9.0-cuda12.8-cudnn9-runtime |
| 27 | + target_name: pytorch-2.9.0-cuda12.8-cudnn9-runtime |
| 28 | + fail-fast: false |
| 29 | + |
| 30 | + steps: |
| 31 | + - name: Log in to GHCR |
| 32 | + uses: docker/login-action@v3 |
| 33 | + with: |
| 34 | + registry: ghcr.io |
| 35 | + username: ${{ github.actor }} |
| 36 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 37 | + |
| 38 | + - name: Set target image name |
| 39 | + run: | |
| 40 | + TARGET_IMAGE="ghcr.io/${{ github.repository_owner }}/mirrors/${{ matrix.image.target_name }}" |
| 41 | + echo "TARGET_IMAGE=${TARGET_IMAGE,,}" >> $GITHUB_ENV |
| 42 | + echo "Will mirror ${{ matrix.image.source }} -> ${TARGET_IMAGE,,}" |
| 43 | +
|
| 44 | + - name: Check if image already exists in GHCR |
| 45 | + id: check_image |
| 46 | + continue-on-error: true |
| 47 | + run: | |
| 48 | + if docker manifest inspect ${TARGET_IMAGE} > /dev/null 2>&1; then |
| 49 | + echo "exists=true" >> $GITHUB_OUTPUT |
| 50 | + echo "Image already exists in GHCR" |
| 51 | + else |
| 52 | + echo "exists=false" >> $GITHUB_OUTPUT |
| 53 | + echo "Image does not exist in GHCR" |
| 54 | + fi |
| 55 | +
|
| 56 | + - name: Pull source image from Docker Hub |
| 57 | + if: steps.check_image.outputs.exists != 'true' || github.event.inputs.force_pull == 'true' |
| 58 | + run: | |
| 59 | + echo "Pulling ${{ matrix.image.source }} from Docker Hub..." |
| 60 | + docker pull ${{ matrix.image.source }} |
| 61 | +
|
| 62 | + - name: Tag image for GHCR |
| 63 | + if: steps.check_image.outputs.exists != 'true' || github.event.inputs.force_pull == 'true' |
| 64 | + run: | |
| 65 | + docker tag ${{ matrix.image.source }} ${TARGET_IMAGE} |
| 66 | +
|
| 67 | + - name: Push to GHCR |
| 68 | + if: steps.check_image.outputs.exists != 'true' || github.event.inputs.force_pull == 'true' |
| 69 | + run: | |
| 70 | + echo "Pushing ${TARGET_IMAGE} to GHCR..." |
| 71 | + docker push ${TARGET_IMAGE} |
| 72 | + echo "✓ Successfully mirrored ${{ matrix.image.source }}" |
| 73 | +
|
| 74 | + - name: Skipped (image exists) |
| 75 | + if: steps.check_image.outputs.exists == 'true' && github.event.inputs.force_pull != 'true' |
| 76 | + run: | |
| 77 | + echo "⊘ Skipping mirror - image already exists in GHCR" |
| 78 | + echo "Use workflow_dispatch with force_pull=true to update" |
| 79 | +
|
| 80 | + - name: Verify mirrored image |
| 81 | + if: steps.check_image.outputs.exists != 'true' || github.event.inputs.force_pull == 'true' |
| 82 | + run: | |
| 83 | + docker pull ${TARGET_IMAGE} |
| 84 | + docker images ${TARGET_IMAGE} |
| 85 | + echo "✓ Image verified successfully" |
0 commit comments