Skip to content

Commit f02678c

Browse files
committed
Add support for Amphora images in StackHPC Release Train
1 parent 1f73ff1 commit f02678c

File tree

6 files changed

+430
-28
lines changed

6 files changed

+430
-28
lines changed
Lines changed: 261 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,261 @@
1+
---
2+
name: Build Amphora image
3+
on:
4+
workflow_dispatch:
5+
secrets:
6+
KAYOBE_VAULT_PASSWORD:
7+
required: true
8+
CLOUDS_YAML:
9+
required: true
10+
OS_APPLICATION_CREDENTIAL_ID:
11+
required: true
12+
OS_APPLICATION_CREDENTIAL_SECRET:
13+
required: true
14+
15+
env:
16+
ANSIBLE_FORCE_COLOR: True
17+
KAYOBE_ENVIRONMENT: ci-builder
18+
KAYOBE_VAULT_PASSWORD: ${{ secrets.KAYOBE_VAULT_PASSWORD }}
19+
jobs:
20+
amphora-image-build:
21+
name: Build Amphora image
22+
if: github.repository == 'stackhpc/stackhpc-kayobe-config'
23+
runs-on: arc-skc-host-image-builder-runner
24+
permissions: {}
25+
steps:
26+
27+
- name: Install Package
28+
uses: ConorMacBride/install-package@main
29+
with:
30+
apt: git unzip nodejs python3-pip python3-venv openssh-server openssh-client jq
31+
32+
- name: Start the SSH service
33+
run: |
34+
sudo /etc/init.d/ssh start
35+
36+
- name: Checkout
37+
uses: actions/checkout@v4
38+
with:
39+
path: src/kayobe-config
40+
41+
- name: Output image tag of the builder
42+
id: builder_image_tag
43+
run: |
44+
echo image_tag=$(grep stackhpc_rocky_9_overcloud_host_image_version: etc/kayobe/pulp-host-image-versions.yml | awk '{print $2}') >> $GITHUB_OUTPUT
45+
46+
- name: Determine OpenStack release
47+
id: openstack_release
48+
run: |
49+
BRANCH=$(awk -F'=' '/defaultbranch/ {print $2}' src/kayobe-config/.gitreview)
50+
echo "BRANCH=$BRANCH" >> $GITHUB_OUTPUT
51+
echo "openstack_release=${BRANCH}" | sed -E "s,(stable|unmaintained)/,," >> $GITHUB_OUTPUT
52+
53+
# Generate a tag to apply to all built Amphora image.
54+
- name: Generate Amphora image tag
55+
id: image_tag
56+
run: |
57+
echo "image_tag=$(date +${{ steps.openstack_release.outputs.openstack_release }}-%Y%m%dT%H%M%S)" >> $GITHUB_OUTPUT
58+
59+
- name: Display Amphora image tag
60+
run: |
61+
echo "${{ steps.image_tag.outputs.image_tag }}"
62+
63+
- name: Install Kayobe
64+
run: |
65+
mkdir -p venvs &&
66+
pushd venvs &&
67+
python3 -m venv kayobe &&
68+
source kayobe/bin/activate &&
69+
pip install -U pip &&
70+
pip install -r ../src/kayobe-config/requirements.txt
71+
72+
- name: Install terraform
73+
uses: hashicorp/setup-terraform@v2
74+
75+
- name: Initialise terraform
76+
run: terraform init
77+
working-directory: ${{ github.workspace }}/src/kayobe-config/terraform/aio
78+
79+
- name: Generate SSH keypair
80+
run: ssh-keygen -f id_rsa -N ''
81+
working-directory: ${{ github.workspace }}/src/kayobe-config/terraform/aio
82+
83+
- name: Generate clouds.yaml
84+
run: |
85+
cat << EOF > clouds.yaml
86+
${{ secrets.CLOUDS_YAML }}
87+
EOF
88+
working-directory: ${{ github.workspace }}/src/kayobe-config/terraform/aio
89+
90+
- name: Generate terraform.tfvars
91+
run: |
92+
cat << EOF > terraform.tfvars
93+
ssh_public_key = "id_rsa.pub"
94+
ssh_username = "ubuntu"
95+
aio_vm_name = "skc-amphora-image-builder"
96+
# Must be an Ubuntu Jammy host to successfully build all images
97+
# This MUST NOT be an LVM image. It can cause confusing conficts with the built image.
98+
aio_vm_image = "Ubuntu-22.04"
99+
aio_vm_flavor = "en1.medium"
100+
aio_vm_network = "stackhpc-ci"
101+
aio_vm_subnet = "stackhpc-ci"
102+
aio_vm_interface = "ens3"
103+
EOF
104+
working-directory: ${{ github.workspace }}/src/kayobe-config/terraform/aio
105+
106+
- name: Terraform Plan
107+
run: terraform plan
108+
working-directory: ${{ github.workspace }}/src/kayobe-config/terraform/aio
109+
env:
110+
OS_CLOUD: "openstack"
111+
OS_APPLICATION_CREDENTIAL_ID: ${{ secrets.OS_APPLICATION_CREDENTIAL_ID }}
112+
OS_APPLICATION_CREDENTIAL_SECRET: ${{ secrets.OS_APPLICATION_CREDENTIAL_SECRET }}
113+
114+
- name: Terraform Apply
115+
run: |
116+
for attempt in $(seq 5); do
117+
if terraform apply -auto-approve; then
118+
echo "Created infrastructure on attempt $attempt"
119+
exit 0
120+
fi
121+
echo "Failed to create infrastructure on attempt $attempt"
122+
sleep 10
123+
terraform destroy -auto-approve
124+
sleep 60
125+
done
126+
echo "Failed to create infrastructure after $attempt attempts"
127+
exit 1
128+
working-directory: ${{ github.workspace }}/src/kayobe-config/terraform/aio
129+
env:
130+
OS_CLOUD: "openstack"
131+
OS_APPLICATION_CREDENTIAL_ID: ${{ secrets.OS_APPLICATION_CREDENTIAL_ID }}
132+
OS_APPLICATION_CREDENTIAL_SECRET: ${{ secrets.OS_APPLICATION_CREDENTIAL_SECRET }}
133+
134+
- name: Get Terraform outputs
135+
id: tf_outputs
136+
run: |
137+
terraform output -json
138+
working-directory: ${{ github.workspace }}/src/kayobe-config/terraform/aio
139+
140+
- name: Write Terraform outputs
141+
run: |
142+
cat << EOF > src/kayobe-config/etc/kayobe/environments/ci-builder/tf-outputs.yml
143+
${{ steps.tf_outputs.outputs.stdout }}
144+
EOF
145+
146+
- name: Write Terraform network config
147+
run: |
148+
cat << EOF > src/kayobe-config/etc/kayobe/environments/ci-builder/tf-network-allocation.yml
149+
---
150+
aio_ips:
151+
builder: "{{ access_ip_v4.value }}"
152+
EOF
153+
154+
- name: Write Terraform network interface config
155+
run: |
156+
mkdir -p src/kayobe-config/etc/kayobe/environments/$KAYOBE_ENVIRONMENT/inventory/group_vars/seed
157+
rm -f src/kayobe-config/etc/kayobe/environments/$KAYOBE_ENVIRONMENT/inventory/group_vars/seed/network-interfaces
158+
cat << EOF > src/kayobe-config/etc/kayobe/environments/$KAYOBE_ENVIRONMENT/inventory/group_vars/seed/network-interfaces
159+
admin_interface: "{{ access_interface.value }}"
160+
aio_interface: "{{ access_interface.value }}"
161+
EOF
162+
163+
- name: Manage SSH keys
164+
run: |
165+
mkdir -p ~/.ssh
166+
touch ~/.ssh/authorized_keys
167+
cat src/kayobe-config/terraform/aio/id_rsa.pub >> ~/.ssh/authorized_keys
168+
cp src/kayobe-config/terraform/aio/id_rsa* ~/.ssh/
169+
170+
- name: Bootstrap the control host
171+
run: |
172+
source venvs/kayobe/bin/activate &&
173+
source src/kayobe-config/kayobe-env --environment ci-builder &&
174+
kayobe control host bootstrap
175+
176+
- name: Configure the seed host (Builder VM)
177+
run: |
178+
source venvs/kayobe/bin/activate &&
179+
source src/kayobe-config/kayobe-env --environment ci-builder &&
180+
kayobe seed host configure -e seed_bootstrap_user=ubuntu --skip-tags network
181+
182+
- name: Install dependencies
183+
run: |
184+
source venvs/kayobe/bin/activate &&
185+
source src/kayobe-config/kayobe-env --environment ci-builder &&
186+
kayobe seed host command run \
187+
--command "sudo apt update && sudo apt -y install gcc git libffi-dev python3-dev python-is-python3 python3-venv" --show-output
188+
env:
189+
KAYOBE_VAULT_PASSWORD: ${{ secrets.KAYOBE_VAULT_PASSWORD }}
190+
191+
- name: Create Amphora image output directory
192+
run: |
193+
source venvs/kayobe/bin/activate &&
194+
source src/kayobe-config/kayobe-env --environment ci-builder &&
195+
kayobe seed host command run \
196+
--command "mkdir -p /opt/kayobe/images/amphora" --show-output
197+
env:
198+
KAYOBE_VAULT_PASSWORD: ${{ secrets.KAYOBE_VAULT_PASSWORD }}
199+
200+
- name: Build Octavia Amphora image
201+
id: build_amphora
202+
run: |
203+
source venvs/kayobe/bin/activate &&
204+
source src/kayobe-config/kayobe-env --environment ci-builder &&
205+
kayobe playbook run src/kayobe-config/etc/kayobe/ansible/octavia-amphora-image-build.yml -e amphora_image_dest=/opt/kayobe/images/amphora/amphora-x64-haproxy.qcow2
206+
env:
207+
KAYOBE_VAULT_PASSWORD: ${{ secrets.KAYOBE_VAULT_PASSWORD }}
208+
209+
- name: Show last error logs
210+
continue-on-error: true
211+
run: |
212+
source venvs/kayobe/bin/activate &&
213+
source src/kayobe-config/kayobe-env --environment ci-builder &&
214+
kayobe seed host command run --command "tail -200 /var/log/octavia-amphora-image-build.log" --show-output
215+
env:
216+
KAYOBE_VAULT_PASSWORD: ${{ secrets.KAYOBE_VAULT_PASSWORD }}
217+
if: steps.build_amphora.outcome == 'failure'
218+
219+
- name: Upload Octavia Amphora image to Ark
220+
run: |
221+
source venvs/kayobe/bin/activate &&
222+
source src/kayobe-config/kayobe-env --environment ci-builder &&
223+
kayobe playbook run \
224+
src/kayobe-config/etc/kayobe/ansible/pulp-artifact-upload.yml \
225+
-e artifact_path=/opt/kayobe/images/amphora \
226+
-e artifact_tag=${{ steps.image_tag.outputs.image_tag }} \
227+
-e file_regex="*.qcow2" \
228+
-e repository_name="amphora-images-${{ steps.openstack_release.outputs.openstack_release }}" \
229+
-e pulp_base_path="amphora-images/${{ steps.openstack_release.outputs.openstack_release }}"
230+
env:
231+
KAYOBE_VAULT_PASSWORD: ${{ secrets.KAYOBE_VAULT_PASSWORD }}
232+
if: steps.build_amphora.outcome == 'success'
233+
234+
- name: Copy logback
235+
continue-on-error: true
236+
run: |
237+
mkdir artifact
238+
scp stack@$(jq -r .access_ip_v4.value src/kayobe-config/etc/kayobe/environments/ci-builder/tf-outputs.yml):/var/log/octavia-amphora-image-build.log ./artifact
239+
if: always()
240+
241+
- name: Fail if Amphora image builds failed
242+
run: |
243+
echo "Builds failed. See workflow artifacts for details." &&
244+
exit 1
245+
if: steps.build_amphora.outcome == 'failure'
246+
247+
- name: Upload logs & image artifact
248+
uses: actions/upload-artifact@v4
249+
with:
250+
name: amphora-image-build-log
251+
path: ./artifact
252+
if: always()
253+
254+
- name: Destroy
255+
run: terraform destroy -auto-approve
256+
working-directory: ${{ github.workspace }}/src/kayobe-config/terraform/aio
257+
env:
258+
OS_CLOUD: openstack
259+
OS_APPLICATION_CREDENTIAL_ID: ${{ secrets.OS_APPLICATION_CREDENTIAL_ID }}
260+
OS_APPLICATION_CREDENTIAL_SECRET: ${{ secrets.OS_APPLICATION_CREDENTIAL_SECRET }}
261+
if: always()
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
name: Promote Amphora image
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
image_tag:
7+
description: Tag to promote
8+
type: string
9+
required: true
10+
env:
11+
ANSIBLE_FORCE_COLOR: True
12+
jobs:
13+
amphora-image-promote:
14+
name: Promote Amphora image
15+
if: github.repository == 'stackhpc/stackhpc-kayobe-config'
16+
runs-on: ubuntu-22.04
17+
steps:
18+
- uses: actions/checkout@v4
19+
with:
20+
path: src/kayobe-config
21+
22+
- name: Determine OpenStack release
23+
id: openstack_release
24+
run: |
25+
BRANCH=$(awk -F'=' '/defaultbranch/ {print $2}' .gitreview)
26+
echo "openstack_release=${BRANCH}" | sed -E "s,(stable|unmaintained)/,," >> $GITHUB_OUTPUT
27+
working-directory: src/kayobe-config
28+
29+
- name: Setup networking
30+
run: |
31+
if ! ip l show breth1 >/dev/null 2>&1; then
32+
sudo ip l add breth1 type bridge
33+
fi
34+
sudo ip l set breth1 up
35+
if ! ip a show breth1 | grep 192.168.33.3/24; then
36+
sudo ip a add 192.168.33.3/24 dev breth1
37+
fi
38+
if ! ip l show dummy1 >/dev/null 2>&1; then
39+
sudo ip l add dummy1 type dummy
40+
fi
41+
sudo ip l set dummy1 up
42+
sudo ip l set dummy1 master breth1
43+
44+
- name: Install Kayobe
45+
run: |
46+
mkdir -p venvs &&
47+
pushd venvs &&
48+
python3 -m venv kayobe &&
49+
source kayobe/bin/activate &&
50+
pip install -U pip &&
51+
pip install -r ../src/kayobe-config/requirements.txt
52+
53+
- name: Bootstrap the control host
54+
run: |
55+
source venvs/kayobe/bin/activate &&
56+
source src/kayobe-config/kayobe-env --environment ci-builder &&
57+
kayobe control host bootstrap
58+
59+
- name: Promote Amphora image artifact
60+
run: |
61+
source venvs/kayobe/bin/activate &&
62+
source src/kayobe-config/kayobe-env --environment ci-builder &&
63+
kayobe playbook run \
64+
src/kayobe-config/etc/kayobe/ansible/pulp-artifact-promote.yml \
65+
-e repository_name="amphora-${{ steps.openstack_release.outputs.openstack_release }}" \
66+
-e pulp_base_path="amphora/${{ steps.openstack_release.outputs.openstack_release }}"
67+
env:
68+
ARTIFACT_TAG: ${{ inputs.image_tag }}
69+
KAYOBE_VAULT_PASSWORD: ${{ secrets.KAYOBE_VAULT_PASSWORD }}

