-
Notifications
You must be signed in to change notification settings - Fork 19
216 lines (194 loc) · 6.86 KB
/
build-images.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
213
214
215
216
name: Platform Build
on:
workflow_dispatch:
inputs:
docker_push:
description: 'Push the docker image to dockerhub and outout reference'
required: true
default: false
type: boolean
ignore_unfixed:
description: 'Include unfixed vulnerabilities in scan [true,false]'
required: true
default: true
type: boolean
cve_severity:
description: 'Severities of vulnerabilities to scanned for [LOW, MEDIUM, HIGH, CRITICAL, SKIP]'
required: false
default: 'CRITICAL,HIGH'
oasislmf_branch:
description: 'If set, pip install oasislmf branch [git ref]'
required: false
type: string
ods_branch:
description: 'If set, pip install ods-tools branch [git ref]'
required: false
type: string
workflow_call:
inputs:
docker_push:
description: 'Push the docker image to dockerhub and outout reference'
required: true
default: 'false'
type: string
ignore_unfixed:
description: 'Include unfixed vulnerabilities in scan [true,false]'
required: true
default: 'true'
type: string
cve_severity:
description: 'Severities of vulnerabilities to scanned for, fails build if any found'
required: false
default: 'CRITICAL,HIGH'
type: string
oasislmf_branch:
description: 'If set, pip install oasislmf branch [git ref]'
required: false
type: string
ods_branch:
description: 'If set, pip install ods-tools branch [git ref]'
required: false
type: string
outputs:
server_image:
description:
value: 'coreoasis/github-actions:api_server-${{ github.sha }}'
worker_image:
description:
value: 'coreoasis/github-actions:model_worker-${{ github.sha }}'
worker_deb_image:
description:
value: 'coreoasis/github-actions:model_worker_deb-${{ github.sha }}'
worker_controller_image:
description:
value: 'coreoasis/github-actions:worker_controller-${{ github.sha }}'
env:
# inputs
DOCKER_PUSH: 'false'
IGNORE_UNFIXED: 'true'
SEVERITY: 'CRITICAL,HIGH'
IMAGE_REPO: 'coreoasis/github-actions'
TRIVY_SKIP_DB_UPDATE: true
TRIVY_SKIP_JAVA_DB_UPDATE: true
jobs:
build:
name: Docker build
runs-on: ubuntu-latest
strategy:
matrix:
image: [worker, worker_deb, server, worker_controller]
include:
- image: server
tag: 'api_server-${{ github.sha }}'
file: 'Dockerfile.api_server'
report: 'server-scan.sarif'
dive: 'server-layers.txt'
exit-code: '1'
context: '.'
- image: worker
tag: 'model_worker-${{ github.sha }}'
file: 'Dockerfile.model_worker'
report: 'worker-scan.sarif'
dive: 'worker-layers.txt'
exit-code: '1'
context: '.'
- image: worker_deb
tag: 'model_worker_deb-${{ github.sha }}'
file: 'Dockerfile.model_worker_debian'
report: 'worker-deb-scan.sarif'
dive: 'worker-deb-layers.txt'
exit-code: '0' # scan but don't fail
context: '.'
- image: worker_controller
tag: 'worker_controller-${{ github.sha }}'
file: 'kubernetes/worker-controller/Dockerfile'
report: 'worker-controller-scan.sarif'
dive: 'worker-controller-layers.txt'
exit-code: '1'
context: 'kubernetes/worker-controller/'
steps:
- name: Set inputs ${{ github.event_name }}
run: |
[[ -z "${{ inputs.cve_severity }}" ]] || echo "SEVERITY=${{ inputs.cve_severity }}" >> $GITHUB_ENV
[[ -z "${{ inputs.docker_push }}" ]] || echo "DOCKER_PUSH=${{ inputs.docker_push }}" >> $GITHUB_ENV
[[ -z "${{ inputs.ignore_unfixed }}" ]] || echo "IGNORE_UNFIXED=${{ inputs.ignore_unfixed }}" >> $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: Login to Docker Hub
if: env.DOCKER_PUSH == 'true'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Docker Build ${{ matrix.image }}
uses: docker/build-push-action@v3
with:
file: ${{ matrix.file }}
context: ${{ matrix.context }}
push: ${{ env.DOCKER_PUSH }}
tags: ${{ env.IMAGE_REPO }}:${{ matrix.tag }}
build-args: |
oasislmf_branch=${{ inputs.oasislmf_branch }}
ods_tools_branch=${{ inputs.ods_branch }}
- name: Test image efficiency
if: env.SEVERITY != 'SKIP'
run: |
./scripts/imagesize.sh ${{ env.IMAGE_REPO }}:${{ matrix.tag }} ${{ matrix.dive }}
env:
DIVE_HIGHEST_USER_WASTED: '0.20'
DIVE_HIGHEST_WASTED_BYTES: '50mb'
DIVE_LOWSET_EFFICIENCY: '0.95'
- name: Store image size report
if: success() || failure()
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.dive }}
path: ${{ matrix.dive }}
retention-days: 3
- name: Vulnerability scanner
if: env.SEVERITY != 'SKIP'
uses: aquasecurity/trivy-action@master
with:
image-ref: ${{ env.IMAGE_REPO }}:${{ matrix.tag }}
scan-type: 'image'
exit-code: ${{ matrix.exit-code }}
ignore-unfixed: ${{ env.IGNORE_UNFIXED }}
severity: ${{ env.SEVERITY }}
scanners: 'vuln'
- name: Create Report
if: ( success() || failure() ) && env.SEVERITY != 'SKIP' && matrix.exit-code == '1'
uses: aquasecurity/trivy-action@master
with:
image-ref: ${{ env.IMAGE_REPO }}:${{ matrix.tag }}
format: 'sarif'
output: ${{ matrix.report }}
scan-type: 'image'
exit-code: '0'
ignore-unfixed: ${{ env.IGNORE_UNFIXED }}
severity: ${{ env.SEVERITY }}
scanners: 'vuln'
- name: Upload scan results to Security tab
if: ( success() || failure() ) && env.SEVERITY != 'SKIP' && matrix.exit-code == '1'
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: ${{ matrix.report }}
- name: Store CVE report
if: success() || failure() && env.SEVERITY != 'SKIP'
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.report }}
path: ${{ matrix.report }}
retention-days: 3
- name: Docker summary
if: env.DOCKER_PUSH == 'true'
run: |
echo "#### Docker Image: " >> $GITHUB_STEP_SUMMARY
echo "* [${{ env.IMAGE_REPO }}:${{ matrix.tag }}](https://hub.docker.com/r/${{ env.IMAGE_REPO }}/tags?name=${{ matrix.tag }})" >> $GITHUB_STEP_SUMMARY