-
Notifications
You must be signed in to change notification settings - Fork 2
221 lines (218 loc) · 8.54 KB
/
test-reusable-docker-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
name: test reusable-docker-build
env:
VERSION_CRANE: v0.16.1
on:
pull_request: {}
workflow_dispatch: {}
# LIMITATIONS
# - this workflow cannot run in parallel between PRs; retries are required (for now).
# this is due to non-unique image names. having unique image names tends to cause needing to retry more times due to some sort of internal container artifact "registration" behaviour
# TESTCASES
# - t0: basic
# - t1: use-test
# - t2: artifact-pull
# - t3: multi-arch
# - t4: push-to-ecr # TODO need test ECR
# - t5: pull-from-s3 # TODO need test bucket
# - t6: auth-with-geonetci
# - t7: use-setup
# - t8: use-tags
# - t9: no-push
permissions:
packages: write
contents: read
id-token: write
jobs:
t0-basic:
uses: ./.github/workflows/reusable-docker-build.yml
with:
context: ./testdata/t0-basic
dockerfile: ./testdata/t0-basic/Dockerfile
imageName: testimage-t0-basic
platforms: linux/amd64
push: ${{ github.ref != 'refs/heads/main' }}
t0-basic-check:
needs: t0-basic
runs-on: ubuntu-latest
steps:
- uses: GeoNet/setup-crane@00c9e93efa4e1138c9a7a5c594acd6c75a2fbf0c # main
with:
version: ${{ env.VERSION_CRANE }}
- name: check for image
env:
IMAGE: ${{ needs.t0-basic.outputs.image }}
GH_TOKEN: ${{ github.token }}
run: |
crane manifest $IMAGE
crane manifest $IMAGE | jq -r '.manifests[] | select(.annotations."vnd.docker.reference.type" != "attestation-manifest") | .platform.architecture' | xargs | grep -E '^amd64$'
gh api -X DELETE /orgs/GeoNet/packages/container/actions%2Ftestimage-t0-basic || true
t1-use-test:
uses: ./.github/workflows/reusable-docker-build.yml
with:
context: ./testdata/t1-use-test
dockerfile: ./testdata/t1-use-test/Dockerfile
imageName: testimage-t1-use-test
platforms: linux/amd64
push: ${{ github.ref != 'refs/heads/main' }}
test: |
date
crane append ghcr.io/geonet/actions/t1-use-test-${{ github.sha }}-success --new_tag --new_layer <(tar cvf $(mktemp))
t1-use-test-check:
needs: t1-use-test
runs-on: ubuntu-latest
steps:
- uses: GeoNet/setup-crane@00c9e93efa4e1138c9a7a5c594acd6c75a2fbf0c # main
with:
version: ${{ env.VERSION_CRANE }}
- name: check for image
env:
IMAGE: ${{ needs.t1-use-test.outputs.image }}
GH_TOKEN: ${{ github.token }}
run: |
crane manifest $IMAGE
crane manifest $IMAGE | jq -r '.manifests[] | select(.annotations."vnd.docker.reference.type" != "attestation-manifest") | .platform.architecture' | xargs | grep -E '^amd64'
gh api -X DELETE /orgs/GeoNet/packages/container/actions%2Ftestimage-t1-use-test || true
gh api -X DELETE /orgs/GeoNet/packages/container/actions%2Ftestimage-t1-use-test-${{ github.sha }}-success || true
t2-artifact-pull-prepare:
runs-on: ubuntu-latest
steps:
- name: make file
run: |
mkdir -p ./testdata/t2-artifact-pull/something/
date > ./testdata/t2-artifact-pull/something/something.txt
- uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
with:
name: t2-artifact-pull-something
path: ./testdata/t2-artifact-pull/something
retention-days: 1
t2-artifact-pull:
needs: t2-artifact-pull-prepare
uses: ./.github/workflows/reusable-docker-build.yml
with:
context: ./testdata/t2-artifact-pull
dockerfile: ./testdata/t2-artifact-pull/Dockerfile
imageName: testimage-t2-artifact-pull
platforms: linux/amd64
push: false
artifact-name: t2-artifact-pull-something
artifact-path: ./testdata/t2-artifact-pull/something/
test: |
find ./testdata/t2-artifact-pull/something/ | grep -qE 'something.txt$'
t2-artifact-pull-cleanup:
needs: t2-artifact-pull
runs-on: ubuntu-latest
steps:
- name: check for image
env:
GH_TOKEN: ${{ github.token }}
run: |
gh api /repos/GeoNet/Actions/actions/artifacts --jq '.artifacts[] | select(.name=="t2-artifact-pull-something") | .id' | xargs -I{} -n 1 gh api -X DELETE /repos/GeoNet/ac-tools/actions/artifacts/{} || true
t3-multi-arch:
uses: ./.github/workflows/reusable-docker-build.yml
with:
context: ./testdata/t3-multi-arch
dockerfile: ./testdata/t3-multi-arch/Dockerfile
imageName: testimage-t3-multi-arch
platforms: 'linux/amd64,linux/arm64'
push: ${{ github.ref != 'refs/heads/main' }}
t3-multi-arch-check:
needs: t3-multi-arch
runs-on: ubuntu-latest
steps:
- uses: GeoNet/setup-crane@00c9e93efa4e1138c9a7a5c594acd6c75a2fbf0c # main
with:
version: ${{ env.VERSION_CRANE }}
- name: check for image
env:
IMAGE: ${{ needs.t3-multi-arch.outputs.image }}
GH_TOKEN: ${{ github.token }}
run: |
crane manifest $IMAGE
crane manifest $IMAGE | jq -r '.manifests[] | select(.annotations."vnd.docker.reference.type" != "attestation-manifest") | .platform.architecture' | xargs | grep -E '^amd64 arm64$'
gh api -X DELETE /orgs/GeoNet/packages/container/actions%2Ftestimage-t3-multi-arch
t6-auth-with-geonetci:
uses: ./.github/workflows/reusable-docker-build.yml
secrets: inherit
with:
context: ./testdata/t6-auth-with-geonetci
dockerfile: ./testdata/t6-auth-with-geonetci/Dockerfile
imageName: testimage-t6-auth-with-geonetci
platforms: linux/amd64
push: ${{ github.ref != 'refs/heads/main' }}
registryGhcrUsernameOverride: geonetci
t6-auth-with-geonetci-check:
needs: t6-auth-with-geonetci
runs-on: ubuntu-latest
steps:
- uses: GeoNet/setup-crane@00c9e93efa4e1138c9a7a5c594acd6c75a2fbf0c # main
with:
version: ${{ env.VERSION_CRANE }}
- name: check for image
env:
IMAGE: ${{ needs.t6-auth-with-geonetci.outputs.image }}
GH_TOKEN: ${{ github.token }}
run: |
crane manifest $IMAGE
crane manifest $IMAGE | jq -r '.manifests[] | select(.annotations."vnd.docker.reference.type" != "attestation-manifest") | .platform.architecture' | xargs | grep -E '^amd64$'
gh api -X DELETE /orgs/GeoNet/packages/container/actions%2Ftestimage-t6-auth-with-geonetci || true
t7-use-setup:
uses: ./.github/workflows/reusable-docker-build.yml
with:
push: false
context: ./testdata/t7-use-setup
dockerfile: ./testdata/t7-use-setup/Dockerfile
imageName: testimage-t7-use-setup
platforms: linux/amd64
setup: |
echo 'test-complete' > ./test-file.txt
test: |
< ./test-file.txt grep -qE '^test-complete$'
t8-use-tags:
uses: ./.github/workflows/reusable-docker-build.yml
with:
context: ./testdata/t8-use-tags
dockerfile: ./testdata/t8-use-tags/Dockerfile
imageName: testimage-t8-use-tags
platforms: linux/amd64
push: ${{ github.ref != 'refs/heads/main' }}
tags: a,b
t8-use-tags-check:
needs: t8-use-tags
runs-on: ubuntu-latest
steps:
- uses: GeoNet/setup-crane@00c9e93efa4e1138c9a7a5c594acd6c75a2fbf0c # main
with:
version: ${{ env.VERSION_CRANE }}
- name: check for image
env:
IMAGE: ${{ needs.t8-use-tags.outputs.image }}
GH_TOKEN: ${{ github.token }}
run: |
crane manifest $IMAGE
crane ls ghcr.io/geonet/actions/testimage-t8-use-tags | grep -vE '^sha256-' | sort | xargs | grep -E '^a b$'
crane manifest $IMAGE | jq -r '.manifests[] | select(.annotations."vnd.docker.reference.type" != "attestation-manifest") | .platform.architecture' | xargs | grep -E '^amd64$'
gh api -X DELETE /orgs/GeoNet/packages/container/actions%2Ftestimage-t8-use-tags || true
t9-no-push:
uses: ./.github/workflows/reusable-docker-build.yml
with:
context: ./testdata/t9-no-push
dockerfile: ./testdata/t9-no-push/Dockerfile
imageName: testimage-t9-no-push
platforms: linux/amd64
push: false
t9-no-push-check:
needs: t9-no-push
runs-on: ubuntu-latest
steps:
- uses: GeoNet/setup-crane@00c9e93efa4e1138c9a7a5c594acd6c75a2fbf0c # main
with:
version: ${{ env.VERSION_CRANE }}
- name: check for image
env:
IMAGE: ${{ needs.t9-no-push.outputs.image }}
GH_TOKEN: ${{ github.token }}
run: |
! crane manifest $IMAGE || \
(
gh api -X DELETE /orgs/GeoNet/packages/container/actions%2Ftestimage-t9-no-push || true
)