This repository has been archived by the owner on Jun 23, 2022. It is now read-only.
forked from redhat-actions/openshift-actions-runners
-
Notifications
You must be signed in to change notification settings - Fork 0
283 lines (247 loc) · 9.07 KB
/
update_images.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
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
name: Update Runner Images
on:
push:
pull_request:
workflow_dispatch:
env:
REGISTRY_URL: quay.io/redhat-github-actions
BASE_IMG_NAME: runner
BASE_IMG_DIR: base
BUILDAH_IMG_NAME: buildah-runner
BUILDAH_IMG_DIR: buildah
K8S_TOOLS_IMG_NAME: k8s-tools-runner
K8S_TOOLS_IMG_DIR: k8s-tools
NODE_IMG_NAME: node-runner-14
NODE_IMG_DIR: node
JAVA_IMG_NAME: java-runner-11
JAVA_IMG_DIR: java
jobs:
update_images:
name: Update images
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: redhat-actions/common/commit-data@v1
id: commit_data
- uses: lots0logs/[email protected]
id: get_changed_files
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Determine changed directories
id: is_dir_changed
uses: actions/github-script@v4
with:
script: |
const changedFiles = ${{ steps.get_changed_files.outputs.all }};
console.log(`Changed files: ${JSON.stringify(changedFiles)}`);
// console.log(`payload ${JSON.stringify(context.payload)}`);
// console.log(`eventName ${JSON.stringify(context.eventName)}`);
const BASE = "base";
const dirsChanged = {
[BASE]: false,
buildah: false,
"k8s-tools": false,
java: false,
node: false,
};
Object.keys(dirsChanged).forEach((dir) => {
const changed = changedFiles.find((changedFile) => changedFile.startsWith(dir + "/")) != null;
dirsChanged[dir] = changed;
});
let rebuildAll = false;
if (context.ref.startsWith("refs/tags/")) {
console.log(`Tag build; all images will be rebuilt.`);
rebuildAll = true;
}
else if (context.eventName === "workflow_dispatch") {
console.log(`Workflow triggered by workflow_dispatch; all images will be rebuilt`);
rebuildAll = true;
}
else if (dirsChanged[BASE]) {
console.log("Base image changed; all images will be rebuilt.");
rebuildAll = true;
}
Object.keys(dirsChanged).forEach((dir) => {
const changed = rebuildAll || dirsChanged[dir];
const outputName = (dir + "_changed").toUpperCase();
console.log(`${outputName}=${changed}`)
core.exportVariable(outputName, changed);
});
// const anyChanged = Object.entries(dirsChanged).find(([k, v] => dirsChanged[k]));
return dirsChanged;
- name: Determine image tag
shell: bash
run: |
export IMG_TAGS=latest
export GIT_TAG="${{ steps.commit_data.outputs.tag }}"
export BRANCH="${{ steps.commit_data.outputs.branch }}"
if [[ -n "$GIT_TAG" ]]; then
IMG_TAGS="$GIT_TAG"
elif [[ -n "$BRANCH" ]]; then
if [[ "$BRANCH" == "main" ]]; then
IMG_TAGS="latest"
else
IMG_TAGS=$BRANCH
fi
else
IMG_TAGS="${{ steps.commit_data.outputs.short_sha }}"
fi
echo "IMG_TAGS=$IMG_TAGS" >> $GITHUB_ENV
echo "BRANCH=$BRANCH" >> $GITHUB_ENV
echo "Tagging images with '$IMG_TAGS'"
# The child image builds are done on the same machine so that
# it doesn't have to pull the updated base image; it's already there locally.
- name: Determine parent image name and tag
shell: bash
run: |
export FIRST_TAG=$(echo "${{ env.IMG_TAGS }}" | awk '{ print $1 }')
# export BASE_IMG=${{ env.REGISTRY_URL }}/${{ env.BASE_IMG_NAME }}:$FIRST_TAG
export BASE_IMG=${{ env.BASE_IMG_NAME }}:$FIRST_TAG
echo "Base image is '$BASE_IMG'"
echo BASE_IMG=$BASE_IMG >> $GITHUB_ENV
- name: Build base image
if: env.BASE_CHANGED == 'true'
uses: redhat-actions/buildah-build@v2
id: build_base_img
with:
image: ${{ env.BASE_IMG_NAME }}
tags: ${{ env.IMG_TAGS }}
oci: true
context:
${{ env.BASE_IMG_DIR }}
dockerfiles:
${{ env.BASE_IMG_DIR }}/Containerfile
- name: Push base image
if: steps.commit_data.outputs.is_pr == 'false' && env.BASE_CHANGED == 'true'
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ env.BASE_IMG_NAME }}
tags: ${{ env.IMG_TAGS }}
registry: ${{ env.REGISTRY_URL }}
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- name: Determine if child images should be built
run: |
export BUILD_BASE_OUTCOME="${{ steps.build_base_img.outcome }}"
if [[ $BUILD_BASE_OUTCOME == "success" ]] || [[ $BUILD_BASE_OUTCOME == "skipped" ]]; then
echo "Base image was built or did not need to be built"
echo "Child images will be built"
export BUILD_CHILDREN=true
else
export BUILD_CHILDREN=false
echo "Base image build failed"
echo "Child image builds will be skipped."
fi
echo "BUILD_CHILDREN=$BUILD_CHILDREN" >> $GITHUB_ENV
- name: Build buildah image
if: |
always() &&
env.BUILDAH_CHANGED == 'true' &&
env.BUILD_CHILDREN == 'true'
id: build_buildah
uses: redhat-actions/buildah-build@v2
with:
image: ${{ env.BUILDAH_IMG_NAME }}
tags: ${{ env.IMG_TAGS }}
oci: true
context:
${{ env.BUILDAH_IMG_DIR }}
dockerfiles:
${{ env.BUILDAH_IMG_DIR }}/Containerfile
build-args: |
BASE_IMG=${{ env.BASE_IMG }}
- name: Push buildah image
if: |
steps.build_buildah.outcome == 'success' &&
steps.commit_data.outputs.is_pr == 'false'
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ env.BUILDAH_IMG_NAME }}
tags: ${{ env.IMG_TAGS }}
registry: ${{ env.REGISTRY_URL }}
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- name: Build K8s tools image
if: |
always() &&
env.K8S-TOOLS_CHANGED == 'true' &&
env.BUILD_CHILDREN == 'true'
uses: redhat-actions/buildah-build@v2
id: build_k8s
with:
image: ${{ env.K8S_TOOLS_IMG_NAME }}
tags: ${{ env.IMG_TAGS }}
oci: true
context:
${{ env.K8S_TOOLS_IMG_DIR }}
dockerfiles:
${{ env.K8S_TOOLS_IMG_DIR }}/Containerfile
build-args: |
BASE_IMG=${{ env.BASE_IMG }}
- name: Push K8s tools image
if: |
steps.build_k8s.outcome == 'success' &&
steps.commit_data.outputs.is_pr == 'false'
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ env.K8S_TOOLS_IMG_NAME }}
tags: ${{ env.IMG_TAGS }}
registry: ${{ env.REGISTRY_URL }}
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- name: Build Node image
if: |
always() &&
env.NODE_CHANGED == 'true' &&
env.BUILD_CHILDREN == 'true'
id: build_node
uses: redhat-actions/buildah-build@v2
with:
image: ${{ env.NODE_IMG_NAME }}
tags: ${{ env.IMG_TAGS }}
oci: true
context:
${{ env.NODE_IMG_DIR }}
dockerfiles:
${{ env.NODE_IMG_DIR }}/Containerfile
build-args: |
BASE_IMG=${{ env.BASE_IMG }}
- name: Push Node image
if: |
steps.build_node.outcome == 'success' &&
steps.commit_data.outputs.is_pr == 'false'
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ env.NODE_IMG_NAME }}
tags: ${{ env.IMG_TAGS }}
registry: ${{ env.REGISTRY_URL }}
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- name: Build Java image
if: |
always() &&
env.JAVA_CHANGED == 'true' &&
env.BUILD_CHILDREN == 'true'
id: build_java
uses: redhat-actions/buildah-build@v2
with:
image: ${{ env.JAVA_IMG_NAME }}
tags: ${{ env.IMG_TAGS }}
oci: true
context:
${{ env.JAVA_IMG_DIR }}
dockerfiles:
${{ env.JAVA_IMG_DIR }}/Containerfile
build-args: |
BASE_IMG=${{ env.BASE_IMG }}
- name: Push Java image
if: |
steps.build_java.outcome == 'success' &&
steps.commit_data.outputs.is_pr == 'false'
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ env.JAVA_IMG_NAME }}
tags: ${{ env.IMG_TAGS }}
registry: ${{ env.REGISTRY_URL }}
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_PASSWORD }}