1+ name : Build and Push Docker Image
2+
3+ on :
4+ push :
5+ branches :
6+ - master
7+ tags :
8+ - ' v*'
9+ pull_request :
10+ branches :
11+ - master
12+
13+ env :
14+ REGISTRY : ghcr.io
15+ IMAGE_NAME : ${{ github.repository }}
16+
17+ jobs :
18+ build-and-push :
19+ runs-on : ubuntu-latest
20+ permissions :
21+ contents : read
22+ packages : write
23+ id-token : write
24+ attestations : write
25+
26+ steps :
27+ - name : Checkout repository
28+ uses : actions/checkout@v4
29+
30+ - name : Set up Docker Buildx
31+ uses : docker/setup-buildx-action@v3
32+
33+ - name : Log in to Container Registry
34+ uses : docker/login-action@v3
35+ with :
36+ registry : ${{ env.REGISTRY }}
37+ username : ${{ github.actor }}
38+ password : ${{ secrets.GITHUB_TOKEN }}
39+
40+ - name : Extract metadata
41+ id : meta
42+ uses : docker/metadata-action@v5
43+ with :
44+ images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
45+ tags : |
46+ type=ref,event=branch
47+ type=ref,event=pr
48+ type=semver,pattern={{version}}
49+ type=semver,pattern={{major}}.{{minor}}
50+ type=raw,value=latest,enable={{is_default_branch}}
51+
52+ - name : Build and push Docker image
53+ id : build
54+ uses : docker/build-push-action@v5
55+ with :
56+ context : .
57+ platforms : linux/amd64,linux/arm64
58+ push : true
59+ tags : ${{ steps.meta.outputs.tags }}
60+ labels : ${{ steps.meta.outputs.labels }}
61+ cache-from : type=gha
62+ cache-to : type=gha,mode=max
63+
64+ - name : Generate artifact attestation
65+ uses : actions/attest-build-provenance@v1
66+ with :
67+ subject-name : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
68+ subject-digest : ${{ steps.build.outputs.digest }}
69+ push-to-registry : true
0 commit comments