|
| 1 | +name: Build and publish the agent Docker image |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + push: |
| 6 | + paths: |
| 7 | + - ".github/workflows/build-agent-docker-image.yml" |
| 8 | + |
| 9 | +env: |
| 10 | + REGISTRY: ghcr.io |
| 11 | + IMAGE_NAME: ${{ github.repository_owner }}/blink-agent |
| 12 | + |
| 13 | +jobs: |
| 14 | + build: |
| 15 | + strategy: |
| 16 | + matrix: |
| 17 | + include: |
| 18 | + - runner: ubuntu-latest |
| 19 | + platform: linux/amd64 |
| 20 | + - runner: ubuntu-24.04-arm |
| 21 | + platform: linux/arm64 |
| 22 | + runs-on: ${{ matrix.runner }} |
| 23 | + permissions: |
| 24 | + contents: read |
| 25 | + packages: write |
| 26 | + steps: |
| 27 | + - name: Checkout repository |
| 28 | + uses: actions/checkout@v5 |
| 29 | + |
| 30 | + - name: Set up Docker Buildx |
| 31 | + uses: docker/setup-buildx-action@v3 |
| 32 | + |
| 33 | + - name: Log in to the Container registry |
| 34 | + uses: docker/login-action@v3 |
| 35 | + with: |
| 36 | + registry: ${{ env.REGISTRY }} |
| 37 | + username: ${{ github.actor }} |
| 38 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 39 | + |
| 40 | + - name: Build and push by digest |
| 41 | + id: build |
| 42 | + uses: docker/build-push-action@v6 |
| 43 | + with: |
| 44 | + context: packages/server/docker |
| 45 | + file: packages/server/docker/Dockerfile |
| 46 | + platforms: ${{ matrix.platform }} |
| 47 | + outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true |
| 48 | + provenance: false |
| 49 | + |
| 50 | + - name: Upload digest |
| 51 | + run: | |
| 52 | + mkdir -p /tmp/digests |
| 53 | + platform="${{ matrix.platform }}" |
| 54 | + echo "${{ steps.build.outputs.digest }}" > "/tmp/digests/${platform//\//-}" |
| 55 | + - uses: actions/upload-artifact@v4 |
| 56 | + with: |
| 57 | + name: digest-${{ matrix.runner }} |
| 58 | + path: /tmp/digests/* |
| 59 | + retention-days: 1 |
| 60 | + |
| 61 | + create-manifest: |
| 62 | + needs: build |
| 63 | + runs-on: ubuntu-latest |
| 64 | + permissions: |
| 65 | + contents: read |
| 66 | + packages: write |
| 67 | + steps: |
| 68 | + - name: Download digests |
| 69 | + uses: actions/download-artifact@v4 |
| 70 | + with: |
| 71 | + path: /tmp/digests |
| 72 | + pattern: digest-* |
| 73 | + merge-multiple: true |
| 74 | + |
| 75 | + - name: Log in to the Container registry |
| 76 | + uses: docker/login-action@v3 |
| 77 | + with: |
| 78 | + registry: ${{ env.REGISTRY }} |
| 79 | + username: ${{ github.actor }} |
| 80 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 81 | + |
| 82 | + - name: Create and push manifest |
| 83 | + run: | |
| 84 | + SHORT_TAG="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:$(echo ${{ github.sha }} | cut -c1-7)" |
| 85 | + LATEST_TAG="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" |
| 86 | + DIGESTS=$(for digest in /tmp/digests/*; do echo "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@$(cat $digest)"; done) |
| 87 | +
|
| 88 | + docker manifest create $SHORT_TAG $DIGESTS |
| 89 | + docker manifest push $SHORT_TAG |
| 90 | +
|
| 91 | + docker manifest create $LATEST_TAG $DIGESTS |
| 92 | + docker manifest push $LATEST_TAG |
0 commit comments