@@ -162,6 +162,8 @@ jobs:
162162 docker-build-scan-push :
163163# if: github.ref == 'refs/heads/main'
164164 runs-on : ubuntu-latest
165+ env :
166+ BASE_IMAGE : abhisheksr01/companieshouse
165167# needs:
166168# - unit-test
167169# - mutation-test
@@ -189,19 +191,19 @@ jobs:
189191# echo "is-version-bumped: ${{ steps.bump-version.outputs.is-version-bumped }}"
190192# echo "is-dryrun-version-bumped: ${{ steps.bump-version.outputs.is-dryrun-version-bumped }}"
191193# shell: bash
192- # - name: Login to Docker Hub
193- # uses: docker/login-action@v3
194- # with:
195- # username: ${{ vars.DOCKERHUB_USERNAME }}
196- # password: ${{ secrets.DOCKERHUB_TOKEN }}
194+ - name : Login to Docker Hub
195+ uses : docker/login-action@v3
196+ with :
197+ username : ${{ vars.DOCKERHUB_USERNAME }}
198+ password : ${{ secrets.DOCKERHUB_TOKEN }}
197199 - name : Set up Docker Buildx
198200 uses : docker/setup-buildx-action@v3
199201 - name : Docker meta
200202# if: ${{ steps.bump-version.outputs.is-dryrun-version-bumped == 'true' }}
201203 id : meta
202204 uses : docker/metadata-action@v5
203205 with :
204- images : abhisheksr01/companieshouse
206+ images : ${{ env.BASE_IMAGE }}
205207 context : git
206208 tags : |
207209 type=ref,event=pr
@@ -222,27 +224,36 @@ jobs:
222224 load : true
223225 tags : ${{ steps.meta.outputs.tags }}
224226 labels : ${{ steps.meta.outputs.labels }}
225- - name : Convert Image to Tar
226- run : |
227- docker images
228- tags="${{ steps.meta.outputs.tags }}"
229- tags="${tags//,/ }" # replace commas with spaces
230- echo "Saving images: $tags"
227+ cache-to : type=registry,ref=${{ env.BASE_IMAGE }}:cache
228+ cache-from : type=registry,ref=${{ env.BASE_IMAGE }}:cache,mode=max
231229 - name : Scan Image
232230 uses :
aquasecurity/[email protected] 233231 with :
232+ versin : 0.66
234233 image-ref : ${{ steps.meta.outputs.tags }}
235234 format : ' table'
236235 exit-code : ' 1'
237236 ignore-unfixed : true
238237 vuln-type : ' os,library'
239- scanners : ' vuln,secret,misconfig,license'
238+ scanners : ' vuln,secret,misconfig'
239+ - name : Validate Container Image
240+ run : |
241+ docker run -d -p 8080:8080 ${{ steps.meta.outputs.tags }}
242+ sleep 5 # Wait for container to start
243+ HEALTH_STATUS=$(curl -s http://localhost:8080/companieshouse/actuator/health | jq -r '.status')
244+ if [ "$HEALTH_STATUS" != "UP" ]; then
245+ echo "Health check failed. Status: $HEALTH_STATUS"
246+ exit 1
247+ fi
248+ echo "Health check passed. Status: $HEALTH_STATUS"
240249 - name : Re-Build & Push Image
241250 uses : docker/build-push-action@v6
242251 with :
243252 push : true
244253 tags : ${{ steps.meta.outputs.tags }}
245254 labels : ${{ steps.meta.outputs.labels }}
255+ cache-to : type=registry,ref=${{ env.BASE_IMAGE }}:cache
256+ cache-from : type=registry,ref=${{ env.BASE_IMAGE }}:cache,mode=max
246257 sbom : true
247258 provenance : true
248259
0 commit comments