forked from FraunhoferISST/DataspaceConnector
-
Notifications
You must be signed in to change notification settings - Fork 29
271 lines (256 loc) · 9.93 KB
/
build-image.yaml
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
name: docker-image
on:
push:
branches: [ main ]
tags: 'v*'
release:
types: [published]
jobs:
productive:
environment: registry
timeout-minutes: 30
runs-on: ubuntu-latest
steps:
-
name: Checkout Repo
uses: actions/checkout@v3
-
name: Build registry path
id: get_repo
run: echo ::set-output name=IMAGE::"ghcr.io/international-data-spaces-association/dataspace-connector"
-
name: Find tag
id: get_tag
run: |
echo ${GITHUB_REF#refs/tags/}
echo ::set-output name=TAG::${GITHUB_REF#refs/tags/}
if: startsWith(github.ref, 'refs/tags')
-
name: Find branch name
id: get_branch
run: |
# to lowercase
TMP=$(git rev-parse --abbrev-ref HEAD)
TMP=$(echo "$TMP" | tr '[:upper:]' '[:lower:]')
echo $TMP
echo ::set-output name=BRANCH::$TMP
-
name: Install SBoM generator
run: |
SYFT_EXPECTED_DIGEST='74a9becd5ccb4c02de99050a632e7bfc72176d5e4e844093b1e2c5bedfb45888'
curl -sSfL https://github.com/anchore/syft/releases/download/v0.29.0/syft_0.29.0_linux_amd64.tar.gz -o syft.tar.gz
SYFT_RESULT_DIGEST=$(sha256sum syft.tar.gz | cut -d' ' -f1);
if [[ $SYFT_RESULT_DIGEST != "${SYFT_EXPECTED_DIGEST}" ]]; then exit 1; fi
mkdir -p syft-install/
tar -zxf syft.tar.gz -C syft-install/
mv syft-install/syft /usr/local/bin/
rm -rf syft.tar.gz syft-install/
-
name: Install SBoM pusher
run: |
ORAS_EXPECTED_DIGEST='660a4ecd87414d1f29610b2ed4630482f1f0d104431576d37e59752c27de37ed'
curl -sSfL https://github.com/oras-project/oras/releases/download/v0.12.0/oras_0.12.0_linux_amd64.tar.gz -o oras.tar.gz
ORAS_RESULT_DIGEST=$(sha256sum oras.tar.gz | cut -d' ' -f1);
if [[ $ORAS_RESULT_DIGEST != "${ORAS_EXPECTED_DIGEST}" ]]; then exit 1; fi
mkdir -p oras-install/
tar -zxf oras.tar.gz -C oras-install/
mv oras-install/oras /usr/local/bin/
rm -rf oras.tar.gz oras-install/
- name: Install signing
run: |
COSIGN_EXPECTED_DIGEST='9604a5eb171748113f92a67495556007dde6f45804f0b38d3e55c3bc7e151774'
curl -sSfL https://github.com/sigstore/cosign/releases/download/v1.3.0/cosign-linux-amd64 -o cosign
COSIGN_RESULT_DIGEST=$(sha256sum cosign | cut -d' ' -f1);
if [[ $COSIGN_RESULT_DIGEST != "${COSIGN_EXPECTED_DIGEST}" ]]; then exit 1; fi
chmod +x cosign
mv cosign /usr/local/bin/cosign
-
name: Login to registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Build image
run: |
docker build . -t $IMAGE:$BRANCH
BOM="dataspace-connector-sbom.json"
syft "${IMAGE}:${BRANCH}" -o spdx-json > "${BOM}"
env:
IMAGE: ${{ steps.get_repo.outputs.IMAGE }}
BRANCH: ${{ steps.get_branch.outputs.BRANCH }}
DOCKER_BUILDKIT: 1
-
name: Push tagged image
run: |
echo $IMAGE
echo $BRANCH
echo $TAG
TMP=$TAG
BOM="dataspace-connector-sbom.json"
if [[ $TMP == v* ]]
then
# Its a version tag
TMP=${TAG:1:${#TAG}}
echo "Found a version tag"
docker tag $IMAGE:$BRANCH $IMAGE:latest
docker push $IMAGE:latest
oras push "${IMAGE}:latest-sbom" "${BOM}:application/json"
echo "${COSIGN_KEY}" > /tmp/cosign.key
cosign sign --key /tmp/cosign.key "${IMAGE}:latest"
cosign sign --key /tmp/cosign.key "${IMAGE}:latest-sbom"
rm /tmp/cosign.key
fi
# Has tag
docker tag $IMAGE:$BRANCH $IMAGE:$TMP
docker push $IMAGE:$TMP
oras push "${IMAGE}:${TMP}-sbom" "${BOM}:application/json"
echo "${COSIGN_KEY}" > /tmp/cosign.key
cosign sign --key /tmp/cosign.key "${IMAGE}:${TMP}"
cosign sign --key /tmp/cosign.key "${IMAGE}:${TMP}-sbom"
rm /tmp/cosign.key
if: startsWith(github.ref, 'refs/tags')
env:
IMAGE: ${{ steps.get_repo.outputs.IMAGE }}
BRANCH: ${{ steps.get_branch.outputs.BRANCH }}
TAG: ${{ steps.get_tag.outputs.TAG }}
COSIGN_KEY: ${{secrets.COSIGN_KEY}}
COSIGN_PASSWORD: ${{secrets.COSIGN_PASSWORD}}
-
name: Push branch image
run: |
docker push $IMAGE:$BRANCH
BOM="dataspace-connector-sbom.json"
oras push "${IMAGE}:${BRANCH}-sbom" "${BOM}:application/json"
echo "${COSIGN_KEY}" > /tmp/cosign.key
cosign sign --key /tmp/cosign.key "${IMAGE}:${BRANCH}"
cosign sign --key /tmp/cosign.key "${IMAGE}:${BRANCH}-sbom"
rm /tmp/cosign.key
if: startsWith(github.ref, 'refs/heads')
env:
IMAGE: ${{ steps.get_repo.outputs.IMAGE }}
BRANCH: ${{ steps.get_branch.outputs.BRANCH }}
COSIGN_KEY: ${{secrets.COSIGN_KEY}}
COSIGN_PASSWORD: ${{secrets.COSIGN_PASSWORD}}
debug:
environment: registry
timeout-minutes: 30
runs-on: ubuntu-latest
steps:
-
name: Checkout Repo
uses: actions/checkout@v3
-
name: Build registry path
id: get_repo
run: echo ::set-output name=IMAGE::"ghcr.io/international-data-spaces-association/dataspace-connector"
-
name: Find tag
id: get_tag
run: |
echo ${GITHUB_REF#refs/tags/}
echo ::set-output name=TAG::${GITHUB_REF#refs/tags/}
if: startsWith(github.ref, 'refs/tags')
-
name: Find branch name
id: get_branch
run: |
# to lowercase
TMP=$(git rev-parse --abbrev-ref HEAD)
TMP=$(echo "$TMP" | tr '[:upper:]' '[:lower:]')
echo $TMP
echo ::set-output name=BRANCH::$TMP
-
name: Install SBoM generator
run: |
SYFT_EXPECTED_DIGEST='74a9becd5ccb4c02de99050a632e7bfc72176d5e4e844093b1e2c5bedfb45888'
curl -sSfL https://github.com/anchore/syft/releases/download/v0.29.0/syft_0.29.0_linux_amd64.tar.gz -o syft.tar.gz
SYFT_RESULT_DIGEST=$(sha256sum syft.tar.gz | cut -d' ' -f1);
if [[ $SYFT_RESULT_DIGEST != "${SYFT_EXPECTED_DIGEST}" ]]; then exit 1; fi
mkdir -p syft-install/
tar -zxf syft.tar.gz -C syft-install/
mv syft-install/syft /usr/local/bin/
rm -rf syft.tar.gz syft-install/
-
name: Install SBoM pusher
run: |
ORAS_EXPECTED_DIGEST='660a4ecd87414d1f29610b2ed4630482f1f0d104431576d37e59752c27de37ed'
curl -sSfL https://github.com/oras-project/oras/releases/download/v0.12.0/oras_0.12.0_linux_amd64.tar.gz -o oras.tar.gz
ORAS_RESULT_DIGEST=$(sha256sum oras.tar.gz | cut -d' ' -f1);
if [[ $ORAS_RESULT_DIGEST != "${ORAS_EXPECTED_DIGEST}" ]]; then exit 1; fi
mkdir -p oras-install/
tar -zxf oras.tar.gz -C oras-install/
mv oras-install/oras /usr/local/bin/
rm -rf oras.tar.gz oras-install/
- name: Install signing
run: |
COSIGN_EXPECTED_DIGEST='9604a5eb171748113f92a67495556007dde6f45804f0b38d3e55c3bc7e151774'
curl -sSfL https://github.com/sigstore/cosign/releases/download/v1.3.0/cosign-linux-amd64 -o cosign
COSIGN_RESULT_DIGEST=$(sha256sum cosign | cut -d' ' -f1);
if [[ $COSIGN_RESULT_DIGEST != "${COSIGN_EXPECTED_DIGEST}" ]]; then exit 1; fi
chmod +x cosign
mv cosign /usr/local/bin/cosign
-
name: Login to registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Build image
run: |
docker build . -f scripts/ci/docker/Debug.dockerfile -t $IMAGE:$BRANCH
BOM="dataspace-connector-sbom.json"
syft "${IMAGE}:${BRANCH}" -o spdx-json > "${BOM}"
env:
IMAGE: ${{ steps.get_repo.outputs.IMAGE }}
BRANCH: ${{ steps.get_branch.outputs.BRANCH }}
DOCKER_BUILDKIT: 1
-
name: Push tagged image
run: |
echo $IMAGE
echo $BRANCH
echo $TAG
TMP=$TAG
BOM="dataspace-connector-sbom.json"
if [[ $TMP == v* ]]
then
# Its a version tag
TMP=${TAG:1:${#TAG}}
echo "Found a version tag"
fi
# Has tag
docker tag $IMAGE:$BRANCH $IMAGE:$TMP-debug
docker push $IMAGE:$TMP-debug
oras push "${IMAGE}:${TMP}-debug-sbom" "${BOM}:application/json"
echo "${COSIGN_KEY}" > /tmp/cosign.key
cosign sign --key /tmp/cosign.key "${IMAGE}:${TMP}-debug"
cosign sign --key /tmp/cosign.key "${IMAGE}:${TMP}-debug-sbom"
rm /tmp/cosign.key
if: startsWith(github.ref, 'refs/tags')
env:
IMAGE: ${{ steps.get_repo.outputs.IMAGE }}
BRANCH: ${{ steps.get_branch.outputs.BRANCH }}
TAG: ${{ steps.get_tag.outputs.TAG }}
COSIGN_KEY: ${{secrets.COSIGN_KEY}}
COSIGN_PASSWORD: ${{secrets.COSIGN_PASSWORD}}
-
name: Push branch image
run: |
docker tag $IMAGE:$BRANCH $IMAGE:$BRANCH-debug
docker push $IMAGE:$BRANCH-debug
BOM="dataspace-connector-sbom.json"
oras push "${IMAGE}:${BRANCH}-debug-sbom" "${BOM}:application/json"
echo "${COSIGN_KEY}" > /tmp/cosign.key
cosign sign --key /tmp/cosign.key "${IMAGE}:${BRANCH}-debug"
cosign sign --key /tmp/cosign.key "${IMAGE}:${BRANCH}-debug-sbom"
rm /tmp/cosign.key
if: startsWith(github.ref, 'refs/heads')
env:
IMAGE: ${{ steps.get_repo.outputs.IMAGE }}
BRANCH: ${{ steps.get_branch.outputs.BRANCH }}
COSIGN_KEY: ${{secrets.COSIGN_KEY}}
COSIGN_PASSWORD: ${{secrets.COSIGN_PASSWORD}}