@@ -80,23 +80,10 @@ jobs:
8080 build-args : ${{ inputs.build-args }}
8181 context : ${{ inputs.context }}
8282 file : ${{ inputs.dockerfile }}
83- platforms : ${{ inputs.platforms }}
84- push : ${{ inputs. push }}
83+ platforms : linux/amd64 # Build single platform for security scanning
84+ push : false # Don't push yet, wait for security checks
8585 tags : ${{ inputs.image-name }}:${{ inputs.image-tag }}
86-
87- - name : Build Docker Image as Tarball
88- if : ${{ inputs.security-scan }}
89- run : |
90- BUILD_ARGS=""
91- if [ -n "${{ inputs.build-args }}" ]; then
92- while IFS= read -r line; do
93- if [ -n "$line" ]; then
94- BUILD_ARGS="$BUILD_ARGS --build-arg $line"
95- fi
96- done <<< "${{ inputs.build-args }}"
97- fi
98- docker build $BUILD_ARGS -t ${{ inputs.image-name }}:${{ inputs.image-tag }} -f ${{ inputs.dockerfile }} ${{ inputs.context }}
99- docker save -o vuln-image.tar ${{ inputs.image-name }}:${{ inputs.image-tag }}
86+ outputs : type=docker,dest=vuln-image.tar # Export as tarball for security scanning
10087
10188 - name : Run Trivy vulnerability scanner
10289 id : trivy
@@ -196,3 +183,35 @@ jobs:
196183 ${{ steps.read_hadolint.outputs.report }}
197184 ```
198185 </details>
186+
187+ - name : Fail build on High/Critical Vulnerabilities
188+ id : security_check
189+ if : ${{ inputs.security-scan }}
190+ uses : aquasecurity/trivy-action@0.29.0
191+ with :
192+ input : vuln-image.tar
193+ format : ${{ (inputs.security-report == 'sarif' && 'sarif') || 'table' }}
194+ ignore-unfixed : true
195+ vuln-type : " os,library"
196+ severity : " CRITICAL,HIGH"
197+ hide-progress : true
198+ skip-setup-trivy : true
199+ exit-code : 1
200+
201+ - name : Build and Push Multi-Platform Image
202+ if : ${{ inputs.push }}
203+ uses : docker/build-push-action@v6
204+ with :
205+ build-args : ${{ inputs.build-args }}
206+ context : ${{ inputs.context }}
207+ file : ${{ inputs.dockerfile }}
208+ platforms : ${{ inputs.platforms }}
209+ push : true
210+ tags : ${{ inputs.image-name }}:${{ inputs.image-tag }}
211+
212+ - name : Cleanup
213+ id : cleanup
214+ if : always()
215+ run : |
216+ rm -f trivy.txt trivy-results.sarif vuln-image.tar
217+ docker image rm -f ${{ inputs.image-name }}:${{ inputs.image-tag }}
0 commit comments