|
| 1 | +name: Publish Docker 🐳 images 📦 to GitHub Container Registry |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - '**' |
| 7 | + |
| 8 | +jobs: |
| 9 | + build-and-publish-to-ghcr: |
| 10 | + # Explicitly grant the `secrets.GITHUB_TOKEN` permissions. |
| 11 | + permissions: |
| 12 | + # Grant the ability to write to GitHub Packages (push Docker images to |
| 13 | + # GitHub Container Registry). |
| 14 | + packages: write |
| 15 | + name: Build and publish Docker 🐳 images 📦 to GitHub Container Registry |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - name: Checkout main |
| 19 | + uses: actions/checkout@v3 |
| 20 | + with: |
| 21 | + fetch-depth: 0 |
| 22 | + |
| 23 | + - name: Extract metadata (tags, labels) for Docker |
| 24 | + id: meta |
| 25 | + uses: docker/metadata-action@v5 |
| 26 | + with: |
| 27 | + images: ghcr.io/${{ github.repository }} |
| 28 | + |
| 29 | + - name: Write version |
| 30 | + run: ./scripts/insert-version-pyproject.sh ${{github.ref_name}} |
| 31 | + |
| 32 | + - name: Set up QEMU |
| 33 | + uses: docker/setup-qemu-action@v3 |
| 34 | + |
| 35 | + - name: Set up Docker Buildx |
| 36 | + uses: docker/setup-buildx-action@v3 |
| 37 | + |
| 38 | + - name: Login to GitHub Container Registry |
| 39 | + uses: docker/login-action@v3 |
| 40 | + with: |
| 41 | + registry: ghcr.io |
| 42 | + # This is the user that triggered the Workflow. In this case, it will |
| 43 | + # either be the user whom created the Release or manually triggered |
| 44 | + # the workflow_dispatch. |
| 45 | + username: ${{ github.actor }} |
| 46 | + # `secrets.GITHUB_TOKEN` is a secret that's automatically generated by |
| 47 | + # GitHub Actions at the start of a workflow run to identify the job. |
| 48 | + # This is used to authenticate against GitHub Container Registry. |
| 49 | + # See https://docs.github.com/en/actions/security-guides/automatic-token-authentication#about-the-github_token-secret |
| 50 | + # for more detailed information. |
| 51 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 52 | + |
| 53 | + - name: Build and push image |
| 54 | + uses: docker/build-push-action@v5 |
| 55 | + with: |
| 56 | + push: true # push the image to ghcr |
| 57 | + tags: > |
| 58 | + ghcr.io/thought-machine/generic-k8s-webhook:${{github.sha}}, |
| 59 | + ghcr.io/thought-machine/generic-k8s-webhook:${{github.ref_name}} |
| 60 | + labels: ${{ steps.meta.outputs.labels }} |
| 61 | + platforms: linux/amd64,linux/arm64 |
0 commit comments