etc/kayobe/ansible/octavia-amphora-image-build.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
hosts: "{{ amphora_builder_group | default('seed') }}"
44
vars:
55
amphora_dib_upper_constraints_file: "{{ pip_upper_constraints_file }}"
6+
amphora_image_dest: "{{ image_cache_path }}/amphora-x64-haproxy-{{ openstack_release }}.qcow2"
67
tasks:
78
- name: Install EPEL
89
ansible.builtin.package:
@@ -15,21 +16,21 @@
1516
- name: Ensure packages are installed
1617
become: true
1718
vars:
19+
packages_common:
20+
- debootstrap
21+
- git
22+
- python3-venv
1823
packages_for_os_family:
1924
RedHat:
20-
- debootstrap
2125
- qemu-img
22-
- git
2326
- e2fsprogs
2427
- policycoreutils-python-utils
2528
- yum-utils
2629
Debian:
27-
- debootstrap
2830
- qemu-utils
29-
- git
3031
- kpartx
3132
ansible.builtin.package:
32-
name: "{{ packages_for_os_family[ansible_facts.os_family] }}"
33+
name: "{{ packages_common + packages_for_os_family[ansible_facts.os_family] }}"
3334

3435
- name: Create a temporary directory
3536
ansible.builtin.tempfile:
@@ -89,15 +90,15 @@
8990
- name: Create the Amphora image
9091
ansible.builtin.shell:
9192
cmd: >-
92-
source {{ venv_path }}/bin/activate &&
93+
. {{ venv_path }}/bin/activate &&
9394
./diskimage-create.sh -i ubuntu-minimal -s 3 -g {{ openstack_branch }} >> /var/log/octavia-amphora-image-build.log 2>&1
9495
chdir: "{{ src_path }}/diskimage-create"
9596
changed_when: true
9697

9798
- name: Copy image to image store
9899
ansible.builtin.copy:
99100
src: "{{ src_path }}/diskimage-create/amphora-x64-haproxy.qcow2"
100-
dest: "{{ image_cache_path }}/amphora-x64-haproxy-{{ openstack_release }}.qcow2"
101+
dest: "{{ amphora_image_dest }}"
101102
remote_src: true
102103
always:
103104
- name: Remove temporary files

0 commit comments

Comments
 (0)