Skip to content

Commit a4b4bad

Browse files
committed
feat: initial version of the new workflows
1 parent 09db41c commit a4b4bad

File tree

1 file changed

+5
-151
lines changed

1 file changed

+5
-151
lines changed

.github/workflows/stage-3-build-images-devtest.yaml

Lines changed: 5 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,6 @@ jobs:
6868
ref: main
6969

7070
- name: Determine which Docker container(s) to build
71-
id: get-function-names
72-
env:
73-
COMPOSE_FILES_CSV: ${{ inputs.docker_compose_file }}
74-
EXCLUDED_CONTAINERS_CSV: ${{ inputs.excluded_containers_csv_list }}
75-
SOURCE_CODE_PATH: ${{ inputs.function_app_source_code_path }}
76-
MANUAL_BUILD_ALL: ${{ inputs.build_all_images || false }}
77-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
78-
run: bash scripts/deployment/get-docker-names.sh
7971

8072
build-and-push:
8173
runs-on: ubuntu-latest
@@ -170,7 +162,7 @@ jobs:
170162
171163
# Tag the image
172164
echo "Tag the image:"
173-
docker tag ${PROJECT_NAME}-${function}:latest "$repo_name:${COMMIT_HASH_TAG}"
165+
docker tag ${PROJECT_NAME}-$ {function}:latest "$repo_name:${COMMIT_HASH_TAG}"
174166
docker tag ${PROJECT_NAME}-${function}:latest "$repo_name:${PR_NUM_TAG}"
175167
docker tag ${PROJECT_NAME}-${function}:latest "$repo_name:${ENVIRONMENT_TAG}"
176168
@@ -182,86 +174,11 @@ jobs:
182174
echo "PR_NUM_TAG=${PR_NUM_TAG}" >> ${GITHUB_ENV}
183175
184176
# Push the image to the repository
185-
if [ "${GITHUB_REF}" == 'refs/heads/main' ]; then
186-
docker push "${repo_name}:${COMMIT_HASH_TAG}"
187-
if [ "${PR_NUM_TAG}" != 'pr' ]; then
188-
docker push "${repo_name}:${PR_NUM_TAG}"
189-
fi
190-
docker push "${repo_name}:${ENVIRONMENT_TAG}"
191-
fi
192-
193-
- name: Run Grype Scan and Save Full Report
194-
uses: anchore/scan-action@56e320f818c551f3f035fde89894504f269ad30b
195-
env:
196-
PROJECT_NAME: ${{ inputs.project_name }}
197-
id: grype
198-
with:
199-
image: "${{ env.PROJECT_NAME }}-${{ matrix.function }}:latest"
200-
output-format: 'table'
201-
output-file: grype-report.txt
202-
fail-build: false
203-
204-
- name: Create Custom Summary Log from Report
205-
working-directory: ${{ steps.get-function-names.outputs.DOCKER_COMPOSE_DIR }}
206-
if: steps.grype.outcome == 'success'
207-
env:
208-
PROJECT_NAME: ${{ inputs.project_name }}
209-
run: |
210-
function=${{ matrix.function }}
211-
212-
SCAN_RESULTS=$(cat grype-report.txt)
213-
214-
# ANSI color codes
215-
RED="\033[0;31m"
216-
RESET="\033[0m"
217-
218-
# Define your log file
219-
VULNERABILITIES_SUMMARY_LOGFILE="${PROJECT_NAME}-${function}-vulnerabilities-summary.txt"
220-
echo "VULNERABILITIES_SUMMARY_LOGFILE=$VULNERABILITIES_SUMMARY_LOGFILE" >> $GITHUB_ENV
221-
222-
# Clear existing log file (or create if it doesn't exist)
223-
> "$VULNERABILITIES_SUMMARY_LOGFILE"
224-
225-
for SEVERITY in CRITICAL HIGH MEDIUM; do
226-
{
227-
echo ""
228-
echo "${PROJECT_NAME}-${function}: vulnerabilities"
229-
echo -e "=== ${RED}${SEVERITY}${RESET} Vulnerabilities list ==="
230-
# If grep finds nothing, we print a fallback message
231-
echo "$SCAN_RESULTS" | grep -i "$SEVERITY" || echo "No $SEVERITY vulnerabilities found."
232-
} | tee -a "$VULNERABILITIES_SUMMARY_LOGFILE"
233-
done
234-
235-
- name: Run the SBOM and scan-vulnerabilities script
236-
working-directory: ${{ steps.get-function-names.outputs.DOCKER_COMPOSE_DIR }}
237-
env:
238-
PROJECT_NAME: ${{ inputs.project_name }}
239-
run: |
240-
function=${{ matrix.function }}
241-
242-
export SBOM_REPOSITORY_REPORT="sbom-${function}-repository-report"
243-
echo "SBOM_REPOSITORY_REPORT=$SBOM_REPOSITORY_REPORT" >> $GITHUB_ENV
244-
bash -x ${GITHUB_WORKSPACE}/templates/scripts/reports/create-sbom-report.sh
245-
246-
export VULNERABILITIES_REPOSITORY_REPORT="vulnerabilities-${function}-repository-report"
247-
echo "VULNERABILITIES_REPOSITORY_REPORT=$VULNERABILITIES_REPOSITORY_REPORT" >> $GITHUB_ENV
248-
249-
echo "Running the scan-vulnerabilities script in a look with 10 minutes timeout, with 3 retries..."
250-
retries=3
251-
delay=300 # 5 minutes
252-
count=0
253-
until [ $count -ge $retries ]
254-
do
255-
timeout 10m bash -x ${GITHUB_WORKSPACE}/templates/scripts/reports/scan-vulnerabilities.sh && break
256-
count=$((count+1))
257-
echo "Attempt $count/$retries failed, retrying after $delay seconds..."
258-
sleep $delay
259-
done
260-
261-
if [ $count -eq $retries ]; then
262-
echo "All attempts failed. Exiting with error."
263-
exit 1
177+
docker push "${repo_name}:${COMMIT_HASH_TAG}"
178+
if [ "${PR_NUM_TAG}" != 'pr' ]; then
179+
docker push "${repo_name}:${PR_NUM_TAG}"
264180
fi
181+
docker push "${repo_name}:${ENVIRONMENT_TAG}"
265182
266183
- name: Cleanup the docker images
267184
env:
@@ -276,66 +193,3 @@ jobs:
276193
docker rmi "${repo_name}:${PR_NUM_TAG}"
277194
docker rmi "${repo_name}:${ENVIRONMENT_TAG}"
278195
docker rmi ${PROJECT_NAME}-${function}:latest
279-
280-
- name: Compress SBOM report
281-
shell: bash
282-
run: |
283-
echo SBOM_REPOSITORY_REPORT: ${SBOM_REPOSITORY_REPORT}
284-
zip "${SBOM_REPOSITORY_REPORT}.json.zip" "${SBOM_REPOSITORY_REPORT}.json"
285-
286-
- name: Upload SBOM report as an artefact
287-
uses: actions/upload-artifact@v4
288-
with:
289-
name: ${{ env.SBOM_REPOSITORY_REPORT }}.json.zip
290-
path: ./${{ env.SBOM_REPOSITORY_REPORT }}.json.zip
291-
retention-days: 21
292-
293-
- name: Compress vulnerabilities report
294-
shell: bash
295-
run: |
296-
echo VULNERABILITIES_REPOSITORY_REPORT: ${VULNERABILITIES_REPOSITORY_REPORT}
297-
zip ${VULNERABILITIES_REPOSITORY_REPORT}.json.zip ${VULNERABILITIES_REPOSITORY_REPORT}.json
298-
299-
- name: Upload vulnerabilities report as an artefact
300-
uses: actions/upload-artifact@v4
301-
with:
302-
name: ${{ env.VULNERABILITIES_REPOSITORY_REPORT }}.json.zip
303-
path: ./${{ env.VULNERABILITIES_REPOSITORY_REPORT }}.json.zip
304-
retention-days: 21
305-
306-
- name: Upload vulnerabilities summary report as an artefact
307-
uses: actions/upload-artifact@v4
308-
with:
309-
name: ${{ env.VULNERABILITIES_SUMMARY_LOGFILE }}
310-
path: ./${{ env.VULNERABILITIES_SUMMARY_LOGFILE }}
311-
retention-days: 21
312-
313-
aggregate-json:
314-
runs-on: ubuntu-latest
315-
needs: build-and-push
316-
steps:
317-
- name: Download SBOM JSON artifacts
318-
uses: actions/download-artifact@v4
319-
with:
320-
path: ./downloaded-artifacts
321-
322-
- name: Combine sbom report JSON files
323-
run: |
324-
zip sbom-repository-report-${{ needs.build-and-push.outputs.PR_NUM_TAG }}.zip downloaded-artifacts/**/sbom*.json.zip
325-
326-
- name: Combine vulnerabilities report JSON files
327-
run: |
328-
zip vulnerabilities-repository-report-${{ needs.build-and-push.outputs.PR_NUM_TAG }}.zip downloaded-artifacts/**/vulnerabilities*.json.zip
329-
zip vulnerabilities-repository-report-${{ needs.build-and-push.outputs.PR_NUM_TAG }}.zip downloaded-artifacts/**/*vulnerabilities-summary*.txt
330-
331-
- name: Upload sbom zip file
332-
uses: actions/upload-artifact@v4
333-
with:
334-
name: aggregated-sbom-repository-report-${{ needs.build-and-push.outputs.PR_NUM_TAG }}.zip
335-
path: sbom-repository-report-${{ needs.build-and-push.outputs.PR_NUM_TAG }}.zip
336-
337-
- name: Upload repository zip file
338-
uses: actions/upload-artifact@v4
339-
with:
340-
name: aggregated-vulnerabilities-repository-report-${{ needs.build-and-push.outputs.PR_NUM_TAG }}.zip
341-
path: vulnerabilities-repository-report-${{ needs.build-and-push.outputs.PR_NUM_TAG }}.zip

0 commit comments

Comments
 (0)