name: Build and Push Multi-Arch Docker Images
on:
push:
branches: [ main ]
tags: [ '*' ]
pull_request:
branches: [ main ]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
matrix:
variant: [cli, proxy, http]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch,suffix=-${{ matrix.variant }}
type=ref,event=pr,suffix=-${{ matrix.variant }}
type=semver,pattern={{version}},suffix=-${{ matrix.variant }}
type=semver,pattern={{major}}.{{minor}},suffix=-${{ matrix.variant }}
type=semver,pattern={{major}},suffix=-${{ matrix.variant }}
type=raw,value=latest,suffix=-${{ matrix.variant }},enable={{is_default_branch}}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile.${{ matrix.variant }}
platforms: linux/amd64,linux/arm64,linux/aarch64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-summary:
runs-on: ubuntu-latest
needs: build
if: always()
steps:
- name: Build Summary
run: |
echo "## Build Results" >> $GITHUB_STEP_SUMMARY
echo "| Variant | Status |" >> $GITHUB_STEP_SUMMARY
echo "|---------|--------|" >> $GITHUB_STEP_SUMMARY
echo "| cli | ${{ needs.build.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| proxy | ${{ needs.build.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| http | ${{ needs.build.result }} |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Images built for platforms: linux/amd64, linux/arm64, linux/aarch64" >> $GITHUB_STEP_SUMMARY
echo "Registry: ghcr.io/${{ github.repository }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Available images:" >> $GITHUB_STEP_SUMMARY
echo "- ghcr.io/${{ github.repository }}:latest-cli" >> $GITHUB_STEP_SUMMARY
echo "- ghcr.io/${{ github.repository }}:latest-proxy" >> $GITHUB_STEP_SUMMARY
echo "- ghcr.io/${{ github.repository }}:latest-http" >> $GITHUB_STEP_SUMMARY