|
1 |
| -name: Build Docker Image |
2 |
| - |
| 1 | +name: Build & Push Container |
3 | 2 | on:
|
| 3 | + push: |
| 4 | + branches: |
| 5 | + - 'main' |
| 6 | + tags: |
| 7 | + - '*' |
| 8 | + merge_group: |
4 | 9 | pull_request:
|
5 |
| - branches: [ main ] |
6 |
| - workflow_dispatch: |
| 10 | + types: [assigned, opened, synchronize, reopened] |
| 11 | + |
| 12 | +concurrency: |
| 13 | + group: ${{ github.workflow }}-${{ github.head_ref || github.ref }} |
| 14 | + cancel-in-progress: true |
| 15 | + |
| 16 | +env: |
| 17 | + REGISTRY: ghcr.io |
| 18 | + IMAGE_NAME: ${{ github.repository }} |
7 | 19 |
|
8 | 20 | jobs:
|
9 |
| - docker: |
| 21 | + docker-build: |
10 | 22 | runs-on: ubuntu-latest
|
| 23 | + permissions: |
| 24 | + contents: read |
| 25 | + packages: write |
| 26 | + attestations: write |
| 27 | + id-token: write |
11 | 28 | steps:
|
12 |
| - - name: Checkout code |
13 |
| - uses: actions/checkout@v4 |
| 29 | + - uses: actions/checkout@v4 |
| 30 | + |
| 31 | + - name: Set current timestamp |
| 32 | + id: vars |
| 33 | + run: | |
| 34 | + echo "timestamp=$(date +%s)" >> $GITHUB_OUTPUT |
| 35 | + echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT |
| 36 | +
|
| 37 | + - name: Log in to the Container registry |
| 38 | + uses: docker/login-action@v3 |
| 39 | + with: |
| 40 | + registry: ${{ env.REGISTRY }} |
| 41 | + username: ${{ github.actor }} |
| 42 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 43 | + |
| 44 | + - name: Docker Meta |
| 45 | + id: meta |
| 46 | + uses: docker/metadata-action@v5 |
| 47 | + with: |
| 48 | + images: | |
| 49 | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 50 | + flavor: | |
| 51 | + latest=false |
| 52 | + tags: | |
| 53 | + type=ref,event=branch,branch=main,suffix=-${{ steps.vars.outputs.sha_short }}-${{ steps.vars.outputs.timestamp }} |
| 54 | + type=pep440,pattern={{raw}} |
| 55 | + type=ref,event=pr |
| 56 | +
|
| 57 | + - name: Set up QEMU |
| 58 | + uses: docker/setup-qemu-action@v3 |
14 | 59 |
|
15 | 60 | - name: Set up Docker Buildx
|
16 | 61 | uses: docker/setup-buildx-action@v3
|
17 | 62 |
|
18 |
| - - name: Build |
| 63 | + - name: Build and push |
19 | 64 | uses: docker/build-push-action@v6
|
| 65 | + id: push |
20 | 66 | with:
|
21 |
| - push: false |
22 | 67 | context: .
|
23 |
| - file: Dockerfile |
24 |
| - tags: "${{ github.sha }}" |
| 68 | + platforms: linux/amd64, linux/arm64 |
| 69 | + push: ${{ github.event_name != 'pull_request' }} |
| 70 | + tags: ${{ steps.meta.outputs.tags }} |
| 71 | + labels: ${{ steps.meta.outputs.labels }} |
| 72 | + cache-from: type=gha |
| 73 | + cache-to: type=gha,mode=max |
| 74 | + |
| 75 | + - name: Generate artifact attestation |
| 76 | + if: github.event_name != 'pull_request' |
| 77 | + uses: actions/attest-build-provenance@v2 |
| 78 | + with: |
| 79 | + subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} |
| 80 | + subject-digest: ${{ steps.push.outputs.digest }} |
| 81 | + push-to-registry: true |
0 commit comments