|
1 |
| -name: Build and Push Docker Images |
| 1 | +name: Publish Docker image |
2 | 2 |
|
3 | 3 | on:
|
4 | 4 | workflow_run:
|
|
13 | 13 | IMAGE_NAME: ${{ github.repository }}
|
14 | 14 |
|
15 | 15 | jobs:
|
16 |
| - build: |
| 16 | + build-and-push-image: |
17 | 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 | + # |
18 | 25 | steps:
|
19 |
| - - name: Checkout code |
20 |
| - uses: actions/checkout@v3 |
| 26 | + - name: Checkout repository |
| 27 | + uses: actions/checkout@v4 |
21 | 28 |
|
22 |
| - - name: Set up Docker Buildx |
23 |
| - uses: docker/setup-buildx-action@v2 |
24 |
| - |
25 |
| - - name: Log in to GitHub Container Registry |
26 |
| - uses: docker/login-action@v2 |
| 29 | + - name: Log in to the Container registry |
| 30 | + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 |
27 | 31 | with:
|
28 |
| - registry: ghcr.io |
| 32 | + registry: ${{ env.REGISTRY }} |
29 | 33 | username: ${{ github.actor }}
|
30 | 34 | password: ${{ secrets.GITHUB_TOKEN }}
|
| 35 | + # This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels. |
| 36 | + - name: Extract metadata (tags, labels) for Docker |
| 37 | + id: meta |
| 38 | + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 |
| 39 | + with: |
| 40 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 41 | + # This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages. |
| 42 | + # It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository. |
| 43 | + # It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step. |
| 44 | + - name: Build and push Docker image |
| 45 | + id: push |
| 46 | + uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 |
| 47 | + with: |
| 48 | + context: . |
| 49 | + push: true |
| 50 | + tags: ${{ steps.meta.outputs.tags }} |
| 51 | + labels: ${{ steps.meta.outputs.labels }} |
31 | 52 |
|
32 |
| - - name: Build and push Docker images using docker-compose |
33 |
| - run: | |
34 |
| - # Install Docker Compose |
35 |
| - sudo apt-get update |
36 |
| - sudo apt-get install -y docker-compose |
| 53 | + # This step generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built. It increases supply chain security for people who consume the image. For more information, see "[AUTOTITLE](/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds)." |
| 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 |
37 | 60 |
|
38 |
| - # Build and push images |
39 |
| - docker-compose build |
40 |
| - docker-compose push |
|
0 commit comments