1111 description : ' Name of Docker Image'
1212 type : string
1313 required : true
14+ image-tag :
15+ description : ' Tag of Docker Image'
16+ type : string
17+ required : true
18+ security-scan :
19+ description : ' Enable Security Scan'
20+ default : ' true'
21+ type : boolean
22+ push :
23+ description : ' Push Docker Image to Registry'
24+ default : ' false'
25+ type : boolean
1426 secrets :
1527 dockerhub-username :
1628 required : true
1729 dockerhub-pat :
1830 required : true
1931
2032jobs :
21- build-test :
22- if : github.event_name == 'pull_request'
33+ build :
2334 runs-on : ubuntu-latest
2435 steps :
2536 - name : Checkout Repository
@@ -37,13 +48,14 @@ jobs:
3748 context : .
3849 file : ${{ inputs.dockerfile }}
3950 platforms : linux/amd64,linux/arm64
40- push : false
41- tags : ${{ inputs.image-name }}:${{ github.sha }}
51+ push : ${{ inputs.push }}
52+ tags : ${{ inputs.image-name }}:${{ inputs.image-tag }}
4253
4354 - name : Run Trivy vulnerability scanner
55+ if : ${{ inputs.security-scan }}
4456 uses :
aquasecurity/[email protected] 4557 with :
46- image-ref : ${{ inputs.image-name }}:${{ github.sha }}
58+ image-ref : ${{ inputs.image-name }}:${{ inputs.image-tag }}
4759 format : ' table'
4860 exit-code : ' 1'
4961 ignore-unfixed : true
5365 output : trivy.txt
5466
5567 - name : Publish Trivy Output to Summary
68+ if : ${{ inputs.security-scan }}
5669 run : |
5770 if [[ -s trivy.txt ]]; then
5871 {
6578 echo "</details>"
6679 } >> $GITHUB_STEP_SUMMARY
6780 fi
68-
69- build-push :
70- if : github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
71- runs-on : ubuntu-latest
72- steps :
73- - name : Checkout Repository
74- uses : actions/checkout@v4
75-
76- - name : Login to Docker Hub
77- uses : docker/login-action@v3
78- with :
79- username : ${{ secrets.dockerhub-username }}
80- password : ${{ secrets.dockerhub-pat }}
81-
82- - name : Set up Docker Buildx
83- uses : docker/setup-buildx-action@v3
84-
85- - name : Push Docker Image
86- uses : docker/build-push-action@v6
87- with :
88- context : .
89- file : ${{ inputs.dockerfile }}
90- platforms : linux/amd64,linux/arm64
91- push : true
92- tags : ${{ inputs.image-name }}:${{ github.ref_name }}
0 commit comments