|
| 1 | +# Copyright 2026 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +name: Build AgentGateway image |
| 16 | + |
| 17 | +on: |
| 18 | + workflow_dispatch: |
| 19 | + inputs: |
| 20 | + repository: |
| 21 | + description: AgentGateway repository |
| 22 | + required: true |
| 23 | + default: agentgateway/agentgateway |
| 24 | + sha: |
| 25 | + description: AgentGateway commit SHA |
| 26 | + required: true |
| 27 | + |
| 28 | +permissions: |
| 29 | + contents: read |
| 30 | + packages: write |
| 31 | + |
| 32 | +jobs: |
| 33 | + source: |
| 34 | + runs-on: ubuntu-24.04 |
| 35 | + outputs: |
| 36 | + sha: ${{ steps.source.outputs.sha }} |
| 37 | + short_sha: ${{ steps.source.outputs.short_sha }} |
| 38 | + steps: |
| 39 | + - name: Checkout AgentGateway |
| 40 | + uses: actions/checkout@v4 |
| 41 | + with: |
| 42 | + repository: ${{ inputs.repository }} |
| 43 | + ref: ${{ inputs.sha }} |
| 44 | + persist-credentials: false |
| 45 | + |
| 46 | + - name: Resolve source revision |
| 47 | + id: source |
| 48 | + run: | |
| 49 | + echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" |
| 50 | + echo "short_sha=$(git rev-parse --short=12 HEAD)" >> "$GITHUB_OUTPUT" |
| 51 | +
|
| 52 | + build: |
| 53 | + needs: source |
| 54 | + strategy: |
| 55 | + fail-fast: false |
| 56 | + matrix: |
| 57 | + include: |
| 58 | + - platform: linux/amd64 |
| 59 | + runner: ubuntu-24.04 |
| 60 | + artifact: linux-amd64 |
| 61 | + - platform: linux/arm64 |
| 62 | + runner: ubuntu-24.04-arm |
| 63 | + artifact: linux-arm64 |
| 64 | + runs-on: ${{ matrix.runner }} |
| 65 | + steps: |
| 66 | + - name: Checkout AgentGateway |
| 67 | + uses: actions/checkout@v4 |
| 68 | + with: |
| 69 | + repository: ${{ inputs.repository }} |
| 70 | + ref: ${{ needs.source.outputs.sha }} |
| 71 | + persist-credentials: false |
| 72 | + |
| 73 | + - name: Log in to GHCR |
| 74 | + uses: docker/login-action@v3 |
| 75 | + with: |
| 76 | + registry: ghcr.io |
| 77 | + username: ${{ github.actor }} |
| 78 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 79 | + |
| 80 | + - name: Set up Docker Buildx |
| 81 | + uses: docker/setup-buildx-action@v3 |
| 82 | + |
| 83 | + - name: Build and push by digest |
| 84 | + id: build |
| 85 | + uses: docker/build-push-action@v6 |
| 86 | + with: |
| 87 | + context: . |
| 88 | + platforms: ${{ matrix.platform }} |
| 89 | + tags: ghcr.io/${{ github.repository }}/agentgateway |
| 90 | + outputs: type=image,push-by-digest=true,name-canonical=true,push=true |
| 91 | + build-args: | |
| 92 | + VERSION=0.0.0-alpha.${{ needs.source.outputs.short_sha }} |
| 93 | + GIT_REVISION=${{ needs.source.outputs.sha }} |
| 94 | +
|
| 95 | + - name: Export digest |
| 96 | + run: | |
| 97 | + mkdir -p "$RUNNER_TEMP/digests" |
| 98 | + digest='${{ steps.build.outputs.digest }}' |
| 99 | + touch "$RUNNER_TEMP/digests/${digest#sha256:}" |
| 100 | +
|
| 101 | + - name: Upload digest |
| 102 | + uses: actions/upload-artifact@v4 |
| 103 | + with: |
| 104 | + name: digest-${{ matrix.artifact }} |
| 105 | + path: ${{ runner.temp }}/digests/* |
| 106 | + if-no-files-found: error |
| 107 | + retention-days: 1 |
| 108 | + |
| 109 | + push: |
| 110 | + needs: |
| 111 | + - source |
| 112 | + - build |
| 113 | + runs-on: ubuntu-24.04 |
| 114 | + steps: |
| 115 | + - name: Download digests |
| 116 | + uses: actions/download-artifact@v4 |
| 117 | + with: |
| 118 | + path: ${{ runner.temp }}/digests |
| 119 | + pattern: digest-linux-* |
| 120 | + merge-multiple: true |
| 121 | + |
| 122 | + - name: Log in to GHCR |
| 123 | + uses: docker/login-action@v3 |
| 124 | + with: |
| 125 | + registry: ghcr.io |
| 126 | + username: ${{ github.actor }} |
| 127 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 128 | + |
| 129 | + - name: Set up Docker Buildx |
| 130 | + uses: docker/setup-buildx-action@v3 |
| 131 | + |
| 132 | + - name: Push multi-architecture image |
| 133 | + working-directory: ${{ runner.temp }}/digests |
| 134 | + env: |
| 135 | + IMAGE: ghcr.io/${{ github.repository }}/agentgateway:${{ needs.source.outputs.short_sha }} |
| 136 | + run: | |
| 137 | + docker buildx imagetools create \ |
| 138 | + --tag "$IMAGE" \ |
| 139 | + $(printf 'ghcr.io/${{ github.repository }}/agentgateway@sha256:%s ' *) |
| 140 | + digest=$(docker buildx imagetools inspect "$IMAGE" --format '{{json .}}' | jq -r '.manifest.digest') |
| 141 | + echo "$IMAGE@$digest" >> "$GITHUB_STEP_SUMMARY" |
0 commit comments