11name : Build and Push
2+
23on :
34 push :
45 branches :
56 - ' **'
67 tags :
78 - ' v[0-9]+.[0-9]+.[0-9]+'
89 - ' v[0-9]+.[0-9]+.[0-9]+-*'
10+ workflow_dispatch :
11+ inputs :
12+ force_push :
13+ description : ' Force push to registry even if not latest tag'
14+ required : false
15+ default : false
16+ type : boolean
17+
18+ # Explicit permissions following least-privilege principle
19+ permissions :
20+ contents : read
21+ packages : write
22+
23+ # Prevent duplicate workflow runs
24+ concurrency :
25+ group : ${{ github.workflow }}-${{ github.ref }}
26+ cancel-in-progress : true
927
1028# env:
1129# ## overrides the docker image name (name is repo name with docker- prefix stripped)
1735 outputs :
1836 image : ${{ steps.set.outputs.image }}
1937 steps :
20- -
38+ - name : Set image name
2139 uses : actions/github-script@v7
2240 id : set
2341 with :
@@ -34,18 +52,20 @@ jobs:
3452 - name : Checkout
3553 uses : actions/checkout@v4
3654
37- - uses : hadolint/hadolint-action@v3.1.0
55+ - name : Lint Dockerfile
56+ uses : hadolint/hadolint-action@v3.1.0
3857 with :
3958 dockerfile : Dockerfile
40- -
59+
60+ - name : Find latest tag
4161 uses : dysnix/find-latest-tag@v1
4262 id : latest
4363 with :
4464 regex : ' ^v\d'
4565 compared-to-tag : ${{ github.ref }}
4666 repository : ${{ github.repository }}
47- -
48- name : Docker meta
67+
68+ - name : Docker meta
4969 id : meta
5070 uses : docker/metadata-action@v5
5171 with :
@@ -55,16 +75,18 @@ jobs:
5575 tags : |
5676 type=ref,event=tag
5777 type=ref,event=branch
78+ type=sha,prefix=,format=short
5879
5980 - name : Set up QEMU
6081 uses : docker/setup-qemu-action@v3
6182 with :
62- # amd64 is native platform at the moment and should not be specified here to keep amd64 builds fast
83+ # amd64 is native platform and should not be specified here to keep amd64 builds fast
6384 platforms : linux/arm64
6485
6586 - name : Set up Docker Buildx
6687 uses : docker/setup-buildx-action@v3
67- -
88+
89+ - name : Login to Docker Hub
6890 uses : docker/login-action@v3
6991 with :
7092 username : ${{ secrets.DOCKERHUB_USER }}
7597 with :
7698 platforms : linux/amd64,linux/arm64
7799 context : .
78- push : ${{ steps.latest.outputs.newer == 'true' || steps.latest.outputs.equal == 'true' }}
100+ push : ${{ steps.latest.outputs.newer == 'true' || steps.latest.outputs.equal == 'true' || inputs.force_push == true }}
79101 file : Dockerfile
80102 tags : ${{ steps.meta.outputs.tags }}
81103 labels : ${{ steps.meta.outputs.labels }}
104+ cache-from : type=gha
105+ cache-to : type=gha,mode=max
106+ provenance : true
107+ sbom : true
0 commit comments