@@ -98,33 +98,42 @@ jobs:
9898 password : ${{ secrets.GITHUB_TOKEN }}
9999
100100 - name : Pull latest image
101+ id : pull-image
101102 run : |
102- docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ matrix.component }}-latest || echo "Image not found, skipping scan"
103+ IMAGE_NAME_LOWER=$(echo "${{ env.IMAGE_NAME }}" | tr '[:upper:]' '[:lower:]')
104+ if docker pull ${{ env.REGISTRY }}/${IMAGE_NAME_LOWER}:${{ matrix.component }}-latest; then
105+ echo "image_exists=true" >> $GITHUB_OUTPUT
106+ echo "image_ref=${{ env.REGISTRY }}/${IMAGE_NAME_LOWER}:${{ matrix.component }}-latest" >> $GITHUB_OUTPUT
107+ else
108+ echo "image_exists=false" >> $GITHUB_OUTPUT
109+ echo "Image not found, skipping scan for ${{ matrix.component }}"
110+ fi
103111 continue-on-error : true
104112
105113 - name : Run Trivy container scan
114+ if : steps.pull-image.outputs.image_exists == 'true'
106115 uses : aquasecurity/trivy-action@master
107116 with :
108- image-ref : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ matrix.component }}-latest
117+ image-ref : ${{ steps.pull-image.outputs.image_ref }}
109118 format : ' sarif'
110119 output : ' trivy-${{ matrix.component }}.sarif'
111120 severity : ' CRITICAL,HIGH,MEDIUM'
112121 exit-code : ' 0'
113122 continue-on-error : true
114123
115124 - name : Upload container scan results
125+ if : steps.pull-image.outputs.image_exists == 'true' && always()
116126 uses : github/codeql-action/upload-sarif@v3
117- if : always()
118127 with :
119128 sarif_file : ' trivy-${{ matrix.component }}.sarif'
120129 category : ' container-${{ matrix.component }}'
121130 continue-on-error : true
122131
123132 - name : Run Grype vulnerability scanner
133+ if : steps.pull-image.outputs.image_exists == 'true'
124134 uses : anchore/scan-action@v3
125- if : always()
126135 with :
127- image : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ matrix.component }}-latest
136+ image : ${{ steps.pull-image.outputs.image_ref }}
128137 fail-build : false
129138 severity-cutoff : high
130139 continue-on-error : true
0 commit comments