Skip to content

Commit f0f40ad

Browse files
committed
CI: overcloud host image matrix build
This change refactors the overcloud host image build workflow to make the image tag consistent across different images built from the same workflow run.
1 parent c48f398 commit f0f40ad

File tree

4 files changed

+144
-150
lines changed

4 files changed

+144
-150
lines changed

.github/workflows/overcloud-host-image-build.yml

Lines changed: 121 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,124 @@ on:
2727
env:
2828
ANSIBLE_FORCE_COLOR: True
2929
jobs:
30-
overcloud-host-image-build:
31-
name: Build overcloud host images
30+
generate-tag:
31+
name: Generate overcloud host image tag
3232
if: github.repository == 'stackhpc/stackhpc-kayobe-config'
3333
runs-on: [self-hosted, stackhpc-kayobe-config-kolla-builder]
34+
permissions: {}
35+
outputs:
36+
host_image_tag: ${{ steps.host_image_tag.outputs.host_image_tag }}
37+
matrix: ${{ steps.set-matrix.outputs.matrix }}
38+
openstack_release: ${{ steps.openstack_release.outputs.openstack_release }}
3439
steps:
35-
- uses: actions/checkout@v3
36-
with:
37-
path: src/kayobe-config
40+
- name: Checkout
41+
uses: actions/checkout@v3
3842

