Skip to content

Commit

Permalink
Cleanup github action yaml file
Browse files Browse the repository at this point in the history
  • Loading branch information
ukanga committed Jun 24, 2024
1 parent 8f728de commit 8686d41
Showing 1 changed file with 50 additions and 20 deletions.
70 changes: 50 additions & 20 deletions .github/workflows/ecr-image-build-w-arm-runner.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
---
name: AWS ECR Build Image with ARM Runner

on:
on: # yamllint disable-line rule:truthy
release:
types:
- "released"
types:
- "released"
push:
branches:
- "main"
- "*-rc"
- "fix-arm-build"
tags:
- "v*"

Expand Down Expand Up @@ -68,7 +70,9 @@ jobs:

- name: Get the branch name
id: get-branch-name
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
if: >
github.event_name == 'push'
|| github.event_name == 'workflow_dispatch'
run: echo "version=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV

- name: (Ubuntu) Build and push
Expand All @@ -78,24 +82,32 @@ jobs:
context: .
file: ./docker/onadata-uwsgi/Dockerfile.ubuntu
platforms: ${{ matrix.platforms[0] }}
cache-from: type=registry,ref=${{ steps.login-ecr.outputs.registry }}/onaio/onadata:${{ env.version || github.ref_name }}
cache-from: >
type=registry,
ref=${{ steps.login-ecr.outputs.registry }}/onaio/onadata:${{ env.version || github.ref_name }}
cache-to: type=inline
ssh: |
default=/tmp/ssh-agent.sock
build-args: |
optional_packages=PyYAML django-redis ${{ secrets.ECR_OPTIONAL_PACKAGES }}
build-args: >
optional_packages=PyYAML
django-redis
${{ secrets.ECR_OPTIONAL_PACKAGES }}
push: true
labels: ${{ steps.meta.outputs.labels }}
provenance: false
outputs: type=image,name=${{ steps.login-ecr.outputs.registry }}/onaio/onadata,push-by-digest=true,name-canonical=true,push=true
-
name: Export digest
outputs: >
type=image,
name=${{ steps.login-ecr.outputs.registry }}/onaio/onadata,
push-by-digest=true,
name-canonical=true,
push=true
- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.docker-build-ubuntu.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
-
name: Upload digest
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ env.PLATFORM_PAIR }}
Expand Down Expand Up @@ -141,17 +153,24 @@ jobs:
- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ steps.login-ecr.outputs.registry }}/onaio/onadata@sha256:%s ' *)
docker buildx imagetools create \
$(jq -cr '.tags | map("-t " + .) | join(" ")' \
<<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ steps.login-ecr.outputs.registry }}\
/onaio/onadata@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ steps.login-ecr.outputs.registry }}/onaio/onadata:${{ steps.meta.outputs.version }}
docker buildx imagetools inspect \
${{ steps.login-ecr.outputs.registry }}/onaio/onadata\
:${{ steps.meta.outputs.version }}
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: ${{ steps.login-ecr.outputs.registry }}/onaio/onadata:${{ steps.meta.outputs.version }}
image-ref: |
${{ steps.login-ecr.outputs.registry }}\
/onaio/onadata:${{ steps.meta.outputs.version }}
format: 'sarif'
output: 'trivy-results.sarif'

Expand All @@ -164,13 +183,19 @@ jobs:
- name: Run Trivy vulnerability scanner for Slack
uses: aquasecurity/trivy-action@master
with:
image-ref: ${{ steps.login-ecr.outputs.registry }}/onaio/onadata:${{ steps.meta.outputs.version }}
image-ref: |
${{ steps.login-ecr.outputs.registry }}\
/onaio/onadata:${{ steps.meta.outputs.version }}
format: json
output: 'trivy-results.json'

- name: Create summary of trivy issues
run: |
summary=$(jq -r '.Results[] | select(.Vulnerabilities) | .Vulnerabilities | group_by(.Severity) | map({Severity: .[0].Severity, Count: length}) | .[] | [.Severity, .Count] | join(": ")' trivy-results.json | awk 'NR > 1 { printf(" | ") } {printf "%s",$0}')
summary=$(jq -r '.Results[] | select(.Vulnerabilities) \
| .Vulnerabilities | group_by(.Severity) \
| map({Severity: .[0].Severity, Count: length}) \
| .[] | [.Severity, .Count] | join(": ")' trivy-results.json \
| awk 'NR > 1 { printf(" | ") } {printf "%s",$0}')
if [ -z $summary ]
then
summary="0 Issues"
Expand All @@ -182,7 +207,8 @@ jobs:
with:
payload: |
{
"text": "Trivy scan results for ${{ steps.meta.outputs.version }}",
"text":
"Trivy scan results for ${{ steps.meta.outputs.version }}",
"blocks": [
{
"type": "section",
Expand All @@ -195,7 +221,11 @@ jobs:
"type": "section",
"text": {
"type": "mrkdwn",
"text": "View scan results: https://github.com/${{ github.repository }}/security/code-scanning?query=branch:${{ env.version || github.ref_name }}+is:open++"
"text": "View scan results: \
https://github.com/${{ github.repository }}\
/security/code-scanning\
?query=branch:${{ env.version || github.ref_name }}\
+is:open++"
}
}
]
Expand Down

0 comments on commit 8686d41

Please sign in to comment.