-
Notifications
You must be signed in to change notification settings - Fork 34
383 lines (335 loc) · 13.3 KB
/
build-and-test.yml
File metadata and controls
383 lines (335 loc) · 13.3 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
name: Build and Test
# This workflow is responsible for building Pelican's container images and
# running the test suite. Much of its length and complexity is a consequence
# of trying to keep build times short by taking advantage of caching.
#
# The intended behavior is that all container images are always built.
# However:
#
# - For pull requests: We never push images to a registry. In fact,
# we can't, because the credentials aren't available.
#
# - Pushes to main: We push only pelican-test and pelican-dev.
#
# - Pushes to semvar tags: We push pelican-test and all the "server" images.
on:
pull_request:
push:
branches:
- main
tags:
# Run only on release tags for v7.0.0 and up.
- v[7-9]\.[0-9]+\.[0-9]+
- v[7-9]\.[0-9]+\.[0-9]+-rc\.[0-9]+
- v[1-9][0-9]+\.[0-9]+\.[0-9]+
- v[1-9][0-9]+\.[0-9]+\.[0-9]+-rc\.[0-9]+
repository_dispatch:
types:
- dispatch-build
workflow_dispatch:
jobs:
set-build-parameters:
outputs:
#
# While some of these outputs are intended to be treated as booleans,
# they are actually strings ('true', 'false'). In any conditionals, test
# their values using "== 'true'" or "== 'false'".
#
platforms: ${{ steps.parameters.outputs.PLATFORMS }}
push-dev: ${{ steps.parameters.outputs.PUSH_DEV }}
push-server: ${{ steps.parameters.outputs.PUSH_SERVER }}
runs-on: ubuntu-latest
steps:
- name: Determine build parameters
id: parameters
run: |
PUSH_DEV=${{ github.repository == 'PelicanPlatform/pelican' && github.ref == 'refs/heads/main' }}
PUSH_SERVER=${{ github.repository == 'PelicanPlatform/pelican' && startsWith(github.ref, 'refs/tags/') }}
if ${PUSH_DEV} || ${PUSH_SERVER}; then
PLATFORMS=linux/amd64,linux/arm64
else
# If we're not pushing images to a registry, then save resources.
PLATFORMS=linux/amd64
fi
echo "PLATFORMS=${PLATFORMS}" >> $GITHUB_OUTPUT
echo "PUSH_DEV=${PUSH_DEV}" >> $GITHUB_OUTPUT
echo "PUSH_SERVER=${PUSH_SERVER}" >> $GITHUB_OUTPUT
set-tags:
runs-on: ubuntu-latest
outputs:
TIMESTAMP: ${{ steps.make_timestamp.outputs.TIMESTAMP }}
IS_LATEST: ${{ steps.is_latest.outputs.IS_LATEST }}
GITHUB_TAG: ${{ steps.determine_tags.outputs.GITHUB_TAG }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Make timestamp tag
id: make_timestamp
run: echo "TIMESTAMP=$(date +%Y%m%d-%H%M)" >> $GITHUB_OUTPUT
- name: Determine whether to tag this build with "latest"
id: is_latest
run: |
git fetch --tags
tags=$(git tag -l 'v*.*.*' | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | sort -V)
highest_tag=$(echo "${tags}" | tail -n1)
echo "Highest version tag is ${highest_tag}"
if [[ "${GITHUB_REF##*/}" == "${highest_tag}" ]]; then
echo "IS_LATEST=true" >> $GITHUB_OUTPUT
else
echo "IS_LATEST=false" >> $GITHUB_OUTPUT
fi
- name: Determine the tags that triggered this build
id: determine_tags
run: |
# Check if we're working with a tagged version
if [ -z "${{ inputs.tag }}" ]
then
# Use regex to check for a semver tag match.
if [[ ${GITHUB_REF##*/} =~ v[0-9]+\.[0-9]+\.[0-9]+ ]]
then
GITHUB_TAG=${GITHUB_REF##*/}
else
GITHUB_TAG="latest-dev"
fi
else
GITHUB_TAG=${{ inputs.tag }}
fi
echo "Master SHA:"
echo $(git rev-parse $GITHUB_REF_NAME)
echo "Current SHA:"
echo $(git rev-parse HEAD)
echo "Computed tags:"
echo $GITHUB_TAG
echo "GITHUB_TAG=$GITHUB_TAG" >> $GITHUB_OUTPUT
cache-image-layers:
needs: [set-build-parameters]
runs-on: ubuntu-latest
steps:
- name: Free disk space
shell: bash
run: |
# Use `df` to quickly check how much space is available.
echo "::group::Before"
df -h
echo "::endgroup::"
sudo rm -rf /usr/local/lib/android
echo "::group::After"
df -h
echo "::endgroup::"
- name: Checkout code
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: amd64,arm64
# NOTE (brianaydemir): Do not try to be clever and/or ambitious here.
# Keep the cache small by restricting it to the current GitHub Action
# run. We need to be able to save it for future jobs.
- name: Create a cache for Docker Buildx
uses: actions/cache@v4
with:
path: /tmp/.base-buildx-cache
key: base-buildx-${{ github.sha }}-${{ github.run_id }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
buildkitd-flags: --debug
- name: Save the GitHub workspace
uses: actions/cache/save@v4
with:
path: ${{ github.workspace }}
key: github-workspace-${{ github.sha }}-${{ github.run_id }}
- name: Create and cache image layers
uses: docker/build-push-action@v5
with:
context: .
file: ./images/Dockerfile
platforms: ${{ needs.set-build-parameters.outputs.platforms }}
target: origin
cache-from: |
type=registry,ref=hub.opensciencegrid.org/pelican_platform/pelican-dev:buildcache
type=local,src=/tmp/.base-buildx-cache
cache-to: type=local,dest=/tmp/.base-buildx-cache,mode=max
build-server-images:
needs: [set-build-parameters, cache-image-layers, set-tags]
strategy:
fail-fast: false
matrix:
image:
- origin
- cache
- director
- registry
- osdf-origin
- osdf-cache
- osdf-director
- osdf-registry
# For release candidates, this is where we build and push the testing container.
- pelican-test
runs-on: ubuntu-latest
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: amd64,arm64
- name: Generate tag list
id: generate-tag-list
env:
GITHUB_TAG: ${{ needs.set-tags.outputs.GITHUB_TAG }}
IS_LATEST: ${{ needs.set-tags.outputs.IS_LATEST }}
run: |
docker_repo="pelican_platform"
image_name=${{ matrix.image }}
tag_list=()
for registry in hub.opensciencegrid.org; do
for image_tag in "$GITHUB_TAG"; do
tag_list+=("$registry/$docker_repo/$image_name":"$image_tag")
done
done
if [[ "$IS_LATEST" == "true" ]]; then
tag_list+=("$registry/$docker_repo/$image_name:latest")
fi
# This causes the tag_list array to be comma-separated below,
# which is required for build-push-action
IFS=,
echo "taglist=${tag_list[*]}" >> $GITHUB_OUTPUT
- name: Restore the cache for Docker Buildx
uses: actions/cache/restore@v4
with:
path: /tmp/.base-buildx-cache
key: base-buildx-${{ github.sha }}-${{ github.run_id }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
buildkitd-flags: --debug
- name: Log in to OSG Harbor
uses: docker/login-action@v3
if: ${{ needs.set-build-parameters.outputs.push-server == 'true' }}
with:
registry: hub.opensciencegrid.org
username: ${{ secrets.PELICAN_HARBOR_ROBOT_USER }}
password: ${{ secrets.PELICAN_HARBOR_ROBOT_PASSWORD }}
- name: Restore the GitHub workspace
uses: actions/cache/restore@v4
with:
path: ${{ github.workspace }}
key: github-workspace-${{ github.sha }}-${{ github.run_id }}
#
# NOTE (brianaydemir): If we've somehow managed to get the GitHub
# workspace cache evicted, then there are likely serious problems
# with how we're triggering and using GitHub actions. Make noise!
#
fail-on-cache-miss: true
- name: Build and push Docker images
uses: docker/build-push-action@v5
with:
context: .
file: ./images/Dockerfile
platforms: ${{ needs.set-build-parameters.outputs.platforms }}
target: ${{ matrix.image }}
push: ${{ needs.set-build-parameters.outputs.push-server == 'true' }}
tags: "${{ steps.generate-tag-list.outputs.taglist }}"
cache-from: |
type=registry,ref=hub.opensciencegrid.org/pelican_platform/pelican-dev:buildcache
type=local,src=/tmp/.base-buildx-cache
build-devtest-images:
needs: [set-build-parameters, cache-image-layers]
runs-on: ubuntu-latest
steps:
# NOTE (brianaydemir): If it wasn't for the potential expense of
# loading the Docker Buildx cache, we could implement this job using
# a matrix and eliminate near-identical steps.
- name: Determine image tags (pelican-test)
id: pelican-test-tags
uses: docker/metadata-action@v5
with:
images: hub.opensciencegrid.org/pelican_platform/pelican-test
tags: |
type=raw,value=latest-itb
type=raw,value=sha-{{sha}}
- name: Determine image tags (pelican-dev)
id: pelican-dev-tags
uses: docker/metadata-action@v5
with:
images: hub.opensciencegrid.org/pelican_platform/pelican-dev
tags: |
type=raw,value=latest-itb
type=raw,value=sha-{{sha}}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: amd64,arm64
- name: Restore the cache for Docker Buildx
uses: actions/cache/restore@v4
with:
path: /tmp/.base-buildx-cache
key: base-buildx-${{ github.sha }}-${{ github.run_id }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
buildkitd-flags: --debug
- name: Log in to OSG Harbor
uses: docker/login-action@v3
if: ${{ needs.set-build-parameters.outputs.push-dev == 'true' }}
with:
registry: hub.opensciencegrid.org
username: ${{ secrets.PELICAN_HARBOR_ROBOT_USER }}
password: ${{ secrets.PELICAN_HARBOR_ROBOT_PASSWORD }}
- name: Restore the GitHub workspace
uses: actions/cache/restore@v4
with:
path: ${{ github.workspace }}
key: github-workspace-${{ github.sha }}-${{ github.run_id }}
#
# NOTE (brianaydemir): If we've somehow managed to get the GitHub
# workspace cache evicted, then there are likely serious problems
# with how we're triggering and using GitHub actions. Make noise!
#
fail-on-cache-miss: true
- name: Build and push Docker images (pelican-test)
uses: docker/build-push-action@v5
with:
context: .
file: ./images/Dockerfile
platforms: ${{ needs.set-build-parameters.outputs.platforms }}
target: pelican-test
push: ${{ needs.set-build-parameters.outputs.push-dev == 'true' }}
tags: ${{ steps.pelican-test-tags.outputs.tags }}
cache-from: |
type=registry,ref=hub.opensciencegrid.org/pelican_platform/pelican-dev:buildcache
type=local,src=/tmp/.base-buildx-cache
- name: Build and push Docker images (pelican-dev)
uses: docker/build-push-action@v5
with:
context: .
file: ./images/Dockerfile
platforms: ${{ needs.set-build-parameters.outputs.platforms }}
target: pelican-dev
push: ${{ needs.set-build-parameters.outputs.push-dev == 'true' }}
tags: ${{ steps.pelican-dev-tags.outputs.tags }}
cache-from: |
type=registry,ref=hub.opensciencegrid.org/pelican_platform/pelican-dev:buildcache
type=local,src=/tmp/.base-buildx-cache
cache-to: type=registry,ref=hub.opensciencegrid.org/pelican_platform/pelican-dev:buildcache,mode=max,image-manifest=true,oci-mediatypes=true,ignore-error=true
# The macOS and Windows tests do not depend on any of the images being
# built above. Thus, there is a separate workflow for running the tests:
# test-macos-windows.yaml.
#
# The Linux tests are less straightforward because we need to decide
# which container image to run the tests in, which might require waiting
# for the image to be built.
#
# For a pull request, we cannot build and push a newer image. Thus, there
# is a separate workflow for running the tests: test-linux-pr.yaml.
test-linux-push-to-main:
needs: [set-build-parameters, build-devtest-images]
if: ${{ needs.set-build-parameters.outputs.push-dev == 'true' }}
uses: ./.github/workflows/test-linux.yml
with:
image: hub.opensciencegrid.org/pelican_platform/pelican-test:latest-itb
test-linux-push-to-tag:
needs: [set-build-parameters, set-tags, build-server-images]
if: ${{ needs.set-build-parameters.outputs.push-server == 'true' }}
uses: ./.github/workflows/test-linux.yml
with:
image: hub.opensciencegrid.org/pelican_platform/pelican-test:${{ needs.set-tags.outputs.GITHUB_TAG }}