3943
- name: Determine OpenStack release
4044
id: openstack_release
4145
run: |
4246
BRANCH=$(awk -F'=' '/defaultbranch/ {print $2}' .gitreview)
4347
echo "openstack_release=${BRANCH}" | sed "s|stable/||" >> $GITHUB_OUTPUT
4448
49+
# Generate a tag to apply to all built overcloud host images.
50+
- name: Generate overcloud host image tag
51+
id: host_image_tag
52+
run: |
53+
echo "host_image_tag=$(date +${{ steps.openstack_release.outputs.openstack_release }}-%Y%m%dT%H%M%S)" >> $GITHUB_OUTPUT
54+
55+
# Dynamically define job matrix.
56+
# We need a separate matrix entry for each distribution, when the relevant input is true.
57+
# https://stackoverflow.com/questions/65384420/how-do-i-make-a-github-action-matrix-element-conditional
58+
# The resultant matrix will have the following structure, filtered by inputs:
59+
# matrix:
60+
# distro: [centos, rocky8, rocky9, ubuntu-focal, ubuntu-jammy]
61+
# include:
62+
# - distro: centos
63+
# os_distribution: centos
64+
# os_release: 8-stream
65+
# - distro: rocky8
66+
# os_distribution: rocky
67+
# os_release: 8
68+
# - distro: rocky9
69+
# os_distribution: rocky
70+
# os_release: 9
71+
# - distro: ubuntu-focal
72+
# os_distribution: ubuntu
73+
# os_release: focal
74+
# - distro: ubuntu-jammy
75+
# os_distribution: ubuntu
76+
# os_release: jammy
77+
- name: Generate build matrix
78+
id: set-matrix
79+
run: |
80+
comma=""
81+
echo -n "matrix={\"distro\": [" >> $GITHUB_OUTPUT
82+
if [[ ${{ inputs.centos }} == 'true' ]]; then
83+
echo -n "$comma\"centos\"" >> $GITHUB_OUTPUT
84+
comma=", "
85+
fi
86+
if [[ ${{ inputs.rocky8 }} == 'true' ]]; then
87+
echo -n "$comma\"rocky8\"" >> $GITHUB_OUTPUT
88+
comma=", "
89+
fi
90+
if [[ ${{ inputs.rocky9 }} == 'true' ]]; then
91+
echo -n "$comma\"rocky9\"" >> $GITHUB_OUTPUT
92+
comma=", "
93+
fi
94+
if [[ ${{ inputs.ubuntu-focal }} == 'true' ]]; then
95+
echo -n "$comma\"ubuntu-focal\"" >> $GITHUB_OUTPUT
96+
comma=", "
97+
fi
98+
if [[ ${{ inputs.ubuntu-jammy }} == 'true' ]]; then
99+
echo -n "$comma\"ubuntu-jammy\"" >> $GITHUB_OUTPUT
100+
fi
101+
echo -n "]" >> $GITHUB_OUTPUT
102+
echo -n ", \"include\": [" >> $GITHUB_OUTPUT
103+
comma=""
104+
if [[ ${{ inputs.centos }} == 'true' ]]; then
105+
echo -n "$comma{\"distro\": \"centos\", \"os_distribution\": \"centos\", \"os_release\": \"8-stream\"}" >> $GITHUB_OUTPUT
106+
comma=", "
107+
fi
108+
if [[ ${{ inputs.rocky8 }} == 'true' ]]; then
109+
echo -n "$comma{\"distro\": \"rocky8\", \"os_distribution\": \"rocky\", \"os_release\": \"8\"}" >> $GITHUB_OUTPUT
110+
comma=", "
111+
fi
112+
if [[ ${{ inputs.rocky9 }} == 'true' ]]; then
113+
echo -n "$comma{\"distro\": \"rocky9\", \"os_distribution\": \"rocky\", \"os_release\": \"9\"}" >> $GITHUB_OUTPUT
114+
comma=", "
115+
fi
116+
if [[ ${{ inputs.ubuntu-focal }} == 'true' ]]; then
117+
echo -n "$comma{\"distro\": \"ubuntu-focal\", \"os_distribution\": \"ubuntu\", \"os_release\": \"focal\"}" >> $GITHUB_OUTPUT
118+
comma=", "
119+
fi
120+
if [[ ${{ inputs.ubuntu-jammy }} == 'true' ]]; then
121+
echo -n "$comma{\"distro\": \"ubuntu-jammy\", \"os_distribution\": \"ubuntu\", \"os_release\": \"jammy\"}" >> $GITHUB_OUTPUT
122+
fi
123+
echo "]}" >> $GITHUB_OUTPUT
124+
125+
- name: Display container image tag
126+
run: |
127+
echo "${{ steps.host_image_tag.outputs.host_image_tag }}"
128+
129+
overcloud-host-image-build:
130+
name: Build overcloud host images
131+
if: github.repository == 'stackhpc/stackhpc-kayobe-config'
132+
runs-on: [self-hosted, stackhpc-kayobe-config-kolla-builder]
133+
strategy:
134+
matrix: ${{ fromJson(needs.generate-tag.outputs.matrix) }}
135+
fail-fast: false
136+
needs:
137+
- generate-tag
138+
steps:
139+
- uses: actions/checkout@v3
140+
with:
141+
path: src/kayobe-config
142+
45143
- name: Clone StackHPC Kayobe repository
46144
uses: actions/checkout@v3
47145
with:
48146
repository: stackhpc/kayobe
49-
ref: refs/heads/stackhpc/${{ steps.openstack_release.outputs.openstack_release }}
147+
ref: refs/heads/stackhpc/${{ needs.generate-tag.outputs.openstack_release }}
50148
path: src/kayobe
51149

