-
Notifications
You must be signed in to change notification settings - Fork 80
334 lines (315 loc) · 11.4 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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
name: "[Blocking] Build"
on:
push:
branches:
- main
- release-*
tags:
- v*
paths-ignore:
- "**.md"
- "website/**"
- "docs/**"
- "demo/**"
pull_request:
branches:
- main
- release-*
paths-ignore:
- "**.md"
- "website/**"
- "docs/**"
- "demo/**"
workflow_dispatch:
env:
TRIVY_VERSION: 0.59.1
BUILDKIT_VERSION: 0.19.0
TRIVY_DISABLE_VEX_NOTICE: "true"
permissions:
contents: read
jobs:
unit-test:
name: Unit Test
runs-on: ubuntu-latest
timeout-minutes: 5
permissions: read-all
steps:
- name: Harden Runner
uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.3.1
with:
egress-policy: audit
- name: Check out code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # v5.4.0
with:
go-version: "1.24"
check-latest: true
- name: Add containerd-snapshotter to docker daemon
run: |
echo '{"features": { "containerd-snapshotter": true }}' | sudo tee /etc/docker/daemon.json
sudo systemctl restart docker
- name: Unit test
shell: bash
env:
CODECOV_OPTS: "-coverprofile=coverage.txt -covermode=atomic"
run: make test
- name: Upload coverage to Codecov
uses: codecov/codecov-action@ad3126e916f78f00edff4ed0317cf185271ccc2d # v5.4.2
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
build:
name: Build
runs-on: ${{ matrix.os }}
timeout-minutes: 5
permissions:
packages: write
contents: read
strategy:
matrix:
os: [ubuntu-latest]
steps:
- name: Harden Runner
uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.3.1
with:
egress-policy: audit
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # v5.4.0
with:
go-version: "1.24"
check-latest: true
- name: Build copa
shell: bash
run: |
make build
make archive
- name: Upload copa to build artifacts
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: copa_edge_linux_amd64.tar.gz
path: dist/linux_amd64/release/copa_edge_linux_amd64.tar.gz
- name: Load test cases for patch testing
id: load-test-envs-matrix
shell: bash
run: echo "buildkitenvs=$(.github/workflows/scripts/buildkit-env-matrix.sh)" | tee -a "${GITHUB_OUTPUT}"
outputs:
buildkitenvs: ${{ steps.load-test-envs-matrix.outputs.buildkitenvs }}
test-patch-trivy:
needs: build
name: Test patch with trivy ${{ matrix.buildkit_mode }}
runs-on: ubuntu-latest
timeout-minutes: 30
permissions: read-all
strategy:
fail-fast: false
matrix:
buildkit_mode: ${{fromJson(needs.build.outputs.buildkitenvs)}}
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
with:
egress-policy: audit
- name: Download copa from build artifacts
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1
with:
name: copa_edge_linux_amd64.tar.gz
- run: docker system prune -a -f --volumes
- name: Check out code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # v5.4.0
with:
go-version: "1.24"
check-latest: true
- name: Install required tools
shell: bash
run: .github/workflows/scripts/download-tooling.sh
- name: Download copa from build artifacts
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1
with:
name: copa_edge_linux_amd64.tar.gz
- name: Extract copa
shell: bash
run: |
tar xzf copa_edge_linux_amd64.tar.gz
./copa --version
- name: Set up QEMU
uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0
- name: Run functional test
shell: bash
run: |
set -eu -o pipefail
. .github/workflows/scripts/buildkitenvs/${{ matrix.buildkit_mode}}
go test -v ./integration --addr="${COPA_BUILDKIT_ADDR}" --copa="$(pwd)/copa" -timeout 0 --report-file
test-patch-no-report:
needs: build
name: Test patch no report ${{ matrix.buildkit_mode }}
runs-on: ubuntu-latest
timeout-minutes: 30
permissions: read-all
strategy:
fail-fast: false
matrix:
buildkit_mode: ${{fromJson(needs.build.outputs.buildkitenvs)}}
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
with:
egress-policy: audit
- name: Download copa from build artifacts
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1
with:
name: copa_edge_linux_amd64.tar.gz
- run: docker system prune -a -f --volumes
- name: Check out code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # v5.4.0
with:
go-version: "1.24"
check-latest: true
- name: Install required tools
shell: bash
run: .github/workflows/scripts/download-tooling.sh
- name: Download copa from build artifacts
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1
with:
name: copa_edge_linux_amd64.tar.gz
- name: Extract copa
shell: bash
run: |
tar xzf copa_edge_linux_amd64.tar.gz
./copa --version
- name: Set up QEMU
uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0
- name: Run functional test
shell: bash
run: |
set -eu -o pipefail
. .github/workflows/scripts/buildkitenvs/${{ matrix.buildkit_mode}}
echo "COPA_BUILDKIT_ADDR=${COPA_BUILDKIT_ADDR}" >> "$GITHUB_ENV"
go test -v ./integration --addr="${COPA_BUILDKIT_ADDR}" --copa="$(pwd)/copa" -timeout 0
- name: Test RPM validation - noreplace files
shell: bash
run: |
set -eux -o pipefail
if [[ -n "${COPA_BUILDKIT_ADDR}" && "${COPA_BUILDKIT_ADDR}" == docker://* ]]; then
export DOCKER_HOST="${COPA_BUILDKIT_ADDR#docker://}"
fi
docker create --name test ghcr.io/project-copacetic/copacetic/test/openssl:test-patched /bin/sh
tmp="$(mktemp)"
docker cp test:/etc/pki/tls/openssl.cnf "${tmp}"
if ! grep -q foo "${tmp}"; then
echo "Error: openssl.cnf content replaced" >&2
rm "${tmp}"
docker rm -f test
exit 1
fi
rm "${tmp}"
docker rm -f test
- name: Test RPM validation - symlink
shell: bash
run: |
set -eux -o pipefail
_cleanup() {
docker rm -f "$DOCKER_CUSTOM_UNIX_ID"
sudo rm -rf "$SOCK_DIR"
}
if [[ -n "${COPA_BUILDKIT_ADDR}" && "${COPA_BUILDKIT_ADDR}" == docker://* ]]; then
export DOCKER_HOST="${COPA_BUILDKIT_ADDR#docker://}"
trap '_cleanup' EXIT
fi
docker create --name test ghcr.io/project-copacetic/copacetic/test/openssl:test-patched /bin/sh
tmp="$(mktemp)"
symlink_path="/sbin"
docker cp test:"$symlink_path" "${tmp}_symlink"
if [ ! -L "${tmp}_symlink" ]; then
echo "Error: The path $symlink_path is not a symlink."
rm "${tmp}" "${tmp}_symlink"
docker rm -f test
exit 1
fi
rm "${tmp}" "${tmp}_symlink"
docker rm -f test
test-plugin:
needs: build
name: Test plugin
runs-on: ubuntu-latest
timeout-minutes: 5
permissions: read-all
steps:
- name: Harden Runner
uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.3.1
with:
egress-policy: audit
- name: Check out code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # v5.4.0
with:
go-version: "1.24"
check-latest: true
- name: Install scanner-plugin-template
shell: bash
run: |
go install github.com/project-copacetic/scanner-plugin-template@latest
mv $(go env GOPATH)/bin/scanner-plugin-template $(go env GOPATH)/bin/copa-fake
mv $(go env GOPATH)/bin/copa-fake /usr/local/bin
- name: Install required tools
shell: bash
run: .github/workflows/scripts/download-tooling.sh
- name: Download copa from build artifacts
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1
with:
name: copa_edge_linux_amd64.tar.gz
- name: Extract copa
shell: bash
run: |
tar xzf copa_edge_linux_amd64.tar.gz
./copa --version
- name: Set up QEMU
uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0
- name: Run e2e tests
shell: bash
run: |
set -eu -o pipefail
. .github/workflows/scripts/buildkitenvs/direct/tcp
go test -v ./test/e2e/plugin --addr="${COPA_BUILDKIT_ADDR}" --copa="$(pwd)/copa" --scanner fake -timeout 0
test-push:
needs: build
name: Test push
runs-on: ubuntu-latest
timeout-minutes: 5
permissions: read-all
steps:
- name: Check out code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # v5.4.0
with:
go-version: "1.24"
check-latest: true
- name: Add containerd-snapshotter to docker daemon
run: |
echo '{"features": { "containerd-snapshotter": true }}' | sudo tee /etc/docker/daemon.json
sudo systemctl restart docker
- name: Set up buildx
uses: docker/setup-buildx-action@v3
with:
install: true
- name: Install oras CLI
uses: oras-project/setup-oras@5c0b487ce3fe0ce3ab0d034e63669e426e294e4d # v1.2.2
- name: Install required tools
shell: bash
run: .github/workflows/scripts/download-tooling.sh
- name: Download copa from build artifacts
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1
with:
name: copa_edge_linux_amd64.tar.gz
- name: Extract copa
shell: bash
run: |
tar xzf copa_edge_linux_amd64.tar.gz
./copa --version
- name: Set up QEMU
uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0
- name: Run e2e tests
shell: bash
run: |
set -eu -o pipefail
go test -v ./test/e2e/push --addr="docker://" --copa="$(pwd)/copa"