Build Sandbox Images #63
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build Sandbox Images | |
| on: | |
| workflow_run: | |
| workflows: ["Release"] | |
| types: | |
| - completed | |
| schedule: | |
| - cron: '0 4 * * 1' | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| packages: write | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME: raine/workmux-sandbox | |
| jobs: | |
| setup: | |
| if: github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success' | |
| runs-on: ubuntu-latest | |
| outputs: | |
| tag: ${{ steps.version.outputs.tag }} | |
| ref: ${{ steps.version.outputs.ref }} | |
| steps: | |
| - name: Determine version | |
| id: version | |
| run: | | |
| if [ "${{ github.event_name }}" = "workflow_run" ]; then | |
| echo "tag=${{ github.event.workflow_run.head_branch }}" >> "$GITHUB_OUTPUT" | |
| echo "ref=${{ github.event.workflow_run.head_sha }}" >> "$GITHUB_OUTPUT" | |
| fi | |
| # Stage 1: Build base image for both architectures | |
| base: | |
| needs: setup | |
| runs-on: ${{ matrix.platform == 'linux/amd64' && 'ubuntu-latest' || 'ubuntu-24.04-arm' }} | |
| strategy: | |
| matrix: | |
| platform: | |
| - linux/amd64 | |
| - linux/arm64 | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ needs.setup.outputs.ref || '' }} | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=raw,value=latest | |
| type=raw,value=${{ needs.setup.outputs.tag }},enable=${{ needs.setup.outputs.tag != '' }} | |
| type=schedule,pattern=weekly-{{date 'YYYYMMDD'}} | |
| - name: Build and push by digest | |
| id: build | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: docker/Dockerfile.base | |
| platforms: ${{ matrix.platform }} | |
| outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true | |
| cache-from: type=gha,scope=base-${{ matrix.platform }} | |
| cache-to: type=gha,mode=max,scope=base-${{ matrix.platform }} | |
| - name: Export digest | |
| run: | | |
| mkdir -p /tmp/digests/base | |
| digest="${{ steps.build.outputs.digest }}" | |
| touch "/tmp/digests/base/${digest#sha256:}" | |
| - name: Upload digest | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: digests-base-${{ strategy.job-index }} | |
| path: /tmp/digests/base/* | |
| if-no-files-found: error | |
| retention-days: 1 | |
| # Stage 2: Merge base image into multi-arch manifest | |
| base-manifest: | |
| runs-on: ubuntu-latest | |
| needs: [setup, base] | |
| steps: | |
| - name: Download digests | |
| uses: actions/download-artifact@v4 | |
| with: | |
| pattern: digests-base-* | |
| path: /tmp/digests/base | |
| merge-multiple: true | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=raw,value=base | |
| type=raw,value=base-latest | |
| type=raw,value=base-${{ needs.setup.outputs.tag }},enable=${{ needs.setup.outputs.tag != '' }} | |
| type=schedule,pattern=base-weekly-{{date 'YYYYMMDD'}} | |
| - name: Create manifest list and push | |
| working-directory: /tmp/digests/base | |
| run: | | |
| docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ | |
| $(printf '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:%s ' *) | |
| # Stage 3: Build agent images for both architectures | |
| agents: | |
| runs-on: ${{ matrix.platform == 'linux/amd64' && 'ubuntu-latest' || 'ubuntu-24.04-arm' }} | |
| needs: [setup, base-manifest] | |
| strategy: | |
| matrix: | |
| agent: | |
| - claude | |
| - codex | |
| - gemini | |
| - opencode | |
| platform: | |
| - linux/amd64 | |
| - linux/arm64 | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ needs.setup.outputs.ref || '' }} | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=raw,value=latest | |
| type=raw,value=${{ needs.setup.outputs.tag }},enable=${{ needs.setup.outputs.tag != '' }} | |
| type=schedule,pattern=weekly-{{date 'YYYYMMDD'}} | |
| - name: Build and push by digest | |
| id: build | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: docker/Dockerfile.${{ matrix.agent }} | |
| platforms: ${{ matrix.platform }} | |
| build-args: | | |
| BASE=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:base | |
| outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true | |
| cache-from: type=gha,scope=${{ matrix.agent }}-${{ matrix.platform }} | |
| cache-to: type=gha,mode=max,scope=${{ matrix.agent }}-${{ matrix.platform }} | |
| - name: Export digest | |
| run: | | |
| mkdir -p /tmp/digests/${{ matrix.agent }} | |
| digest="${{ steps.build.outputs.digest }}" | |
| touch "/tmp/digests/${{ matrix.agent }}/${digest#sha256:}" | |
| - name: Upload digest | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: digests-${{ matrix.agent }}-${{ strategy.job-index }} | |
| path: /tmp/digests/${{ matrix.agent }}/* | |
| if-no-files-found: error | |
| retention-days: 1 | |
| # Stage 4: Merge agent images into multi-arch manifests | |
| agent-manifests: | |
| runs-on: ubuntu-latest | |
| needs: [setup, agents] | |
| strategy: | |
| matrix: | |
| agent: | |
| - claude | |
| - codex | |
| - gemini | |
| - opencode | |
| steps: | |
| - name: Download digests | |
| uses: actions/download-artifact@v4 | |
| with: | |
| pattern: digests-${{ matrix.agent }}-* | |
| path: /tmp/digests/${{ matrix.agent }} | |
| merge-multiple: true | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=raw,value=${{ matrix.agent }} | |
| type=raw,value=${{ matrix.agent }}-latest | |
| type=raw,value=${{ matrix.agent }}-${{ needs.setup.outputs.tag }},enable=${{ needs.setup.outputs.tag != '' }} | |
| type=schedule,pattern=${{ matrix.agent }}-weekly-{{date 'YYYYMMDD'}} | |
| - name: Create manifest list and push | |
| working-directory: /tmp/digests/${{ matrix.agent }} | |
| run: | | |
| docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ | |
| $(printf '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:%s ' *) |