52150
# FIXME: Failed in kolla-ansible : Ensure the latest version of pip is installed
@@ -69,6 +167,14 @@ jobs:
69167
sudo ip l set dummy1 up
70168
sudo ip l set dummy1 master breth1
71169
170+
# FIXME: Without this workaround we see the following issue after the runner is power cycled:
171+
# TASK [MichaelRigart.interfaces : RedHat | ensure network service is started and enabled] ***
172+
# Unable to start service network: Job for network.service failed because the control process exited with error code.
173+
# See \"systemctl status network.service\" and \"journalctl -xe\" for details.
174+
- name: Kill dhclient (workaround)
175+
run: |
176+
(sudo killall dhclient || true) && sudo systemctl restart network
177+
72178
- name: Install Kayobe
73179
run: |
74180
mkdir -p venvs &&
@@ -98,148 +204,26 @@ jobs:
98204
sudo docker volume create bifrost_httpboot
99205
fi
100206
101-
- name: Clean any previous build artifact
102-
run: |
103-
rm -f /tmp/updated_images.txt
104-
105-
- name: Build a CentOS Stream 8 overcloud host image
106-
run: |
107-
source venvs/kayobe/bin/activate &&
108-
source src/kayobe-config/kayobe-env --environment ci-builder &&
109-
kayobe overcloud host image build --force-rebuild \
110-
-e os_distribution=centos \
111-
-e stackhpc_overcloud_dib_name=overcloud-centos-stream-8
112-
env:
113-
KAYOBE_VAULT_PASSWORD: ${{ secrets.KAYOBE_VAULT_PASSWORD }}
114-
if: inputs.centos
115-
116-
- name: Upload CentOS Stream 8 overcloud host image artifact
117-
run: |
118-
source venvs/kayobe/bin/activate &&
119-
source src/kayobe-config/kayobe-env --environment ci-builder &&
120-
kayobe playbook run \
121-
src/kayobe-config/etc/kayobe/ansible/pulp-host-image-upload.yml \
122-
-e image_path='/opt/kayobe/images/overcloud-centos-stream-8' \
123-
-e os_distribution='centos'
124-
env:
125-
KAYOBE_VAULT_PASSWORD: ${{ secrets.KAYOBE_VAULT_PASSWORD }}
126-
if: inputs.centos
127-
128-
- name: Build a Rocky Linux 8 overcloud host image
129-
run: |
130-
source venvs/kayobe/bin/activate &&
131-
source src/kayobe-config/kayobe-env --environment ci-builder &&
132-
kayobe overcloud host image build --force-rebuild \
133-
-e os_distribution=rocky \
134-
-e os_release='8' \
135-
-e stackhpc_overcloud_dib_name=overcloud-rocky-linux-8
136-
env:
137-
KAYOBE_VAULT_PASSWORD: ${{ secrets.KAYOBE_VAULT_PASSWORD }}
138-
if: inputs.rocky8
139-
140-
- name: Upload Rocky Linux 8 overcloud host image artifact
141-
run: |
142-
source venvs/kayobe/bin/activate &&
143-
source src/kayobe-config/kayobe-env --environment ci-builder &&
144-
kayobe playbook run \
145-
src/kayobe-config/etc/kayobe/ansible/pulp-host-image-upload.yml \
146-
-e image_path='/opt/kayobe/images/overcloud-rocky-linux-8' \
147-
-e os_distribution='rocky'
148-
-e os_release='8' \
149-
env:
150-
KAYOBE_VAULT_PASSWORD: ${{ secrets.KAYOBE_VAULT_PASSWORD }}
151-
if: inputs.rocky8
152-
153-
- name: Build a Rocky Linux 9 overcloud host image
207+
- name: Build an overcloud host image
154208
run: |
155209
source venvs/kayobe/bin/activate &&
156210
source src/kayobe-config/kayobe-env --environment ci-builder &&
157211
kayobe overcloud host image build --force-rebuild \
158-
-e os_distribution=rocky \
159-
-e os_release='9' \
160-
-e stackhpc_overcloud_dib_name=overcloud-rocky-linux-9
212+
-e os_distribution=${{ matrix.os_distribution }} \
213+
-e os_release="${{ matrix.os_release }}" \
214+
-e stackhpc_overcloud_dib_name=overcloud-${{ matrix.os_distribution }}-"${{ matrix.os_release }}"
161215
env:
162216
KAYOBE_VAULT_PASSWORD: ${{ secrets.KAYOBE_VAULT_PASSWORD }}
163-
if: inputs.rocky9
164217

