-
Notifications
You must be signed in to change notification settings - Fork 21
198 lines (186 loc) · 7.31 KB
/
build-containers.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
---
name: Build and push container images
on:
push:
pull_request:
workflow_dispatch:
repository_dispatch:
types: [dispatch-build]
jobs:
make-date-tag:
runs-on: ubuntu-latest
outputs:
dtag: ${{ steps.mkdatetag.outputs.dtag }}
steps:
- name: make date tag
id: mkdatetag
run: echo "::set-output name=dtag::$(date +%Y%m%d-%H%M)"
build-image-list:
runs-on: ubuntu-latest
outputs:
images: ${{ steps.image-list.outputs.json }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- id: image-list
run: |
ORG_DIR=opensciencegrid
# Get the list of files changed based on the type of event
# kicking off the GHA:
# 1. For the main branch, diff the previous state of main vs
# the current commit
# 2. For other branches (i.e., on someone's fork), diff main
# vs the current commit
# 3. For PRs, diff the base ref vs the current commit
# 4. For everything else (e.g., dispatches), build all images
if [[ $GITHUB_EVENT_NAME == 'pull_request' ]] ||
[[ $GITHUB_EVENT_NAME == 'push' ]]; then
if [[ $GITHUB_EVENT_NAME == 'pull_request' ]]; then
BASE=$(git merge-base origin/$GITHUB_BASE_REF HEAD)
elif [[ $GITHUB_REF == 'refs/heads/main' ]]; then
BASE=${{github.event.before}}
else
BASE=origin/main
fi
# List image root dirs where files have changed and the
# root dir exists. Example value:
# "opensciencegrid/vo-frontend opensciencegrid/ospool-cm"
images=$(git diff --name-only \
"$BASE" \
"$GITHUB_SHA" |
egrep "^$ORG_DIR/" |
cut -d/ -f -2 |
sort |
uniq |
xargs -I {} find . -type d \
-wholename ./{} \
-printf "%P\n")
else
# List all image root dirs. Example value:
# "opensciencegrid/vo-frontend opensciencegrid/ospool-cm"
images=$(find $ORG_DIR -mindepth 1 \
-maxdepth 1 \
-type d \
-printf "$ORG_DIR/%P\n")
fi
# Ensure that the generated JSON array has a member,
# otherwise GHA will throw an error about an empty matrix
# vector in subsequent steps
image_json=$(echo -n "${images:-dummy}" | jq -Rcs '.|split("\n")')
echo "::set-output name=json::$image_json"
build:
runs-on: ubuntu-latest
needs: build-image-list
if: needs.build-image-list.outputs.images != '["dummy"]'
# Prevent a single build failure from killing the workflow.
# This is safe since subsequent pushes should fail on cache load
continue-on-error: true
strategy:
fail-fast: false
matrix:
image: ${{ fromJson(needs.build-image-list.outputs.images) }}
yum_repo: ['development', 'testing', 'release']
series:
- name: '3.6'
os: 'el7'
- name: '23'
os: 'el9'
# FIXME: reenable osg-23 development when available
exclude:
- yum_repo: 'development'
series: {name: '23', os: 'el9'}
steps:
- name: Build ${{ matrix.image }}:${{ matrix.series }}-${{ matrix.yum_repo }}
continue-on-error: ${{ matrix.yum_repo == 'development' }}
uses: opensciencegrid/[email protected]
with:
osg_series: ${{ matrix.series.name }}
osg_repo: ${{ matrix.yum_repo }}
context: ${{ matrix.image }}
base_os: ${{ matrix.series.os }}
push:
runs-on: ubuntu-latest
if: >-
github.ref == 'refs/heads/main' &&
github.event_name != 'pull_request' &&
github.repository_owner == 'opensciencegrid' &&
needs.build-image-list.outputs.images != '["dummy"]'
needs: [make-date-tag, build-image-list, build]
strategy:
fail-fast: false
matrix:
image: ${{ fromJson(needs.build-image-list.outputs.images) }}
series:
- name: '3.6'
os: 'el7'
- name: '23'
os: 'el9'
steps:
- name: Push to Harbor (${{ matrix.series }}-development)
# FIXME: reenable for OSG 23 development when available
if: matrix.series.name != '23'
uses: opensciencegrid/push-container-action@main
with:
repo: development
osg_series: ${{ matrix.series.name }}
context: ${{ matrix.image }}
base_os: ${{ matrix.series.os }}
registry_url: hub.opensciencegrid.org
registry_user: ${{ secrets.OSG_HARBOR_ROBOT_USER }}
registry_pass: ${{ secrets.OSG_HARBOR_ROBOT_PASSWORD }}
- name: Push to Harbor (${{ matrix.series.name }}-testing)
if: always()
uses: opensciencegrid/push-container-action@main
with:
repo: testing
osg_series: ${{ matrix.series.name }}
context: ${{ matrix.image }}
base_os: ${{ matrix.series.os }}
registry_url: hub.opensciencegrid.org
registry_user: ${{ secrets.OSG_HARBOR_ROBOT_USER }}
registry_pass: ${{ secrets.OSG_HARBOR_ROBOT_PASSWORD }}
- name: Push to Harbor (${{ matrix.series.name }}-release)
if: always()
uses: opensciencegrid/push-container-action@main
with:
repo: release
osg_series: ${{ matrix.series.name }}
context: ${{ matrix.image }}
base_os: ${{ matrix.series.os }}
registry_url: hub.opensciencegrid.org
registry_user: ${{ secrets.OSG_HARBOR_ROBOT_USER }}
registry_pass: ${{ secrets.OSG_HARBOR_ROBOT_PASSWORD }}
- name: Push to Docker Hub (${{ matrix.series.name }}-development)
if: always()
uses: opensciencegrid/push-container-action@main
with:
repo: development
osg_series: ${{ matrix.series.name }}
context: ${{ matrix.image }}
base_os: ${{ matrix.series.os }}
registry_url: docker.io
registry_user: ${{ secrets.DOCKER_USERNAME }}
registry_pass: ${{ secrets.DOCKER_PASSWORD }}
- name: Push to Docker Hub (${{ matrix.series.name }}-testing)
if: always()
uses: opensciencegrid/push-container-action@main
with:
repo: testing
osg_series: ${{ matrix.series.name }}
context: ${{ matrix.image }}
base_os: ${{ matrix.series.os }}
registry_url: docker.io
registry_user: ${{ secrets.DOCKER_USERNAME }}
registry_pass: ${{ secrets.DOCKER_PASSWORD }}
- name: Push to Docker Hub (${{ matrix.series.name }}-release)
if: always()
uses: opensciencegrid/push-container-action@main
with:
repo: release
osg_series: ${{ matrix.series.name }}
context: ${{ matrix.image }}
base_os: ${{ matrix.series.os }}
registry_url: docker.io
registry_user: ${{ secrets.DOCKER_USERNAME }}
registry_pass: ${{ secrets.DOCKER_PASSWORD }}