-
Notifications
You must be signed in to change notification settings - Fork 2
214 lines (200 loc) · 8.15 KB
/
docker_job.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
name: "[Job] Docker Build, Scan and Push to ECR"
on:
workflow_call:
inputs:
tag:
description: 'Tag for docker image'
required: true
type: string
checkout_tag:
description: 'Ref or tag to checkout'
default: ${{ github.ref }}
required: false
type: string
branch_name:
description: 'Branch name'
required: true
type: string
defaults:
run:
shell: bash
permissions:
id-token: write
contents: write
security-events: write
pull-requests: read
jobs:
docker_build_scan_push:
strategy:
fail-fast: false
matrix:
include:
- ecr_repository: modernising-lpa/app
name: app
path: ./docker/mlpa/Dockerfile
trivyignores: ./docker/mlpa/.trivyignore.yaml
platforms: linux/amd64
- ecr_repository: modernising-lpa/create-s3-batch-replication-job
name: create-s3-batch-replication-job
path: ./docker/create-s3-replication-job/Dockerfile
trivyignores: ./docker/create-s3-replication-job/.trivyignore.yaml
platforms: linux/amd64
- ecr_repository: modernising-lpa/event-received
name: event-received
path: ./docker/event-received/Dockerfile
trivyignores: ./docker/event-received/.trivyignore.yaml
platforms: linux/amd64
- ecr_repository: modernising-lpa/mock-pay
name: mock-pay
path: ./docker/mock-pay/Dockerfile
trivyignores: ./docker/mock-pay/.trivyignore.yaml
platforms: linux/amd64
- ecr_repository: modernising-lpa/schedule-runner
name: schedule-runner
path: ./docker/schedule-runner/Dockerfile
trivyignores: ./docker/schedule-runner/.trivyignore.yaml
platforms: linux/amd64
runs-on: ubuntu-latest
name: ${{ matrix.ecr_repository }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.checkout_tag }}
- uses: hadolint/[email protected]
id: hadolint
with:
dockerfile: ${{ matrix.path }}
no-fail: false
failure-threshold: warning
- name: Set up QEMU
uses: docker/[email protected]
- name: Set up Docker Buildx
uses: docker/[email protected]
id: buildx_setup
with:
version: v0.15.1
platforms: linux/amd64,linux/arm64
- uses: unfor19/install-aws-cli-action@v1
- name: Configure AWS Credentials
uses: aws-actions/[email protected]
with:
aws-region: eu-west-1
role-to-assume: arn:aws:iam::311462405659:role/modernising-lpa-github-actions-ecr-push
role-duration-seconds: 900
role-session-name: GithubActionsECRPushMLPAB
- name: ECR Login
id: login_ecr
uses: aws-actions/[email protected]
with:
mask-password: true
registries: 311462405659
- name: Trivy Dockerfile Configuration Scanner for ${{ matrix.ecr_repository }}
id: trivy_dockerfile_misconfiguration_scan
uses: aquasecurity/[email protected]
env:
TRIVY_DB_REPOSITORY: ${{ steps.login_ecr.outputs.registry }}/trivy-db-public-ecr/aquasecurity/trivy-db:2
TRIVY_JAVA_DB_REPOSITORY: ${{ steps.login_ecr.outputs.registry }}/trivy-db-public-ecr/aquasecurity/trivy-java-db:1
TRIVY_IGNOREFILE: ${{ matrix.trivyignores }}
with:
scan-type: fs
scan-ref: ${{ matrix.path }}
severity: 'HIGH,CRITICAL'
scanners: 'misconfig'
version: v0.56.2
exit-code: 1
- name: Build ${{ matrix.ecr_repository }} Image
uses: docker/[email protected]
with:
context: .
file: ${{ matrix.path }}
platforms: linux/amd64
push: false
load: true
cache-from: type=registry,ref=${{ steps.login_ecr.outputs.registry }}/${{ matrix.ecr_repository }}:cache-${{ inputs.branch_name }}
tags: |
${{ matrix.ecr_repository }}:${{ inputs.tag }}
build-args: |
TAG=${{inputs.tag}}
env:
SOURCE_DATE_EPOCH: 0
DOCKER_CONTENT_TRUST: 1
- name: Trivy Image Vulnerability Scanner for ${{ matrix.ecr_repository }}
id: trivy_scan
uses: aquasecurity/[email protected]
env:
TRIVY_DB_REPOSITORY: ${{ steps.login_ecr.outputs.registry }}/trivy-db-public-ecr/aquasecurity/trivy-db:2
TRIVY_JAVA_DB_REPOSITORY: ${{ steps.login_ecr.outputs.registry }}/trivy-db-public-ecr/aquasecurity/trivy-java-db:1
TRIVY_IGNOREFILE: ${{ matrix.trivyignores }}
with:
scan-type: 'image'
scanners: 'vuln'
image-ref: ${{ matrix.ecr_repository }}:${{ inputs.tag }}
severity: 'HIGH,CRITICAL'
format: 'sarif'
output: 'trivy-results.sarif'
exit-code: 0
- name: Upload Trivy scan results to GitHub Security tab for ${{ matrix.ecr_repository }}
id: trivy_upload_sarif
uses: github/codeql-action/[email protected]
if: always()
with:
sarif_file: 'trivy-results.sarif'
- name: Trivy Image SBOM Generator for ${{ matrix.ecr_repository }} and submit results to Dependency Graph
id: trivy_sbom
uses: aquasecurity/[email protected]
env:
TRIVY_DB_REPOSITORY: ${{ steps.login_ecr.outputs.registry }}/trivy-db-public-ecr/aquasecurity/trivy-db:2
TRIVY_JAVA_DB_REPOSITORY: ${{ steps.login_ecr.outputs.registry }}/trivy-db-public-ecr/aquasecurity/trivy-java-db:1
TRIVY_IGNOREFILE: ${{ matrix.trivyignores }}
with:
scan-type: 'image'
image-ref: ${{ matrix.ecr_repository }}:${{ inputs.tag }}
format: 'github'
output: '${{ matrix.name }}-${{ inputs.tag }}.sbom.json'
github-pat: ${{ secrets.GITHUB_TOKEN }}
- name: Upload trivy report as a Github artifact
uses: actions/upload-artifact@v4
with:
name: trivy-sbom-report-${{ matrix.name }}-${{ inputs.tag }}
path: '${{ github.workspace }}/${{ matrix.name }}-${{ inputs.tag }}.sbom.json'
retention-days: 20 # 90 is the default
- name: Push ${{ matrix.ecr_repository }} Image to ECR for PR
if: ${{ github.workflow != 'Path To Live' }}
uses: docker/[email protected]
with:
context: .
file: ${{ matrix.path }}
builder: ${{ steps.buildx_setup.outputs.name }}
push: true
platforms: ${{ matrix.platforms }}
cache-to: type=registry,mode=max,image-manifest=true,oci-mediatypes=true,type=registry,ref=${{ steps.login_ecr.outputs.registry }}/${{ matrix.ecr_repository }}:cache-${{ inputs.branch_name }}
tags: |
${{ steps.login_ecr.outputs.registry }}/${{ matrix.ecr_repository }}:${{ inputs.tag }}
build-args: |
TAG=${{inputs.tag}}
sbom: false
provenance: false
env:
SOURCE_DATE_EPOCH: 0
DOCKER_CONTENT_TRUST: 1
- name: Push ${{ matrix.ecr_repository }} Image to ECR for Path to Live
if: ${{ github.workflow == 'Path To Live' }}
uses: docker/[email protected]
with:
context: .
file: ${{ matrix.path }}
builder: ${{ steps.buildx_setup.outputs.name }}
push: true
platforms: ${{ matrix.platforms }}
cache-to: type=registry,mode=max,image-manifest=true,oci-mediatypes=true,type=registry,ref=${{ steps.login_ecr.outputs.registry }}/${{ matrix.ecr_repository }}:cache-${{ inputs.branch_name }}
tags: |
${{ steps.login_ecr.outputs.registry }}/${{ matrix.ecr_repository }}:${{ inputs.tag }}
${{ steps.login_ecr.outputs.registry }}/${{ matrix.ecr_repository }}:main-${{ inputs.tag }}
${{ steps.login_ecr.outputs.registry }}/${{ matrix.ecr_repository }}:latest
build-args: |
TAG=${{inputs.tag}}
sbom: false
provenance: false
env:
SOURCE_DATE_EPOCH: 0
DOCKER_CONTENT_TRUST: 1