|
| 1 | +name: Build and Release Runner Image (GAR only) |
| 2 | + |
| 3 | +# Triggered when a PR carries the `build-gar-images` label. Pushes test |
| 4 | +# builds of all three variants to the internal GAR mirror only — Docker |
| 5 | +# Hub is not touched. Each new push to the PR rebuilds while the label |
| 6 | +# is applied. Images are tagged by branch name (lower-cased) so |
| 7 | +# collaborators can pull a stable reference (e.g. scalr/runner:my-branch). |
| 8 | +# Each image is pushed to two regional GAR repos: europe-west4 and us-central1. |
| 9 | + |
| 10 | +on: |
| 11 | + pull_request: |
| 12 | + types: [labeled, synchronize, reopened] |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: read |
| 16 | + # Required by google-github-actions/auth for workload identity federation. |
| 17 | + id-token: write |
| 18 | + |
| 19 | +jobs: |
| 20 | + build: |
| 21 | + name: Build and Push to GAR |
| 22 | + if: contains(github.event.pull_request.labels.*.name, 'build-gar-images') |
| 23 | + runs-on: ubuntu-latest |
| 24 | + steps: |
| 25 | + - name: Checkout |
| 26 | + uses: actions/checkout@v4 |
| 27 | + |
| 28 | + - name: Authenticate to Google Cloud |
| 29 | + uses: google-github-actions/auth@v3 |
| 30 | + with: |
| 31 | + workload_identity_provider: ${{vars.GOOGLE_WORKLOAD_IDENTITY_POOL_PROVIDER}} |
| 32 | + service_account: ${{vars.GOOGLE_SERVICE_ACCOUNT_EMAIL}} |
| 33 | + token_format: access_token |
| 34 | + |
| 35 | + - name: Configure Docker for GAR |
| 36 | + run: | |
| 37 | + gcloud auth configure-docker ${{ vars.EU_DEV_MIRROR_LOCATION }}-docker.pkg.dev --quiet |
| 38 | + gcloud auth configure-docker ${{ vars.US_PROD_MIRROR_LOCATION }}-docker.pkg.dev --quiet |
| 39 | +
|
| 40 | + - name: Set up QEMU |
| 41 | + uses: docker/setup-qemu-action@v3 |
| 42 | + |
| 43 | + - name: Set up Docker Buildx |
| 44 | + uses: docker/setup-buildx-action@v3 |
| 45 | + |
| 46 | + # PR source branch, lower-cased and sanitized for use as a Docker tag |
| 47 | + # (Docker tags are case-sensitive but downstream agents lower-case |
| 48 | + # image refs; slashes are illegal and become dashes). |
| 49 | + - name: Resolve branch tag |
| 50 | + id: branch |
| 51 | + run: | |
| 52 | + raw='${{ github.head_ref }}' |
| 53 | + sanitized="${raw,,}" |
| 54 | + sanitized="${sanitized//\//-}" |
| 55 | + echo "tag=${sanitized}" | tee -a $GITHUB_OUTPUT |
| 56 | +
|
| 57 | + # Two regional GAR mirrors — EU dev and US production. |
| 58 | + - name: Compose GAR image paths |
| 59 | + id: gar |
| 60 | + run: | |
| 61 | + echo "image_eu=${{ vars.EU_DEV_MIRROR_LOCATION }}-docker.pkg.dev/${{ vars.EU_DEV_GOOGLE_PROJECT }}/main/scalr/runner" | tee -a $GITHUB_OUTPUT |
| 62 | + echo "image_us=${{ vars.US_PROD_MIRROR_LOCATION }}-docker.pkg.dev/${{ vars.US_PROD_GOOGLE_PROJECT }}/main/scalr/runner" | tee -a $GITHUB_OUTPUT |
| 63 | +
|
| 64 | + - name: Build and push images |
| 65 | + uses: docker/bake-action@v5 |
| 66 | + env: |
| 67 | + VERSION: ${{ steps.branch.outputs.tag }} |
| 68 | + with: |
| 69 | + files: | |
| 70 | + docker-bake.hcl |
| 71 | + versions.json |
| 72 | + push: true |
| 73 | + # Replace each target's tag list (first `tags=` removes the Docker |
| 74 | + # Hub default from docker-bake.hcl; subsequent lines add to the |
| 75 | + # list) so a single build pushes to both regional GAR repos. |
| 76 | + # The europe-west4 mirror also holds the per-branch buildcache. |
| 77 | + set: | |
| 78 | + full.tags=${{ steps.gar.outputs.image_eu }}:${{ steps.branch.outputs.tag }} |
| 79 | + full.tags=${{ steps.gar.outputs.image_us }}:${{ steps.branch.outputs.tag }} |
| 80 | + python39.tags=${{ steps.gar.outputs.image_eu }}:${{ steps.branch.outputs.tag }}-python39 |
| 81 | + python39.tags=${{ steps.gar.outputs.image_us }}:${{ steps.branch.outputs.tag }}-python39 |
| 82 | + slim.tags=${{ steps.gar.outputs.image_eu }}:${{ steps.branch.outputs.tag }}-slim |
| 83 | + slim.tags=${{ steps.gar.outputs.image_us }}:${{ steps.branch.outputs.tag }}-slim |
| 84 | + full.cache-from=type=registry,ref=${{ steps.gar.outputs.image_eu }}:buildcache-${{ steps.branch.outputs.tag }} |
| 85 | + python39.cache-from=type=registry,ref=${{ steps.gar.outputs.image_eu }}:buildcache-${{ steps.branch.outputs.tag }}-python39 |
| 86 | + slim.cache-from=type=registry,ref=${{ steps.gar.outputs.image_eu }}:buildcache-${{ steps.branch.outputs.tag }}-slim |
| 87 | + full.cache-to=type=registry,ref=${{ steps.gar.outputs.image_eu }}:buildcache-${{ steps.branch.outputs.tag }},mode=max |
| 88 | + python39.cache-to=type=registry,ref=${{ steps.gar.outputs.image_eu }}:buildcache-${{ steps.branch.outputs.tag }}-python39,mode=max |
| 89 | + slim.cache-to=type=registry,ref=${{ steps.gar.outputs.image_eu }}:buildcache-${{ steps.branch.outputs.tag }}-slim,mode=max |
| 90 | +
|
| 91 | + - name: Summary |
| 92 | + run: | |
| 93 | + cat <<EOF >> $GITHUB_STEP_SUMMARY |
| 94 | + Pushed GAR test images for branch \`${{ steps.branch.outputs.tag }}\`: |
| 95 | +
|
| 96 | + europe-west4: |
| 97 | + - \`${{ steps.gar.outputs.image_eu }}:${{ steps.branch.outputs.tag }}\` |
| 98 | + - \`${{ steps.gar.outputs.image_eu }}:${{ steps.branch.outputs.tag }}-python39\` |
| 99 | + - \`${{ steps.gar.outputs.image_eu }}:${{ steps.branch.outputs.tag }}-slim\` |
| 100 | +
|
| 101 | + us-central1: |
| 102 | + - \`${{ steps.gar.outputs.image_us }}:${{ steps.branch.outputs.tag }}\` |
| 103 | + - \`${{ steps.gar.outputs.image_us }}:${{ steps.branch.outputs.tag }}-python39\` |
| 104 | + - \`${{ steps.gar.outputs.image_us }}:${{ steps.branch.outputs.tag }}-slim\` |
| 105 | + EOF |
0 commit comments