|
| 1 | +name: Create and publish a Docker image |
| 2 | + |
| 3 | +# Configures this workflow to run every time a tag is pushed. |
| 4 | +on: |
| 5 | + push: |
| 6 | + tags: |
| 7 | + - '*' |
| 8 | + |
| 9 | +# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds. |
| 10 | +env: |
| 11 | + REGISTRY: ghcr.io |
| 12 | + IMAGE_NAME: ${{ github.repository }} |
| 13 | + |
| 14 | +# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu. |
| 15 | +jobs: |
| 16 | + build-and-push-image: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. |
| 19 | + permissions: |
| 20 | + contents: read |
| 21 | + packages: write |
| 22 | + attestations: write |
| 23 | + id-token: write |
| 24 | + steps: |
| 25 | + - name: Checkout repository |
| 26 | + uses: actions/checkout@v4 |
| 27 | + |
| 28 | + - name: Log in to the Container registry |
| 29 | + uses: docker/login-action@v2 |
| 30 | + with: |
| 31 | + registry: ${{ env.REGISTRY }} |
| 32 | + username: ${{ github.actor }} |
| 33 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 34 | + |
| 35 | + - name: Extract metadata (tags, labels) for Docker |
| 36 | + id: meta |
| 37 | + uses: docker/metadata-action@v4 |
| 38 | + with: |
| 39 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 40 | + tags: | |
| 41 | + type=ref,event=tag |
| 42 | + labels: | |
| 43 | + type=ref,event=tag |
| 44 | +
|
| 45 | + - name: Build and push Docker image |
| 46 | + id: push |
| 47 | + uses: docker/build-push-action@v4 |
| 48 | + with: |
| 49 | + context: . |
| 50 | + push: true |
| 51 | + tags: ${{ steps.meta.outputs.tags }} |
| 52 | + labels: ${{ steps.meta.outputs.labels }} |
| 53 | + |
| 54 | + - name: Generate artifact attestation |
| 55 | + uses: actions/attest-build-provenance@v1 |
| 56 | + with: |
| 57 | + subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} |
| 58 | + subject-digest: ${{ steps.push.outputs.digest }} |
| 59 | + push-to-registry: true |
0 commit comments