Skip to content

Commit 22b24b2

Browse files
committed
Add support for Amphora images in StackHPC Release Train
1 parent 4f54036 commit 22b24b2

6 files changed

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

+8-6
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:
@@ -88,6 +89,7 @@
8889

8990
- name: Create the Amphora image
9091
ansible.builtin.shell:
92+
executable: /bin/bash
9193
cmd: >-
9294
source {{ venv_path }}/bin/activate &&
9395
./diskimage-create.sh -i ubuntu-minimal -s 3 -g {{ openstack_branch }} >> /var/log/octavia-amphora-image-build.log 2>&1
@@ -97,7 +99,7 @@
9799
- name: Copy image to image store
98100
ansible.builtin.copy:
99101
src: "{{ src_path }}/diskimage-create/amphora-x64-haproxy.qcow2"
100-
dest: "{{ image_cache_path }}/amphora-x64-haproxy-{{ openstack_release }}.qcow2"
102+
dest: "{{ amphora_image_dest }}"
101103
remote_src: true
102104
always:
103105
- name: Remove temporary files

0 commit comments

Comments
 (0)