|
| 1 | +# <https://docs.github.com/en/actions/publishing-packages/publishing-docker-images> |
| 2 | +name: Create and publish a Docker image |
| 3 | + |
| 4 | +on: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - main |
| 8 | + |
| 9 | +env: |
| 10 | + IMAGE_NAME: ${{ github.repository }} |
| 11 | + REGISTRY: ghcr.io |
| 12 | + |
| 13 | +jobs: |
| 14 | + build-and-push-image: |
| 15 | + permissions: |
| 16 | + attestations: write |
| 17 | + contents: read |
| 18 | + id-token: write |
| 19 | + packages: write |
| 20 | + runs-on: ubuntu-latest |
| 21 | + steps: |
| 22 | + |
| 23 | + - name: Checkout repository |
| 24 | + uses: actions/checkout@v4 |
| 25 | + |
| 26 | + - name: Log in to the Container registry |
| 27 | + uses: docker/login-action@v3 |
| 28 | + with: |
| 29 | + registry: ${{ env.REGISTRY }} |
| 30 | + username: ${{ github.actor }} |
| 31 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 32 | + |
| 33 | + - id: meta |
| 34 | + name: Extract metadata (tags, labels) for Docker |
| 35 | + uses: docker/metadata-action@v5 |
| 36 | + with: |
| 37 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 38 | + tags: | |
| 39 | + type=raw,value=latest |
| 40 | + type=sha |
| 41 | +
|
| 42 | + # setup qemu and buildx for cross-builds (arm64) |
| 43 | + - name: Set up QEMU (for arm64 builds) |
| 44 | + uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # v3 |
| 45 | + - name: Set up Docker Buildx |
| 46 | + uses: docker/setup-buildx-action@988b5a0280414f521da01fcc63a27aeeb4b104db # v3 |
| 47 | + |
| 48 | + - id: push |
| 49 | + name: Build and push Docker image |
| 50 | + uses: docker/build-push-action@v6 |
| 51 | + with: |
| 52 | + context: . |
| 53 | + labels: ${{ steps.meta.outputs.labels }} |
| 54 | + platforms: linux/amd64,linux/arm64 |
| 55 | + push: true |
| 56 | + tags: ${{ steps.meta.outputs.tags }} |
| 57 | + |
| 58 | + - name: Generate artifact attestation |
| 59 | + uses: actions/attest-build-provenance@v1 |
| 60 | + with: |
| 61 | + push-to-registry: true |
| 62 | + subject-digest: ${{ steps.push.outputs.digest }} |
| 63 | + subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} |
0 commit comments