Skip to content

Commit 8c153a3

Browse files
committed
CI: Support building multiple container image distros in parallel
1 parent efa70f6 commit 8c153a3

File tree

1 file changed

+41
-40
lines changed

1 file changed

+41
-40
lines changed

.github/workflows/stackhpc-container-image-build.yml

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@ on:
1818
type: boolean
1919
required: false
2020
default: false
21-
distro:
22-
description: Container image OS distribution
23-
type: choice
21+
centos-stream-8:
22+
description: Build CentOS Stream 8 images?
23+
type: boolean
24+
required: false
25+
default: true
26+
ubuntu-focal:
27+
description: Build Ubuntu Focal 20.04 images?
28+
type: boolean
2429
required: false
25-
default: centos
26-
options:
27-
- centos
28-
- ubuntu
30+
default: true
2931
push:
3032
description: Whether to push images
3133
type: boolean
@@ -41,8 +43,9 @@ jobs:
4143
runs-on: [self-hosted, stackhpc-kayobe-config-kolla-builder]
4244
permissions: {}
4345
outputs:
44-
openstack_release: ${{ steps.openstack_release.outputs.openstack_release }}
4546
kolla_tag: ${{ steps.kolla_tag.outputs.kolla_tag }}
47+
matrix: ${{ steps.set-matrix.outputs.matrix }}
48+
openstack_release: ${{ steps.openstack_release.outputs.openstack_release }}
4649
steps:
4750
- name: Checkout
4851
uses: actions/checkout@v3
@@ -60,6 +63,24 @@ jobs:
6063
run: |
6164
echo "kolla_tag=$(date +${{ steps.openstack_release.outputs.openstack_release }}-%Y%m%dT%H%M%S)" >> $GITHUB_OUTPUT
6265
66+
# Dynamically define job matrix.
67+
# We need a separate matrix entry for each distribution, when the relevant input is true.
68+
# https://stackoverflow.com/questions/65384420/how-do-i-make-a-github-action-matrix-element-conditional
69+
- name: Generate build matrix
70+
id: set-matrix
71+
run: |
72+
comma=""
73+
echo -n "matrix={\"distro\": [" >> $GITHUB_OUTPUT
74+
if [[ ${{ inputs.centos-stream-8 }} == 'true' ]]; then
75+
echo -n "$comma\"centos\"" >> $GITHUB_OUTPUT
76+
comma=", "
77+
fi
78+
if [[ ${{ inputs.ubuntu-focal }} == 'true' ]]; then
79+
echo -n "$comma\"ubuntu\"" >> $GITHUB_OUTPUT
80+
comma=", "
81+
fi
82+
echo "]}" >> $GITHUB_OUTPUT
83+
6384
- name: Display container image tag
6485
run: |
6586
echo "${{ steps.kolla_tag.outputs.kolla_tag }}"
@@ -69,6 +90,8 @@ jobs:
6990
if: github.repository == 'stackhpc/stackhpc-kayobe-config'
7091
runs-on: [self-hosted, stackhpc-kayobe-config-kolla-builder]
7192
permissions: {}
93+
strategy:
94+
matrix: ${{ fromJson(needs.generate-tag.outputs.matrix) }}
7295
needs:
7396
- generate-tag
7497
steps:
@@ -136,7 +159,9 @@ jobs:
136159

137160
- name: Build and push kolla overcloud images
138161
run: |
139-
args="${{ github.event.inputs.regexes }} -e kolla_base_distro=${{ inputs.distro }} -e kolla_tag=${{ needs.generate-tag.outputs.kolla_tag }}"
162+
args="${{ github.event.inputs.regexes }}"
163+
args="$args -e kolla_base_distro=${{ matrix.distro }}"
164+
args="$args -e kolla_tag=${{ needs.generate-tag.outputs.kolla_tag }}"
140165
if ${{ inputs.push }} == 'true'; then
141166
args="$args --push"
142167
fi
@@ -147,27 +172,10 @@ jobs:
147172
KAYOBE_VAULT_PASSWORD: ${{ secrets.KAYOBE_VAULT_PASSWORD }}
148173
if: github.event.inputs.overcloud == 'true'
149174

150-
- name: Display the overcloud container image tag
151-
run: |
152-
echo "$(cat ~/kolla_tag)"
153-
if: github.event.inputs.overcloud == 'true'
154-
155-
- name: Get built overcloud container images
156-
run: |
157-
sudo docker image ls --filter "reference=ark.stackhpc.com/stackhpc-dev/*:$(cat ~/kolla_tag)" > overcloud-container-images
158-
if: github.event.inputs.overcloud == 'true'
159-
160-
- name: Upload overcloud-container-images artifact
161-
uses: actions/upload-artifact@v3
162-
with:
163-
name: Overcloud container images
164-
path: overcloud-container-images
165-
retention-days: 7
166-
if: github.event.inputs.overcloud == 'true'
167-
168175
- name: Build and push kolla seed images
169176
run: |
170-
args="kolla_base_distro=${{ inputs.distro }} -e kolla_tag=${{ needs.generate-tag.outputs.kolla_tag }}"
177+
args="kolla_base_distro=${{ matrix.distro }}"
178+
args="$args -e kolla_tag=${{ needs.generate-tag.outputs.kolla_tag }}"
171179
if ${{ inputs.push }} == 'true'; then
172180
args="$args --push"
173181
fi
@@ -178,23 +186,16 @@ jobs:
178186
KAYOBE_VAULT_PASSWORD: ${{ secrets.KAYOBE_VAULT_PASSWORD }}
179187
if: github.event.inputs.seed == 'true'
180188

181-
- name: Display the seed container image tag
182-
run: |
183-
echo "$(cat ~/kolla_tag)"
184-
if: github.event.inputs.seed == 'true'
185-
186-
- name: Get built seed container images
189+
- name: Get built container images
187190
run: |
188-
sudo docker image ls --filter "reference=ark.stackhpc.com/stackhpc-dev/*:$(cat ~/kolla_tag)" > seed-container-images
189-
if: github.event.inputs.seed == 'true'
191+
sudo docker image ls --filter "reference=ark.stackhpc.com/stackhpc-dev/${{ matrix.distro }}-*:${{ needs.generate-tag.outputs.kolla_tag }}" > ${{ matrix.distro }}-container-images
190192
191-
- name: Upload seed-container-images artifact
193+
- name: Upload container images artifact
192194
uses: actions/upload-artifact@v3
193195
with:
194-
name: Seed container images
195-
path: seed-container-images
196+
name: ${{ matrix.distro }} container images
197+
path: ${{ matrix.distro }}-container-images
196198
retention-days: 7
197-
if: github.event.inputs.seed == 'true'
198199

199200
- name: Prune local Kolla container images over 1 week old
200201
run: |

0 commit comments

Comments
 (0)