-
Notifications
You must be signed in to change notification settings - Fork 16
296 lines (273 loc) · 11.8 KB
/
docker-builds.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
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
name: Build and publish docker artifacts
on:
push:
branches: [ main ]
tags:
- '[0-9]+.[0-9]+.[0-9]+*'
pull_request:
types: [ opened, synchronize ]
paths:
- 'Earthfile'
- '.github/workflows/docker-builds.yaml'
- 'services/credential-server-ui/**'
- 'services/credential-server/**'
workflow_dispatch:
inputs:
images:
description: 'Select which earthly targets to build and push'
required: true
default: 'all'
type: choice
options:
- idw-keria
- idw-witness
- cred-issuance
- cred-issuance-ui
- cip45-sample-dapp
- all
env:
DOCKER_PUSH: true
jobs:
set-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: set-matrix
id: set-matrix
run: |
echo 'matrix={"platform":["linux/amd64","linux/arm64"]}' | tee -a "$GITHUB_ENV" | tee -a "$GITHUB_OUTPUT"
build-n-publish:
needs: set-matrix
permissions:
contents: read
packages: write
runs-on: ubuntu-latest
strategy:
matrix: ${{fromJson(needs.set-matrix.outputs.matrix)}}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup qemu for arm builds
uses: docker/setup-qemu-action@v3
if: matrix.platform == 'linux/arm64'
with:
platforms: arm64
- name: ⛮ cf-gha-baseline
uses: cardano-foundation/cf-gha-workflows/./actions/cf-gha-baseline@main
id: cf-gha-baseline
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PRIVATE_DOCKER_REGISTRY_URL: ${{ secrets.GITLAB_DOCKER_REGISTRY_URL }}
PRIVATE_DOCKER_REGISTRY_USER: Deploy-Token
PRIVATE_DOCKER_REGISTRY_PASS: ${{ secrets.GITLAB_PKG_REGISTRY_TOKEN }}
HUB_DOCKER_COM_USER: ${{ secrets.HUB_DOCKER_COM_USER }}
HUB_DOCKER_COM_PASS: ${{ secrets.HUB_DOCKER_COM_PASS }}
DOCKER_REGISTRIES: "${{ secrets.DOCKER_REGISTRIES }}"
- name: Set docker image targets based on path changes from last commit
id: metadata
run: |
set -x
if [ ${{github.event_name}} == "workflow_dispatch" ]
then
case "${{ github.event.inputs.images }}" in
idw-keria)
DOCKER_IMAGES_TARGETS="idw-keria"
;;
idw-witness)
DOCKER_IMAGES_TARGETS="idw-witness"
;;
cred-issuance)
DOCKER_IMAGES_TARGETS="cred-issuance"
;;
cred-issuance-ui)
DOCKER_IMAGES_TARGETS="cred-issuance-ui"
;;
cip45-sample-dapp)
DOCKER_IMAGES_TARGETS="cip45-sample-dapp"
;;
all)
DOCKER_IMAGES_TARGETS="idw-keria idw-witness cred-issuance cred-issuance-ui cip45-sample-dapp"
;;
*)
echo "Invalid option, exiting..."
exit 1
;;
esac
echo "DOCKER_IMAGES_TARGETS=${DOCKER_IMAGES_TARGETS}" | tee -a "$GITHUB_ENV" | tee -a "$GITHUB_OUTPUT"
echo "DOCKER_IMAGES_TARGETS_$(echo ${{ matrix.platform }} | sed 's|/|_|g')=${DOCKER_IMAGES_TARGETS}" | tee -a "$GITHUB_ENV" | tee -a "$GITHUB_OUTPUT"
fi
if [ ${{github.event_name}} == "pull_request" ]
then
git checkout ${BRANCH_NAME}
# set earthly docker image targets based on changed paths
set +e
DOCKER_IMAGES_TARGETS="$( \
( git log --pretty=format:'%h' -n 1 Earthfile | grep -q ${PR_GIT_SHORT_COMMIT} ) && \
( git log --patch -n1 Earthfile | grep -q "^[+-]ARG.*global.*KERIA_" ) && \
echo idw-keria
)"
DOCKER_IMAGES_TARGETS="$DOCKER_IMAGES_TARGETS $( \
( git log --pretty=format:'%h' -n 1 Earthfile | grep -q ${PR_GIT_SHORT_COMMIT} ) && \
( git log --patch -n1 Earthfile | grep -q "^[+-]ARG.*global.*KERI_DOCKER" ) && \
echo idw-witness
)"
DOCKER_IMAGES_TARGETS="$DOCKER_IMAGES_TARGETS $( \
( git log --pretty=format:'%h' -n 1 services/credential-server | grep -q ${PR_GIT_SHORT_COMMIT} ) && \
echo cred-issuance
)"
DOCKER_IMAGES_TARGETS="$DOCKER_IMAGES_TARGETS $( \
( git log --pretty=format:'%h' -n 1 services/credential-server-ui | grep -q ${PR_GIT_SHORT_COMMIT} ) && \
echo cred-issuance-ui
)"
DOCKER_IMAGES_TARGETS="$DOCKER_IMAGES_TARGETS $( \
( git log --pretty=format:'%h' -n 1 services/cip45-sample-dapp | grep -q ${PR_GIT_SHORT_COMMIT} ) && \
echo cip45-sample-dapp
)"
set -e
STRIPPED_DOCKER_IMAGES_TARGETS=$(echo $DOCKER_IMAGES_TARGETS | tr -s ' ' | sed -e 's|^ ||' -e 's| $||')
if [ ! -z "${STRIPPED_DOCKER_IMAGES_TARGETS}" ]; then
echo "DOCKER_IMAGES_TARGETS=${STRIPPED_DOCKER_IMAGES_TARGETS}" | tee -a "$GITHUB_ENV" | tee -a "$GITHUB_OUTPUT"
echo "DOCKER_IMAGES_TARGETS_$(echo ${{ matrix.platform }} | sed 's|/|_|g')=${STRIPPED_DOCKER_IMAGES_TARGETS}" | tee -a "$GITHUB_ENV" | tee -a "$GITHUB_OUTPUT"
fi
git checkout ${GIT_SHORT_COMMIT}
fi
- name: 🌍 earthly (docker build and push)
run: |
set -x
# For PR builds, we skip any earthly build if there are no changes on any known target-related file, for branch builds, we just build everything
if [ ${{github.event_name}} == "pull_request" ]
then
if [ ! -z "${DOCKER_IMAGES_TARGETS}" ]
then
earthly --platform=${{ matrix.platform }} \
+docker-publish \
--PUSH=true \
--TARGET_PLATFORM="${{ matrix.platform }}" \
--DOCKER_REGISTRIES="${{ secrets.DOCKER_REGISTRIES }}" \
--DOCKER_IMAGES_EXTRA_TAGS="${EARTHLY_DOCKER_IMAGES_EXTRA_TAGS}" \
--DOCKER_IMAGES_LABELS="${DOCKER_METADATA_OUTPUT_LABELS_COMMA_SEPARATED}" \
--DOCKER_IMAGES_TARGETS="${DOCKER_IMAGES_TARGETS}"
else
echo "[+] No changes on any known target-related file, skipping earthly build..."
fi
else
# if the workflow was triggered manually, we force the build
if [ ${{github.event_name}} == "workflow_dispatch" ]
then
FORCE_BUILD="--FORCE_BUILD=true"
DOCKER_IMAGES_TARGETS_ARG="--DOCKER_IMAGES_TARGETS=${DOCKER_IMAGES_TARGETS}"
earthly --platform=${{ matrix.platform }} \
+docker-publish \
${FORCE_BUILD} \
"${DOCKER_IMAGES_TARGETS_ARG}" \
--PUSH=true \
--TARGET_PLATFORM="${{ matrix.platform }}" \
--DOCKER_REGISTRIES="${{ secrets.DOCKER_REGISTRIES }}" \
--DOCKER_IMAGES_LABELS="${DOCKER_METADATA_OUTPUT_LABELS_COMMA_SEPARATED}" \
--DOCKER_IMAGES_EXTRA_TAGS="${EARTHLY_DOCKER_IMAGES_EXTRA_TAGS}"
else
earthly --platform=${{ matrix.platform }} \
+docker-publish \
${FORCE_BUILD} \
--PUSH=true \
--TARGET_PLATFORM="${{ matrix.platform }}" \
--DOCKER_REGISTRIES="${{ secrets.DOCKER_REGISTRIES }}" \
--DOCKER_IMAGES_LABELS="${DOCKER_METADATA_OUTPUT_LABELS_COMMA_SEPARATED}" \
--DOCKER_IMAGES_EXTRA_TAGS="${EARTHLY_DOCKER_IMAGES_EXTRA_TAGS}"
fi
fi
- uses: cloudposse/github-action-matrix-outputs-write@v1
id: out
with:
matrix-step-name: ${{ github.job }}
matrix-key: ${{ matrix.platform }}
outputs: |-
DOCKER_IMAGES_TARGETS: ${{ steps.metadata.outputs.DOCKER_IMAGES_TARGETS }}
merge-multi-platform-manifests:
needs:
- set-matrix
- build-n-publish
permissions:
contents: read
packages: write
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
# Manually doing this instead of using the cloudposse/read action as it seems there is some issue with it
- name: read-matrix-artifacts
id: matrix-artifacts
env:
MATRIX_STEP_NAME: build-n-publish
run: |
DOCKER_IMAGES_TARGETS=$(find . -name ${MATRIX_STEP_NAME} -maxdepth 2 -type f | head -n1 | xargs cat | jq -r '.[].DOCKER_IMAGES_TARGETS')
echo DOCKER_IMAGES_TARGETS=${DOCKER_IMAGES_TARGETS} | tee -a "$GITHUB_ENV" | tee -a "$GITHUB_OUTPUT"
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: ⛮ cf-gha-baseline
uses: cardano-foundation/cf-gha-workflows/./actions/cf-gha-baseline@main
id: cf-gha-baseline
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PRIVATE_DOCKER_REGISTRY_URL: ${{ secrets.GITLAB_DOCKER_REGISTRY_URL }}
PRIVATE_DOCKER_REGISTRY_USER: Deploy-Token
PRIVATE_DOCKER_REGISTRY_PASS: ${{ secrets.GITLAB_PKG_REGISTRY_TOKEN }}
HUB_DOCKER_COM_USER: ${{ secrets.HUB_DOCKER_COM_USER }}
HUB_DOCKER_COM_PASS: ${{ secrets.HUB_DOCKER_COM_PASS }}
DOCKER_REGISTRIES: "${{ secrets.DOCKER_REGISTRIES }}"
- name: Merge multi-platform manifests
run: |
PLATFORMS=$(echo '${{ needs.set-matrix.outputs.matrix }}' | jq -r '.platform[]' | xargs echo)
echo $PLATFORMS
echo $DOCKER_IMAGES_TARGETS
if [ "${DOCKER_IMAGES_TARGETS}" != "null" ]
then
DOCKER_IMAGES_TARGETS_ARG="--DOCKER_IMAGES_TARGETS=${DOCKER_IMAGES_TARGETS}"
earthly \
+docker-manifests-merge \
--DOCKER_IMAGES_TARGETS="${DOCKER_IMAGES_TARGETS}" \
--PUSH=true \
--PLATFORMS="${PLATFORMS}" \
--DOCKER_IMAGES_TARGETS="${DOCKER_IMAGES_TARGETS}" \
--DOCKER_REGISTRIES="${{ secrets.DOCKER_REGISTRIES }}" \
--DOCKER_IMAGES_EXTRA_TAGS="${EARTHLY_DOCKER_IMAGES_EXTRA_TAGS}"
else
if [ "${{github.event_name}}" == "pull_request" ]
then
echo "[+] No changes on any known target-related file, skipping earthly build..."
exit 0
fi
earthly \
+docker-manifests-merge \
--PUSH=true \
--PLATFORMS="${PLATFORMS}" \
--DOCKER_REGISTRIES="${{ secrets.DOCKER_REGISTRIES }}" \
--DOCKER_IMAGES_EXTRA_TAGS="${EARTHLY_DOCKER_IMAGES_EXTRA_TAGS}"
fi
dispatch-build-success-event:
runs-on: ubuntu-latest
needs:
- merge-multi-platform-manifests
steps:
- name: Checkout
uses: actions/checkout@v4
- name: ⛮ cf-gha-baseline
uses: cardano-foundation/cf-gha-workflows/./actions/cf-gha-baseline@main
id: cf-gha-baseline
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Dispatch successful build event to private repo
uses: cardano-foundation/cf-gha-workflows/./actions/cf-gha-dispatch-event@main
with:
EVENT_TYPE: "${{ github.event_name }}-${{ steps.cf-gha-baseline.outputs.TRIGGERING_REF }}-${{ steps.cf-gha-baseline.outputs.BRANCH_NAME }}"
GITHUB_TOKEN: ${{ secrets.PRIVATE_REPO_PAT }}
GITHUB_REPO: ${{ secrets.PRIVATE_REPO }}
TRIGGERING_EVENT: ${{ github.event_name }}
TRIGGERING_REF: ${{ steps.cf-gha-baseline.outputs.TRIGGERING_REF }}
TRIGGERING_BRANCH: ${{ steps.cf-gha-baseline.outputs.BRANCH_NAME }}
TRIGGERING_GHRUNID: ${{ github.run_id }}
GIT_SHORT_COMMIT: ${{ steps.cf-gha-baseline.outputs.GIT_SHORT_COMMIT }}