name: docker on: push: branches: [main] tags: ["v*"] pull_request: workflow_dispatch: env: REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }} concurrency: group: docker-${{ github.ref }} cancel-in-progress: true jobs: build: runs-on: ubuntu-latest permissions: contents: read packages: write steps: - uses: actions/checkout@v4 # QEMU lets one runner produce the arm64 image alongside amd64. - uses: docker/setup-qemu-action@v3 - uses: docker/setup-buildx-action@v3 # Pull requests build but never publish: forks must not be able to push. - name: Log in to ${{ env.REGISTRY }} if: github.event_name != 'pull_request' uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Derive tags and labels id: meta uses: docker/metadata-action@v5 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} type=semver,pattern={{major}} type=ref,event=branch type=ref,event=pr type=sha,format=short type=raw,value=latest,enable={{is_default_branch}} - name: Build and push uses: docker/build-push-action@v6 with: context: . platforms: linux/amd64,linux/arm64 push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} build-args: | VERSION=${{ steps.meta.outputs.version }} cache-from: type=gha cache-to: type=gha,mode=max - name: Summary if: github.event_name != 'pull_request' run: | { echo "### Published" echo echo '```' echo "${{ steps.meta.outputs.tags }}" echo '```' } >> "$GITHUB_STEP_SUMMARY"