-
-
Notifications
You must be signed in to change notification settings - Fork 39
446 lines (424 loc) · 17.1 KB
/
Copy pathbuild_and_test.yml
File metadata and controls
446 lines (424 loc) · 17.1 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
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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
# Copyright (C) 2022-2023 C-PAC Developers
# This file is part of C-PAC.
# C-PAC is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 3 of the License, or (at your
# option) any later version.
# C-PAC is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
# License for more details.
# You should have received a copy of the GNU Lesser General Public
# License along with C-PAC. If not, see <https://www.gnu.org/licenses/>.
name: Build and test C-PAC
on:
workflow_call:
inputs:
phase_one:
description: 'first phase of staging images to include (OS & data)'
type: string
required: true
rebuild_phase_one:
description: 'first phase of staging images to rebuild (OS & data)'
type: string
required: true
phase_two:
description: 'second phase of staging images to include (dependencies)'
type: string
required: true
rebuild_phase_two:
description: 'second phase of staging images to rebuild (dependencies)'
type: string
required: true
phase_three:
description: 'third phase of staging images to include (base images)'
type: string
required: true
rebuild_phase_three:
description: 'third phase of staging images to rebuild (base images)'
type: string
required: true
jobs:
Ubuntu:
name: Build C-PAC stage images for Ubuntu & FSL data
strategy:
matrix:
Dockerfile: ${{ fromJSON(inputs.phase_one) }}
env:
REBUILD: ${{ inputs.rebuild_phase_one }}
runs-on: ubuntu-latest
steps:
- name: Check out C-PAC
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set tag & see if it exists
continue-on-error: true
id: docker_tag
if: always()
run: |
TAG=$(sed 's/\./:/' <(echo ${{ matrix.Dockerfile }}))
DOCKER_TAG=$(echo "ghcr.io/${{ github.repository }}/$TAG" | tr '[:upper:]' '[:lower:]')
echo DOCKER_TAG=$DOCKER_TAG >> $GITHUB_ENV
docker buildx imagetools inspect $DOCKER_TAG >/dev/null || echo "not_yet_exists=1" >> $GITHUB_OUTPUT
cat $GITHUB_OUTPUT
- name: Clear up some space on runner
if: contains(fromJSON(env.REBUILD), matrix.Dockerfile) || steps.docker_tag.outputs.not_yet_exists == 1
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
- name: Set up Docker Buildx
if: contains(fromJSON(env.REBUILD), matrix.Dockerfile) || steps.docker_tag.outputs.not_yet_exists == 1
uses: docker/setup-buildx-action@v2.2.1
- name: Log in to GitHub Container Registry
if: contains(fromJSON(env.REBUILD), matrix.Dockerfile) || steps.docker_tag.outputs.not_yet_exists == 1
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
if: contains(fromJSON(env.REBUILD), matrix.Dockerfile) || steps.docker_tag.outputs.not_yet_exists == 1
uses: docker/build-push-action@v4.0.0
with:
file: .github/Dockerfiles/${{ matrix.Dockerfile }}.Dockerfile
push: true
tags: |
${{ env.DOCKER_TAG }}
cache-from: type=gha
cache-to: type=gha,mode=min,compression=zstd
stages:
name: Build C-PAC Docker stage images for dependencies
needs: Ubuntu
strategy:
matrix:
Dockerfile: ${{ fromJSON(inputs.phase_two) }}
env:
REBUILD: ${{ inputs.rebuild_phase_two }}
runs-on: ubuntu-latest
steps:
- name: Check out C-PAC
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set tag & see if it exists
continue-on-error: true
id: docker_tag
run: |
TAG=$(sed 's/\./:/' <(echo ${{ matrix.Dockerfile }}))
DOCKER_TAG=$(echo "ghcr.io/${{ github.repository }}/$TAG" | tr '[:upper:]' '[:lower:]')
echo DOCKER_TAG=$DOCKER_TAG >> $GITHUB_ENV
docker buildx imagetools inspect $DOCKER_TAG >/dev/null || echo "not_yet_exists=1" >> $GITHUB_OUTPUT
cat $GITHUB_OUTPUT
if: always()
- name: Prep Dockerfiles for forked repository
if: contains(fromJSON(env.REBUILD), matrix.Dockerfile) || steps.docker_tag.outputs.not_yet_exists == 1
run: |
.github/scripts/local_ghcr .github/Dockerfiles/${{ matrix.Dockerfile }}.Dockerfile ${{ github.repository_owner }} $DOCKER_TAG
cat .github/Dockerfiles/${{ matrix.Dockerfile }}.Dockerfile
- name: See Dockerfile
if: contains(fromJSON(env.REBUILD), matrix.Dockerfile) || steps.docker_tag.outputs.not_yet_exists == 1
run: cat .github/Dockerfiles/${{ matrix.Dockerfile }}.Dockerfile
- name: Clear up some space on runner
if: contains(fromJSON(env.REBUILD), matrix.Dockerfile) || steps.docker_tag.outputs.not_yet_exists == 1
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
- name: Set up Docker Buildx
if: contains(fromJSON(env.REBUILD), matrix.Dockerfile) || steps.docker_tag.outputs.not_yet_exists == 1
uses: docker/setup-buildx-action@v2.2.1
- name: Log in to GitHub Container Registry
if: contains(fromJSON(env.REBUILD), matrix.Dockerfile) || steps.docker_tag.outputs.not_yet_exists == 1
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
if: contains(fromJSON(env.REBUILD), matrix.Dockerfile) || steps.docker_tag.outputs.not_yet_exists == 1
uses: docker/build-push-action@v4.0.0
with:
context: .
file: .github/Dockerfiles/${{ matrix.Dockerfile }}.Dockerfile
push: true
tags: |
${{ env.DOCKER_TAG }}
cache-from: type=gha
cache-to: type=gha,mode=min,compression=zstd
build-base:
name: Build C-PAC base stage images
needs: stages
runs-on: ubuntu-latest
env:
BUILD_CACHE: /home/runner/.docker/buildkit
REBUILD: ${{ inputs.rebuild_phase_three }}
strategy:
matrix:
variant: ${{ fromJSON(inputs.phase_three) }}
steps:
- name: Maximize build space
uses: easimon/maximize-build-space@v6
with:
remove-dotnet: 'true'
remove-android: 'true'
remove-haskell: 'true'
overprovision-lvm: 'true'
- name: Check out C-PAC
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Prep source files
run: |
sed -i -e 's/^/\.github\/Dockerfiles\//' .github/stage_requirements/${{ matrix.variant }}.txt
echo 'dev/docker_data/required_afni_pkgs.txt' >> .github/stage_requirements/${{ matrix.variant }}.txt
echo '.github/workflows/build_and_test.yml' >> .github/stage_requirements/${{ matrix.variant }}.txt
echo '.github/stage_requirements/${{ matrix.variant }}.txt' >> .github/stage_requirements/${{ matrix.variant }}.txt
- name: Set tag & see if it exists
continue-on-error: true
run: |
TAG="stage-base:${{ matrix.variant }}-$(cat version)"
DOCKER_TAG=$(echo "ghcr.io/${{ github.repository }}/$TAG" | tr '[:upper:]' '[:lower:]')
echo DOCKER_TAG=$DOCKER_TAG >> $GITHUB_ENV
docker buildx imagetools inspect $DOCKER_TAG >/dev/null || echo "not_yet_exists=1" >> $GITHUB_OUTPUT
cat $GITHUB_OUTPUT
id: docker_tag
if: always()
- name: Prep Dockerfiles for forked repository
if: contains(fromJSON(env.REBUILD), matrix.variant) || steps.docker_tag.outputs.not_yet_exists == 1
run: |
.github/scripts/local_ghcr .github/Dockerfiles/base-${{ matrix.variant }}.Dockerfile ${{ github.repository_owner }} $DOCKER_TAG
cat .github/Dockerfiles/base-${{ matrix.variant }}.Dockerfile
- name: See Dockerfile
if: contains(fromJSON(env.REBUILD), matrix.variant) || steps.docker_tag.outputs.not_yet_exists == 1
run: cat .github/Dockerfiles/base-${{ matrix.variant }}.Dockerfile
- name: Clear up some space on runner
if: contains(fromJSON(env.REBUILD), matrix.variant) || steps.docker_tag.outputs.not_yet_exists == 1
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
- name: Set up Docker Buildx
if: contains(fromJSON(env.REBUILD), matrix.variant) || steps.docker_tag.outputs.not_yet_exists == 1
uses: docker/setup-buildx-action@v2.2.1
- name: Log in to GitHub Container Registry
if: contains(fromJSON(env.REBUILD), matrix.variant) || steps.docker_tag.outputs.not_yet_exists == 1
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push base image
if: contains(fromJSON(env.REBUILD), matrix.variant) || steps.docker_tag.outputs.not_yet_exists == 1
uses: docker/build-push-action@v4.0.0
with:
context: .
file: .github/Dockerfiles/base-${{ matrix.variant }}.Dockerfile
provenance: false
sbom: false
push: true
tags: |
${{ env.DOCKER_TAG }}
build-base-standard:
name: Build C-PAC standard base stage image
needs: build-base
runs-on: ubuntu-latest
env:
BUILD_CACHE: /home/runner/.docker/buildkit
REBUILD: ${{ inputs.rebuild_phase_three }}
steps:
- name: Maximize build space
uses: easimon/maximize-build-space@v6
with:
remove-dotnet: 'true'
remove-android: 'true'
remove-haskell: 'true'
overprovision-lvm: 'true'
- name: Check out C-PAC
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Prep source files
run: |
sed -i -e 's/^/\.github\/Dockerfiles\//' .github/stage_requirements/standard.txt
echo 'dev/docker_data/required_afni_pkgs.txt' >> .github/stage_requirements/standard.txt
echo '.github/workflows/build_and_test.yml' >> .github/stage_requirements/standard.txt
echo '.github/stage_requirements/standard.txt' >> .github/stage_requirements/standard.txt
- name: Set tag & see if it exists
continue-on-error: true
run: |
TAG="stage-base:standard-$(cat version)"
DOCKER_TAG=$(echo "ghcr.io/${{ github.repository }}/$TAG" | tr '[:upper:]' '[:lower:]')
echo DOCKER_TAG=$DOCKER_TAG >> $GITHUB_ENV
docker buildx imagetools inspect $DOCKER_TAG >/dev/null || echo "not_yet_exists=1" >> $GITHUB_OUTPUT
cat $GITHUB_OUTPUT
id: docker_tag
if: always()
- name: Prep Dockerfiles for forked repository
if: contains(fromJSON(env.REBUILD), 'standard') || steps.docker_tag.outputs.not_yet_exists == 1
run: |
.github/scripts/local_ghcr .github/Dockerfiles/base-standard.Dockerfile ${{ github.repository_owner }} $DOCKER_TAG
cat .github/Dockerfiles/base-standard.Dockerfile
- name: See Dockerfile
if: contains(fromJSON(env.REBUILD), 'standard') || steps.docker_tag.outputs.not_yet_exists == 1
run: cat .github/Dockerfiles/base-standard.Dockerfile
- name: Clear up some space on runner
if: contains(fromJSON(env.REBUILD), 'standard') || steps.docker_tag.outputs.not_yet_exists == 1
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
- name: Set up Docker Buildx
if: contains(fromJSON(env.REBUILD), 'standard') || steps.docker_tag.outputs.not_yet_exists == 1
uses: docker/setup-buildx-action@v2.2.1
- name: Log in to GitHub Container Registry
if: contains(fromJSON(env.REBUILD), 'standard') || steps.docker_tag.outputs.not_yet_exists == 1
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push base image
if: contains(fromJSON(env.REBUILD), 'standard') || steps.docker_tag.outputs.not_yet_exists == 1
uses: docker/build-push-action@v4.0.0
with:
context: .
file: .github/Dockerfiles/base-standard.Dockerfile
provenance: false
sbom: false
push: true
tags: |
${{ env.DOCKER_TAG }}
C-PAC:
needs: build-base-standard
uses: ./.github/workflows/build_C-PAC.yml
with:
variant: ''
C-PAC-lite:
needs: build-base
uses: ./.github/workflows/build_C-PAC.yml
with:
variant: lite
# C-PAC-ABCD-HCP:
# needs: build-base
# uses: ./.github/workflows/build_C-PAC.yml
# with:
# variant: ABCD-HCP
# C-PAC-fMRIPrep-LTS:
# needs: build-base
# uses: ./.github/workflows/build_C-PAC.yml
# with:
# variant: fMRIPrep-LTS
smoke-tests-participant:
name: Run participant-level smoke tests
needs:
- C-PAC
- C-PAC-lite
# - C-PAC-ABCD-HCP
# - C-PAC-fMRIPrep-LTS
if: github.ref_name == 'develop' || github.ref_name == 'main'
uses: ./.github/workflows/smoke_test_participant.yml
regtest-lite:
name: Run lite regression test
needs:
- C-PAC
secrets: inherit
if: contains(github.event.head_commit.message, '[run reg-suite]')
uses: ./.github/workflows/regression_test_lite.yml
regtest-full:
name: Run full regression test
needs:
- smoke-tests-participant
uses: ./.github/workflows/regression_test_full.yml
Circle_tests:
name: Run tests on CircleCI
needs:
- C-PAC
- C-PAC-lite
# - C-PAC-ABCD-HCP
# - C-PAC-fMRIPrep-LTS
if: github.ref_type == 'branch'
runs-on: ubuntu-latest
steps:
- name: Check out C-PAC
uses: actions/checkout@v3
with:
fetch-depth: 2
- name: Trigger CircleCI tests
run: |
echo "ref: $GITHUB_REF_NAME"
TEXT="Triggered pipeline at "
U1="https://circleci.com/api/v2/project/gh/${GITHUB_REPOSITORY}/pipeline"
export DATA="{\"branch\":\"$GITHUB_REF_NAME\", \"parameters\": {\"run_tests\": true}}"
echo "URL ${U1}"
echo "data ${DATA}"
RESPONSE=$(curl \
--request POST \
--url "${U1}" \
-u ${{ secrets.CIRCLE_API_USER_TOKEN }}: \
--header 'content-type: application/json' \
--data "${DATA}")
echo "$RESPONSE"
PIPELINE_NUMBER=$(echo $RESPONSE |
jq '.number')
if [[ $PIPELINE_NUMBER == 'null' ]]
then
echo "Failed to trigger CircleCI tests"
exit 126
fi
PIPELINE_ID=$(curl \
--request GET \
--url "https://circleci.com/api/v2/project/gh/${GITHUB_REPOSITORY}/pipeline/${PIPELINE_NUMBER}" \
-u "${{ secrets.CIRCLE_API_USER_TOKEN }}:" |
jq '.id' |
tr -d '"')
# wait for workflow to get an ID
sleep 20
WORKFLOW_ID=$(curl \
--request GET \
--url "https://circleci.com/api/v2/pipeline/${PIPELINE_ID}/workflow" \
-u "${{ secrets.CIRCLE_API_USER_TOKEN }}:" |
jq '.items[0].id' |
tr -d '"')
echo ${TEXT}https://app.circleci.com/pipelines/github/${GITHUB_REPOSITORY}/${PIPELINE_NUMBER}/workflows/${WORKFLOW_ID}
Deploy_to_Docker_Hub:
name: Deploy to Docker Hub
needs:
- C-PAC
if: github.ref_type == 'tag'
uses: ./.github/workflows/deploy_to_Docker_Hub.yml
with:
variant: ''
secrets: inherit
Deploy_to_Docker_Hub-lite:
name: Deploy 'lite' to Docker Hub
needs:
- C-PAC-lite
if: github.ref_type == 'tag'
uses: ./.github/workflows/deploy_to_Docker_Hub.yml
with:
variant: 'lite'
secrets: inherit
# Deploy_to_Docker_Hub-ABCD-HCP:
# name: Deploy 'ABCD-HCP' to Docker Hub
# needs:
# - C-PAC-ABCD-HCP
# if: github.ref_type == 'tag'
# uses: ./.github/workflows/deploy_to_Docker_Hub.yml
# with:
# variant: 'ABCD-HCP'
# secrets: inherit
# Deploy_to_Docker_Hub-fMRIPrep-LTS:
# name: Deploy 'fMRIPrep-LTS' to Docker Hub
# needs:
# - C-PAC-fMRIPrep-LTS
# if: github.ref_type == 'tag'
# uses: ./.github/workflows/deploy_to_Docker_Hub.yml
# with:
# variant: 'fMRIPrep-LTS'
# secrets: inherit