165-
- name: Upload Rocky Linux 9 overcloud host image artifact
218+
- name: Upload overcloud host image artifact
166219
run: |
167220
source venvs/kayobe/bin/activate &&
168221
source src/kayobe-config/kayobe-env --environment ci-builder &&
169222
kayobe playbook run \
170223
src/kayobe-config/etc/kayobe/ansible/pulp-host-image-upload.yml \
171-
-e image_path='/opt/kayobe/images/overcloud-rocky-linux-9' \
172-
-e os_distribution='rocky' \
173-
-e os_release='9'
224+
-e image_path=/opt/kayobe/images/overcloud-${{ matrix.os_distribution }}-"${{ matrix.os_release }}" \
225+
-e host_image_tag=${{ needs.generate-tag.outputs.host_image_tag }} \
226+
-e os_distribution=${{ matrix.os_distribution }} \
227+
-e os_release="${{ matrix.os_release }}"
174228
env:
175229
KAYOBE_VAULT_PASSWORD: ${{ secrets.KAYOBE_VAULT_PASSWORD }}
176-
if: inputs.rocky9
177-
178-
# FIXME: Need EPEL on CentOS for debootstrap. It is disabled by default.
179-
# Do this via config?
180-
- name: Enable EPEL repository
181-
run: |
182-
sudo dnf config-manager --set-enabled epel
183-
184-
- name: Build a Ubuntu Focal 20.04 overcloud host image
185-
run: |
186-
source venvs/kayobe/bin/activate &&
187-
source src/kayobe-config/kayobe-env --environment ci-builder &&
188-
kayobe overcloud host image build --force-rebuild \
189-
-e os_distribution=ubuntu \
190-
-e os_release=focal \
191-
-e stackhpc_overcloud_dib_name=overcloud-ubuntu-focal
192-
env:
193-
KAYOBE_VAULT_PASSWORD: ${{ secrets.KAYOBE_VAULT_PASSWORD }}
194-
if: inputs.ubuntu-focal
195-
196-
- name: Upload Ubuntu Focal 20.04 overcloud host image artifact
197-
run: |
198-
source venvs/kayobe/bin/activate &&
199-
source src/kayobe-config/kayobe-env --environment ci-builder &&
200-
kayobe playbook run \
201-
src/kayobe-config/etc/kayobe/ansible/pulp-host-image-upload.yml \
202-
-e image_path='/opt/kayobe/images/overcloud-ubuntu-focal' \
203-
-e os_distribution='ubuntu' \
204-
-e os_release=focal
205-
env:
206-
KAYOBE_VAULT_PASSWORD: ${{ secrets.KAYOBE_VAULT_PASSWORD }}
207-
if: inputs.ubuntu-focal
208-
209-
- name: Build a Ubuntu Jammy 22.04 overcloud host image
210-
run: |
211-
source venvs/kayobe/bin/activate &&
212-
source src/kayobe-config/kayobe-env --environment ci-builder &&
213-
kayobe overcloud host image build --force-rebuild \
214-
-e os_distribution=ubuntu \
215-
-e os_release=jammy \
216-
-e stackhpc_overcloud_dib_name=overcloud-ubuntu-jammy
217-
env:
218-
KAYOBE_VAULT_PASSWORD: ${{ secrets.KAYOBE_VAULT_PASSWORD }}
219-
if: inputs.ubuntu-jammy
220-
221-
- name: Upload Ubuntu Jammy 22.04 overcloud host image artifact
222-
run: |
223-
source venvs/kayobe/bin/activate &&
224-
source src/kayobe-config/kayobe-env --environment ci-builder &&
225-
kayobe playbook run \
226-
src/kayobe-config/etc/kayobe/ansible/pulp-host-image-upload.yml \
227-
-e image_path='/opt/kayobe/images/overcloud-ubuntu-jammy' \
228-
-e os_distribution='ubuntu' \
229-
-e os_release=jammy
230-
env:
231-
KAYOBE_VAULT_PASSWORD: ${{ secrets.KAYOBE_VAULT_PASSWORD }}
232-
if: inputs.ubuntu-jammy
233-
234-
- name: Upload updated images artifact
235-
uses: actions/upload-artifact@v3
236-
with:
237-
name: Updated images list
238-
path: /tmp/updated_images.txt
239-
retention-days: 7
240-
if: always()
241-
242-
- name: Clean up old images
243-
run: |
244-
sudo rm -rf /opt/kayobe/images/
245-
if: always()

