-
Notifications
You must be signed in to change notification settings - Fork 17
212 lines (189 loc) · 6.32 KB
/
build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
name: OasisUI Build
on:
push:
workflow_dispatch:
inputs:
docker_push:
description: 'Push the docker image to dockerhub and outout reference'
required: false
default: 'false'
cve_severity:
description: 'Severities of vulnerabilities to scanned for, fails build if any found'
required: false
default: 'CRITICAL,HIGH'
#app_image_repo:
# description: 'Docker hub image repository'
# required: false
# default: 'coreoasis/github-actions'
#app_image_tag:
# description: 'Docker tag for image'
# required: false
# default: ''
#proxy_image_repo:
# description: 'Docker hub image repository'
# required: false
# default: 'coreoasis/github-actions'
#proxy_image_tag:
# description: 'Docker tag for image'
# required: false
# default: ''
workflow_call:
inputs:
docker_push:
description: 'Push the docker image to dockerhub and outout reference'
required: false
default: 'false'
type: string
cve_severity:
description: 'Severities of vulnerabilities to scanned for, fails build if any found'
required: false
default: 'CRITICAL,HIGH'
type: string
app_image_repo:
description: 'Docker hub image repository'
required: false
default: 'coreoasis/github-actions'
type: string
app_image_tag:
description: 'Docker tag for image'
required: false
default: ''
type: string
proxy_image_repo:
description: 'Docker hub image repository'
required: false
default: 'coreoasis/github-actions'
type: string
proxy_image_tag:
description: 'Docker tag for image'
required: false
default: ''
type: string
outputs:
app_image:
description:
value: ${{ jobs.shiny_app.outputs.image }}
proxy_image:
description:
value: ${{ jobs.shiny_proxy.outputs.image }}
jobs:
shiny_app:
env:
IMAGE_TAG: 'oasisui_app-${{ github.sha }}'
IMAGE_REPO: 'coreoasis/github-actions'
DOCKERFILE: 'docker/Dockerfile.oasisui_app'
SEVERITY: 'CRITICAL,HIGH'
runs-on: ubuntu-latest
outputs:
image: ${{ steps.docker_push.outputs.image }}
steps:
- name: Set inputs
if: github.event_name != 'push'
run: |
echo "SEVERITY=${{ inputs.cve_severity }}" >> $GITHUB_ENV
[[ -z "${{ inputs.app_image_tag }}" ]] || echo "IMAGE_TAG=${{ inputs.app_image_tag }}" >> $GITHUB_ENV
[[ -z "${{ inputs.app_image_repo }}" ]] || echo "IMAGE_REPO=${{ inputs.app_image_repo }}" >> $GITHUB_ENV
- name: Github context
run: echo "$GITHUB_CONTEXT"
shell: bash
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
- uses: actions/checkout@v3
with:
ref: ${{ github.ref_name }}
- name: Docker Build
run: |
echo "Build from Branch ${{ github.ref_name }}"
docker build -f ${{ env.DOCKERFILE }} --pull --build-arg REF_BRANCH=${{ github.ref_name }} -t ${{ env.IMAGE_REPO }}:${{ env.IMAGE_TAG }} .
#Trivy Scan
- name: Trivy vulnerability scanner
if: env.SEVERITY != ''
uses: aquasecurity/trivy-action@master
with:
image-ref: ${{ env.IMAGE_REPO }}:${{ env.IMAGE_TAG }}
format: 'table'
scan-type: 'image'
exit-code: '1'
ignore-unfixed: true
severity: ${{ env.SEVERITY }}
scanners: 'vuln'
output: 'app_image.txt'
- name: Store CVE report
if: always()
uses: actions/upload-artifact@v3
with:
name: app_image_scan
path: ./app_image.txt
retention-days: 3
- name: Login to Docker Hub
if: inputs.docker_push == 'true'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Docker push
id: docker_push
if: inputs.docker_push == 'true'
run: |
docker push ${{ env.IMAGE_REPO }}:${{ env.IMAGE_TAG }}
echo "image=${{ env.IMAGE_REPO }}:${{ env.IMAGE_TAG }}" >> $GITHUB_OUTPUT
shiny_proxy:
runs-on: ubuntu-latest
env:
IMAGE_TAG: 'oasisui_proxy-${{ github.sha }}'
IMAGE_REPO: 'coreoasis/github-actions'
DOCKERFILE: 'docker/Dockerfile.oasisui_proxy'
SEVERITY: 'CRITICAL,HIGH'
outputs:
image: ${{ steps.docker_push.outputs.image }}
steps:
- name: Set inputs
if: github.event_name != 'push'
run: |
echo "SEVERITY=${{ inputs.cve_severity }}" >> $GITHUB_ENV
[[ -z "${{ inputs.proxy_image_tag }}" ]] || echo "IMAGE_TAG=${{ inputs.proxy_image_tag }}" >> $GITHUB_ENV
[[ -z "${{ inputs.proxy_image_repo }}" ]] || echo "IMAGE_REPO=${{ inputs.proxy_image_repo }}" >> $GITHUB_ENV
- name: Github context
run: echo "$GITHUB_CONTEXT"
shell: bash
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
- uses: actions/checkout@v3
with:
ref: ${{ github.ref_name }}
- name: Docker Build
run: |
docker build -f ${{ env.DOCKERFILE }} -t ${{ env.IMAGE_REPO }}:${{ env.IMAGE_TAG }} .
# NOTE: even the latest version of shiny proxy as CRITICAL CVE issues (warn but no fail)
- name: Trivy vulnerability scanner
if: env.SEVERITY != ''
continue-on-error: true
uses: aquasecurity/trivy-action@master
with:
image-ref: ${{ env.IMAGE_REPO }}:${{ env.IMAGE_TAG }}
format: 'table'
scan-type: 'image'
exit-code: '1'
ignore-unfixed: true
severity: ${{ env.SEVERITY }}
security-checks: 'vuln'
output: 'proxy_image.txt'
- name: Store CVE report
if: always()
uses: actions/upload-artifact@v3
with:
name: proxy_image_scan
path: ./proxy_image.txt
retention-days: 3
- name: Login to Docker Hub
if: inputs.docker_push == 'true'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Docker push
id: docker_push
if: inputs.docker_push == 'true'
run: |
docker push ${{ env.IMAGE_REPO }}:${{ env.IMAGE_TAG }}
echo "image=${{ env.IMAGE_REPO }}:${{ env.IMAGE_TAG }}" >> $GITHUB_OUTPUT