77 push :
88 branches :
99 - " main"
10+ - " *-rc"
1011 workflow_dispatch :
11- inputs :
12- versionTag :
13- description : " Version Tag "
14- required : true
15- default : ' '
12+ buildAlpine :
13+ description : Whether to build an Alpine based image
14+ required : false
15+ type : boolean
16+ default : false
1617
1718jobs :
1819 build :
19- runs-on : ubuntu-20.04
20+ runs-on : ubuntu-latest
2021 steps :
2122 - name : Checkout
22- uses : actions/checkout@v2
23+ uses : actions/checkout@v3
2324
2425 - name : Set up QEMU
25- uses : docker/setup-qemu-action@v1
26+ uses : docker/setup-qemu-action@v2
2627
2728 - name : Set up Docker Buildx
28- uses : docker/setup-buildx-action@v1
29-
30- - name : Get the version
31- id : get-version
32- if : github.event.inputs.versionTag == '' && github.event_name != 'push'
33- run : echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
34-
35- - name : Get the branch name
36- id : get-branch-name
37- if : github.event_name == 'push'
38- run : echo "version=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
29+ uses : docker/setup-buildx-action@v2
3930
4031 - name : Configure AWS credentials
4132 uses : aws-actions/configure-aws-credentials@v1
@@ -57,29 +48,62 @@ jobs:
5748 mkdir -p ~/.ssh
5849 ssh-keyscan github.com > ~/.ssh/known_hosts
5950
60- - name : Build and push
61- id : docker-build
51+ - name : Get the version
52+ id : get-version
53+ if : github.event_name != 'push'
54+ run : echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
55+
56+ - name : Get the branch name
57+ id : get-branch-name
58+ if : github.event_name == 'push' || github.event_name == 'workflow_dispatch'
59+ run : echo "version=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
60+
61+ - name : (Ubuntu) Build and push
62+ id : docker-build-ubuntu
6263 uses : docker/build-push-action@v2
6364 with :
64- context : ./docker/onadata-uwsgi
65- file : ./docker/onadata-uwsgi/Dockerfile
65+ context : .
66+ file : ./docker/onadata-uwsgi/Dockerfile.ubuntu
6667 platforms : linux/amd64
68+ cache-from : type=registry,ref=${{ steps.login-ecr.outputs.registry }}/onaio/onadata:${{ env.version }}
69+ cache-to : type=inline
6770 ssh : |
6871 default=/tmp/ssh-agent.sock
6972 build-args : |
70- release_version=${{ github.event.inputs.versionTag || env.version }}
7173 optional_packages=PyYAML django-redis ${{ secrets.ECR_OPTIONAL_PACKAGES }}
7274 push : true
7375 tags : |
74- ${{ steps.login-ecr.outputs.registry }}/onaio/onadata:${{ github.event.inputs.versionTag || env.version }}
76+ ${{ steps.login-ecr.outputs.registry }}/onaio/onadata:${{ env.version || github.ref_name }}
77+
78+ - name : (Alpine) Build and push
79+ id : docker-build-alpine
80+ uses : docker/build-push-action@v2
81+ if : github.event.inputs.buildAlpine
82+ with :
83+ context : .
84+ file : ./docker/onadata-uwsgi/Dockerfile.alpine
85+ platforms : linux/amd64
86+ cache-from : type=registry,ref=${{ steps.login-ecr.outputs.registry }}/onaio/onadata:${{ env.version }}
87+ cache-to : type=inline
88+ ssh : |
89+ default=/tmp/ssh-agent.sock
90+ build-args : |
91+ optional_packages=PyYAML django-redis ${{ secrets.ECR_OPTIONAL_PACKAGES }}
92+ push : true
93+ tags : |
94+ ${{ steps.login-ecr.outputs.registry }}/onaio/onadata:${{ env.version || github.ref_name }}-alpine
95+
96+ - name : (Ubuntu) Image digest
97+ run : echo ${{ steps.docker-build-ubuntu.outputs.digest }}
7598
76- - name : Image digest
77- run : echo ${{ steps.docker-build.outputs.digest }}
99+ - name : (Alpine) Image digest
100+ if : github.event.inputs.buildAlpine
101+ run : echo ${{ steps.docker-build-alpine.outputs.digest }}
78102
79103 - name : Run Trivy vulnerability scanner
80104 uses : aquasecurity/trivy-action@master
81105 with :
82- image-ref : ${{ steps.login-ecr.outputs.registry }}/onaio/onadata:${{ github.event.inputs.versionTag || env.version }}
106+ image-ref : ${{ steps.login-ecr.outputs.registry }}/onaio/onadata:${{ env.version || github.ref_name }}
83107 format : ' sarif'
84108 output : ' trivy-results.sarif'
85109
91115 - name : Run Trivy vulnerability scanner for Slack
92116 uses : aquasecurity/trivy-action@master
93117 with :
94- image-ref : ${{ steps.login-ecr.outputs.registry }}/onaio/onadata:${{ github.event.inputs.versionTag || env.version }}
118+ image-ref : ${{ steps.login-ecr.outputs.registry }}/onaio/onadata:${{ env.version || github.ref_name }}
95119 format : json
96120 output : ' trivy-results.json'
97121
@@ -105,11 +129,11 @@ jobs:
105129 echo "SUMMARY=$summary" >> $GITHUB_ENV
106130
107131 - name : Send Slack Notification
108- uses : slackapi/slack-github-action@v1.19 .0
132+ uses : slackapi/slack-github-action@v1.23 .0
109133 with :
110134 payload : |
111135 {
112- "text": "Trivy scan results for ${{ github.event.inputs.versionTag || steps.get- version-release.outputs.VERSION || github.base_ref }}",
136+ "text": "Trivy scan results for ${{ env. version || github.ref_name }}",
113137 "blocks": [
114138 {
115139 "type": "section",
@@ -122,7 +146,7 @@ jobs:
122146 "type": "section",
123147 "text": {
124148 "type": "mrkdwn",
125- "text": "View scan results: https://github.com/${{ github.repository }}/security. "
149+ "text": "View scan results: https://github.com/${{ github.repository }}/security/code-scanning?query=branch:${{ env.version || github.ref_name }}+is:open++ "
126150 }
127151 }
128152 ]
0 commit comments