etc/kayobe/ansible/pulp-host-image-upload.yml

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
repository_name: "kayobe-images-{{ openstack_release }}-{{ os_distribution }}-{{ os_release }}"
99
base_path: "kayobe-images/{{ openstack_release }}/{{ os_distribution }}/{{ os_release }}"
1010
tasks:
11+
- name: Print image tag
12+
debug:
13+
msg: "Image tag: {{ host_image_tag }}"
14+
1115
- name: Get filename
1216
find:
1317
paths: "{{ image_path }}"
@@ -81,29 +85,26 @@
8185
pulp_url: "{{ remote_pulp_url }}"
8286
username: "{{ remote_pulp_username }}"
8387
password: "{{ remote_pulp_password }}"
84-
name: "{{ repository_name }}_{{ ansible_facts.date_time.iso8601_basic_short }}"
85-
base_path: "{{ base_path }}/{{ ansible_facts.date_time.iso8601_basic_short }}"
88+
name: "{{ repository_name }}_{{ host_image_tag }}"
89+
base_path: "{{ base_path }}/{{ host_image_tag }}"
8690
publication: "{{ publication_details.publication.pulp_href }}"
8791
content_guard: development
8892
state: present
8993
when: latest_distribution_details.changed
9094

91-
- name: Update new images file with versioned path
92-
lineinfile:
93-
path: /tmp/updated_images.txt
94-
line: "{{ remote_pulp_url }}/pulp/content/{{ base_path }}/\
95-
{{ ansible_facts.date_time.iso8601_basic_short }}/{{ found_files.files[0].path | basename }}"
96-
create: true
95+
- name: Print versioned path
96+
debug:
97+
msg: "New versioned path: {{ remote_pulp_url }}/pulp/content/{{ base_path }}/\
98+
{{ host_image_tag }}/{{ found_files.files[0].path | basename }}"
9799
when: latest_distribution_details.changed
98100

99-
- name: Update new images file with latest path
100-
lineinfile:
101-
path: /tmp/updated_images.txt
102-
line: "{{ remote_pulp_url }}/pulp/content/{{ base_path }}/\
101+
- name: Print latest path
102+
debug:
103+
msg: "New latest path: {{ remote_pulp_url }}/pulp/content/{{ base_path }}/\
103104
latest/{{ found_files.files[0].path | basename }}"
104105
when: latest_distribution_details.changed
105106

106107
- name: Print version tag
107108
debug:
108-
msg: "New tag: {{ ansible_facts.date_time.iso8601_basic_short }}"
109+
msg: "New tag: {{ host_image_tag }}"
109110
when: latest_distribution_details.changed

etc/kayobe/environments/ci-builder/stackhpc-ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,7 @@ stackhpc_docker_registry_password: !vault |
103103
34386133383366326639353432386235336132663839333337323739633434613934346462363031
104104
3265323831663964360a643962346231386462323236373963633066393736323234303833363535
105105
3664
106+
107+
# Username and password of the overcloud host image repository.
108+
stackhpc_image_repository_username: "{{ stackhpc_docker_registry_username }}"
109+
stackhpc_image_repository_password: "{{ stackhpc_docker_registry_password }}"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
upgrade:
3+
- |
4+
Host images are now built in a matrix. Host images built in the same
5+
workflow will have the same tag.

0 commit comments

Comments
 (0)