|
| 1 | +# Publish Docker Image |
| 2 | +# Builds and pushes a multi-platform Docker image to ghcr.io on push to main, tags (v*.*.*), or PR to main. |
| 3 | +# Includes artifact attestation for supply chain security. |
| 4 | +name: Publish Docker Image |
| 5 | + |
| 6 | +on: |
| 7 | + push: |
| 8 | + tags: [ 'v*.*.*' ] |
| 9 | + |
| 10 | +env: |
| 11 | + REGISTRY: ghcr.io |
| 12 | + IMAGE_NAME: ${{ github.repository }} |
| 13 | + |
| 14 | +jobs: |
| 15 | + build-and-publish-image: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + |
| 18 | + permissions: |
| 19 | + contents: read |
| 20 | + packages: write |
| 21 | + attestations: write |
| 22 | + id-token: write |
| 23 | + |
| 24 | + steps: |
| 25 | + - name: Checkout repository |
| 26 | + uses: actions/checkout@v4 |
| 27 | + |
| 28 | + - name: Set up Docker Buildx |
| 29 | + uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3.10.0 |
| 30 | + |
| 31 | + - name: Log into registry ${{ env.REGISTRY }} |
| 32 | + uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0 |
| 33 | + with: |
| 34 | + registry: ${{ env.REGISTRY }} |
| 35 | + username: ${{ github.actor }} |
| 36 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 37 | + |
| 38 | + - name: Extract metadata (tags, labels) for Docker |
| 39 | + id: meta |
| 40 | + uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5.7.0 |
| 41 | + with: |
| 42 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 43 | + tags: | |
| 44 | + type=semver,pattern={{version}} |
| 45 | + type=sha |
| 46 | + type=raw,value=latest |
| 47 | +
|
| 48 | + - name: Build and push Docker image |
| 49 | + id: build-and-push |
| 50 | + uses: docker/build-push-action@14487ce63c7a62a4a324b0bfb37086795e31c6c1 # v6.16.0 |
| 51 | + with: |
| 52 | + context: . |
| 53 | + push: true |
| 54 | + tags: ${{ steps.meta.outputs.tags }} |
| 55 | + labels: ${{ steps.meta.outputs.labels }} |
| 56 | + platforms: linux/amd64,linux/arm64 |
| 57 | + cache-from: type=gha |
| 58 | + cache-to: type=gha,mode=max |
| 59 | + |
| 60 | + - name: Generate artifact attestation |
| 61 | + uses: actions/attest-build-provenance@v2 |
| 62 | + with: |
| 63 | + subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} |
| 64 | + subject-digest: ${{ steps.build-and-push.outputs.digest }} |
| 65 | + push-to-registry: true |
0 commit comments