-
Notifications
You must be signed in to change notification settings - Fork 0
230 lines (202 loc) · 7.61 KB
/
Copy pathdocker-build.yml
File metadata and controls
230 lines (202 loc) · 7.61 KB
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
name: Build Forensics Docker Images
on:
push:
branches: [main]
paths:
- 'packages/lambda-py/**'
- '.github/workflows/docker-build.yml'
pull_request:
branches: [main]
paths:
- 'packages/lambda-py/**'
- '.github/workflows/docker-build.yml'
workflow_dispatch:
inputs:
push_to_ecr:
description: 'Push images to ECR'
required: false
type: boolean
default: false
specific_tool:
description: 'Build specific tool (leave empty for all)'
required: false
type: choice
options:
- ''
- forensics-base
- yara
- clamav
- evidence-miner
- log2timeline
env:
AWS_REGION: us-east-1
PROJECT_NAME: snapshot-sleuth
jobs:
build-base:
name: Build forensics-base
runs-on: ubuntu-latest
outputs:
base-image: ${{ steps.build.outputs.image }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build base image
id: build
uses: docker/build-push-action@v5
with:
context: packages/lambda-py/forensics-base
file: packages/lambda-py/forensics-base/Dockerfile
push: false
load: true
tags: |
forensics-base:latest
${{ env.PROJECT_NAME }}/forensics-base:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Export base image for dependent builds
run: docker save forensics-base:latest | gzip > forensics-base.tar.gz
- name: Upload base image artifact
uses: actions/upload-artifact@v4
with:
name: forensics-base-image
path: forensics-base.tar.gz
retention-days: 1
- name: Scan base image for vulnerabilities
uses: aquasecurity/trivy-action@master
with:
image-ref: ${{ env.PROJECT_NAME }}/forensics-base:${{ github.sha }}
format: 'sarif'
output: 'trivy-base-results.sarif'
severity: 'CRITICAL,HIGH'
- name: Upload Trivy results
uses: github/codeql-action/upload-sarif@v3
if: always()
with:
sarif_file: 'trivy-base-results.sarif'
category: forensics-base
build-tools:
name: Build ${{ matrix.tool }}
runs-on: ubuntu-latest
needs: build-base
strategy:
fail-fast: false
matrix:
tool: [yara, clamav, evidence-miner, log2timeline]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download base image artifact
uses: actions/download-artifact@v4
with:
name: forensics-base-image
- name: Load base image
run: gunzip -c forensics-base.tar.gz | docker load
- name: Build tool image
run: |
docker build \
-t ${{ env.PROJECT_NAME }}/${{ matrix.tool }}:${{ github.sha }} \
-f packages/lambda-py/${{ matrix.tool }}-tool/Dockerfile \
packages/lambda-py/${{ matrix.tool }}-tool
- name: Scan tool image for vulnerabilities
uses: aquasecurity/trivy-action@master
with:
image-ref: ${{ env.PROJECT_NAME }}/${{ matrix.tool }}:${{ github.sha }}
format: 'sarif'
output: 'trivy-${{ matrix.tool }}-results.sarif'
severity: 'CRITICAL,HIGH'
- name: Upload Trivy results
uses: github/codeql-action/upload-sarif@v3
if: always()
with:
sarif_file: 'trivy-${{ matrix.tool }}-results.sarif'
category: ${{ matrix.tool }}
push-to-ecr:
name: Push to ECR
runs-on: ubuntu-latest
needs: [build-base, build-tools]
if: github.ref == 'refs/heads/main' && (github.event_name == 'push' || github.event.inputs.push_to_ecr == 'true')
environment: production
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push forensics-base
uses: docker/build-push-action@v5
with:
context: packages/lambda-py/forensics-base
file: packages/lambda-py/forensics-base/Dockerfile
push: true
tags: |
${{ steps.login-ecr.outputs.registry }}/${{ env.PROJECT_NAME }}/forensics-base:${{ github.sha }}
${{ steps.login-ecr.outputs.registry }}/${{ env.PROJECT_NAME }}/forensics-base:latest
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Build and push yara
uses: docker/build-push-action@v5
with:
context: packages/lambda-py/yara-tool
file: packages/lambda-py/yara-tool/Dockerfile
push: true
tags: |
${{ steps.login-ecr.outputs.registry }}/${{ env.PROJECT_NAME }}/yara:${{ github.sha }}
${{ steps.login-ecr.outputs.registry }}/${{ env.PROJECT_NAME }}/yara:latest
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Build and push clamav
uses: docker/build-push-action@v5
with:
context: packages/lambda-py/clamav-tool
file: packages/lambda-py/clamav-tool/Dockerfile
push: true
tags: |
${{ steps.login-ecr.outputs.registry }}/${{ env.PROJECT_NAME }}/clamav:${{ github.sha }}
${{ steps.login-ecr.outputs.registry }}/${{ env.PROJECT_NAME }}/clamav:latest
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Build and push evidence-miner
uses: docker/build-push-action@v5
with:
context: packages/lambda-py/evidence-miner-tool
file: packages/lambda-py/evidence-miner-tool/Dockerfile
push: true
tags: |
${{ steps.login-ecr.outputs.registry }}/${{ env.PROJECT_NAME }}/evidence-miner:${{ github.sha }}
${{ steps.login-ecr.outputs.registry }}/${{ env.PROJECT_NAME }}/evidence-miner:latest
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Build and push log2timeline
uses: docker/build-push-action@v5
with:
context: packages/lambda-py/log2timeline-tool
file: packages/lambda-py/log2timeline-tool/Dockerfile
push: true
tags: |
${{ steps.login-ecr.outputs.registry }}/${{ env.PROJECT_NAME }}/log2timeline:${{ github.sha }}
${{ steps.login-ecr.outputs.registry }}/${{ env.PROJECT_NAME }}/log2timeline:latest
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Summary
env:
COMMIT_SHA: ${{ github.sha }}
run: |
echo "## Docker Images Published" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Image | Tag |" >> $GITHUB_STEP_SUMMARY
echo "| ----- | --- |" >> $GITHUB_STEP_SUMMARY
echo "| forensics-base | ${COMMIT_SHA}, latest |" >> $GITHUB_STEP_SUMMARY
echo "| yara | ${COMMIT_SHA}, latest |" >> $GITHUB_STEP_SUMMARY
echo "| clamav | ${COMMIT_SHA}, latest |" >> $GITHUB_STEP_SUMMARY
echo "| evidence-miner | ${COMMIT_SHA}, latest |" >> $GITHUB_STEP_SUMMARY
echo "| log2timeline | ${COMMIT_SHA}, latest |" >> $GITHUB_STEP_SUMMARY