2929 required : false
3030 type : boolean
3131 default : false
32+ app_dir :
33+ description : Directory containing application code and compose files
34+ required : true
35+ type : string
36+ snapshot_test_dir :
37+ description : Directory containing the snapshot tests
38+ required : true
39+ type : string
40+ gh_registry :
41+ description : GitHub registry to push images for Snapshot Testing
42+ required : true
43+ type : string
44+ default : ghcr.io
3245
3346jobs :
3447 get-functions :
6982 id-token : write
7083 contents : read
7184 pull-requests : read
85+ packages : write
7286 needs : get-functions
7387 strategy :
7488 matrix :
@@ -91,6 +105,13 @@ jobs:
91105 path : templates
92106 ref : main
93107
108+ - name : Log in to the GitHub Container registry
109+ uses : docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1
110+ with :
111+ registry : ${{ inputs.gh_registry }}
112+ username : ${{ github.actor }}
113+ password : ${{ secrets.GITHUB_TOKEN }}
114+
94115 - name : Az CLI login
95116 if : github.ref == 'refs/heads/main'
96117 uses : azure/login@v2
@@ -135,6 +156,7 @@ jobs:
135156 env :
136157 COMPOSE_FILE : ${{ inputs.docker_compose_file }}
137158 PROJECT_NAME : ${{ inputs.project_name }}
159+ GH_REGISTRY : ${{ inputs.gh_registry }}
138160 run : |
139161 function=${{ matrix.function }}
140162
@@ -173,20 +195,29 @@ jobs:
173195 docker push "${repo_name}:${ENVIRONMENT_TAG}"
174196 fi
175197
198+ echo Tagging the image for GitHub Registry...
199+ GH_IMAGE="${{ inputs.gh_registry }}/${{ github.repository_owner }}/${{ inputs.project_name }}-${{ matrix.function }}:latest"
200+ # make it lowercase
201+ GH_IMAGE_ID="${GH_IMAGE,,}"
202+ docker tag ${PROJECT_NAME}-${function}:latest $GH_IMAGE_ID
203+
204+ echo Pushing the image into GitHub Registry...
205+ docker push $GH_IMAGE_ID
206+
176207 export SBOM_REPOSITORY_REPORT="sbom-${function}-repository-report"
177208 echo "SBOM_REPOSITORY_REPORT=$SBOM_REPOSITORY_REPORT" >> $GITHUB_ENV
178209 bash -x ${GITHUB_WORKSPACE}/templates/scripts/reports/create-sbom-report.sh
179210
180211 export VULNERABILITIES_REPOSITORY_REPORT="vulnerabilities-${function}-repository-report"
181212 echo "VULNERABILITIES_REPOSITORY_REPORT=$VULNERABILITIES_REPOSITORY_REPORT" >> $GITHUB_ENV
182213
183- echo "Running the scan-vulnerabilities script in a look with 10 minutes timeout, with 3 retries..."
214+ echo "Running the scan-vulnerabilities script in a look with 5 minutes timeout, with 3 retries..."
184215 retries=3
185- delay=300 # 5 minutes
216+ delay=30
186217 count=0
187218 until [ $count -ge $retries ]
188219 do
189- timeout 10m bash -x ${GITHUB_WORKSPACE}/templates/scripts/reports/scan-vulnerabilities.sh && break
220+ timeout 5m bash -x ${GITHUB_WORKSPACE}/templates/scripts/reports/scan-vulnerabilities.sh && break
190221 count=$((count+1))
191222 echo "Attempt $count/$retries failed, retrying after $delay seconds..."
192223 sleep $delay
@@ -275,6 +306,119 @@ jobs:
275306 path : ./${{ env.VULNERABILITIES_SUMMARY_LOGFILE }}
276307 retention-days : 21
277308
309+ snapshot-tests :
310+ name : Snapshot tests
311+ runs-on : ubuntu-latest
312+ permissions :
313+ packages : read
314+ needs :
315+ - get-functions
316+ - build-and-push
317+ env :
318+ SNAPSHOT_TEST_DIR : ${{ inputs.snapshot_test_dir }}
319+ APP_DIR : ${{ inputs.app_dir }}
320+ steps :
321+ - name : Checkout code
322+ uses : actions/checkout@v4
323+ with :
324+ submodules : true
325+
326+ - name : Check runner resources before download
327+ run : |
328+ echo "--- DISK SPACE ---"
329+ df -h
330+ echo "--- MEMORY ---"
331+ free -h
332+
333+ - name : Log in to the GitHub Container registry
334+ uses : docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1
335+ with :
336+ registry : ${{ inputs.gh_registry }}
337+ username : ${{ github.actor }}
338+ password : ${{ secrets.GITHUB_TOKEN }}
339+
340+ - name : Generate GHCR override file
341+ working-directory : ${{ inputs.app_dir }}
342+ env :
343+ PROJECT_NAME : ${{ inputs.project_name }}
344+ run : |
345+
346+ echo "Testing the access to get-functions output"
347+ echo ${{ needs.get-functions.outputs.FUNC_NAMES }}
348+ echo "___________________"
349+
350+ echo "Generating compose.ghcr.yaml file..."
351+ echo "services:" > compose.ghcr.yaml
352+ for function in $(echo '${{ needs.get-functions.outputs.FUNC_NAMES }}' | jq -r '.[]'); do
353+ # Skipping services we don't need during local testing on the agent
354+ if [[ "$function" == "web" || "$function" == "wiremock" ]]; then
355+ echo "Skipping ${function}..."
356+ continue
357+ fi
358+ RAW_IMAGE_URL="${{ inputs.gh_registry }}/${{ github.repository_owner }}/${PROJECT_NAME}-${function}:latest"
359+ LOWERCASE_IMAGE_URL="${RAW_IMAGE_URL,,}"
360+ echo " ${function}:" >> compose.ghcr.yaml
361+ echo " image: ${LOWERCASE_IMAGE_URL}" >> compose.ghcr.yaml
362+ echo " build: {}" >> compose.ghcr.yaml
363+ done
364+ echo "--- Generated compose.ghcr.yaml ---"
365+ cat compose.ghcr.yaml
366+ echo "----------------------------------------"
367+
368+ - name : Run application using GHCR images
369+ working-directory : ${{ inputs.app_dir }}
370+ env :
371+ PROJECT_NAME : ${{ inputs.project_name }}
372+ SNAPSHOT_PASSWORD : ${{ secrets.SNAPSHOT_PASSWORD }}
373+ SNAPSHOT_AZURITE_CONNECTION_STRING : ${{ secrets.SNAPSHOT_AZURITE_CONNECTION_STRING }}
374+ SNAPSHOT_DB_NAME : ${{ vars.SNAPSHOT_DB_NAME }}
375+ run : |
376+
377+ echo "Creating .env file for Docker Compose..."
378+ cat > .env <<EOL
379+ PASSWORD=$SNAPSHOT_PASSWORD
380+ AZURITE_CONNECTION_STRING=$SNAPSHOT_AZURITE_CONNECTION_STRING
381+ DB_NAME=$SNAPSHOT_DB_NAME
382+ EOL
383+
384+ echo "Check the .env file"
385+ cat .env
386+
387+ echo "Build the dependencies needed for local operation..."
388+ docker compose -f compose.deps.yaml -p ${PROJECT_NAME} --profile "*" build --no-cache
389+
390+ # Run docker compose using the base file
391+ echo "Run docker compose deps..."
392+ docker compose -f compose.deps.yaml up -d --no-build
393+ echo "Waiting 10s for the depencies to be accessible..."
394+ sleep 10
395+
396+ echo "Run docker compose app with the GHCR..."
397+ docker compose -f compose.data-services.yaml -f compose.core.yaml -f compose.cohort-distribution.yaml -f compose.ghcr.yaml up -d --no-build
398+ echo "Waiting 10s for the app to be accessible..."
399+ sleep 10
400+
401+ - name : Check runner resources after starting the application
402+ run : |
403+ echo "--- DISK SPACE ---"
404+ df -h
405+ echo "--- MEMORY ---"
406+ free -h
407+
408+ - name : print DB logs
409+ run : docker logs db
410+
411+ - name : check container statuses
412+ run : docker ps -a
413+
414+ - name : Run snapshot tests
415+ working-directory : ${{ inputs.snapshot_test_dir }}
416+ run : bash run-snapshot-tests.sh
417+
418+ - name : Teardown application
419+ working-directory : ${{ env.APP_DIR }}
420+ run : docker compose down && docker compose -f compose.deps.yaml down
421+
278422 aggregate-json :
279423 runs-on : ubuntu-latest
280424 needs : build-and-push
0 commit comments