Skip to content

Commit d22c4f2

Browse files
committed
refactor: separate the guest, hypervisor build, and setup actions
Preparing the nested test guest, building the hypervisor image, and booting the hypervisor pair are independent stages. Separating them lets another hypervisor build step reuse the same guest preparation and the same hypervisor boot sequence without duplicating or branching inside either stage. Each action now carries the tools and templates it consumes: build installs oras and butane, validates the tag it builds, renders its own domain XML, and hashes the password of the image it builds, while guest owns the seed files of the guest it prepares. Signed-off-by: Fabian Wiesel <fabian.wiesel@sap.com>
1 parent 2d5c860 commit d22c4f2

8 files changed

Lines changed: 135 additions & 156 deletions

File tree

‎.github/actions/test/integration/build/action.yml‎

Lines changed: 53 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@ inputs:
77
runs:
88
using: "composite"
99
steps:
10+
- name: Install oras
11+
uses: oras-project/setup-oras@5e2f2482b30b0cb3e14e67f89a80c88c659a7c63 # v2
12+
with:
13+
version: 1.2.2
14+
15+
- name: Install butane
16+
shell: bash
17+
run: |
18+
BUTANE_VERSION="0.24.0"
19+
curl -LO "https://github.com/coreos/butane/releases/download/v${BUTANE_VERSION}/butane-x86_64-unknown-linux-gnu"
20+
chmod +x "butane-x86_64-unknown-linux-gnu"
21+
sudo mv "butane-x86_64-unknown-linux-gnu" /usr/local/bin/butane
22+
1023
# TODO https://github.com/actions/cache
1124
- name: Set ENV
1225
shell: bash
@@ -21,6 +34,22 @@ runs:
2134
echo "ESP_SIZE=$ESP_SIZE" >> $GITHUB_ENV
2235
echo "DISK_SIZE=$DISK_SIZE" >> $GITHUB_ENV
2336
37+
- name: Validate image tag
38+
shell: bash
39+
run: |
40+
if [ -z "$TAG" ]; then
41+
echo "Error: image_tag is required"
42+
exit 1
43+
fi
44+
45+
echo "Verifying image $TAG exists in GHCR..."
46+
if ! digest=$(oras resolve "$REPO:$TAG" 2>&1); then
47+
echo "Error: Image tag '$TAG' not found in $REPO"
48+
echo "Resolve output: $digest"
49+
exit 1
50+
fi
51+
echo "Image tag present in GHCR (digest: ${digest:0:12}...)"
52+
2453
- name: Pull ORAS artifacts
2554
shell: bash
2655
run: |
@@ -96,16 +125,14 @@ runs:
96125
shell: bash
97126
run: |
98127
set -Eeuo pipefail
99-
ssh-keygen -t ed25519 -f "/opt/ssh_host_ed25519_key" -N "" -C "user" -q
100-
chmod 600 /opt/ssh_host_ed25519_key
101-
SSH_KEY=$(cat /opt/ssh_host_ed25519_key.pub)
102-
echo "SSH_KEY=$SSH_KEY" >> $GITHUB_ENV
103-
PASSWORD=$(openssl passwd "password")
104-
echo "PASSWORD=$PASSWORD" >> $GITHUB_ENV
105128
: "${SSH_KEY:?the shared test SSH key is not set}"
106-
: "${PASSWORD:?the guest password is not set}"
107129
: "${TAG:?the image tag is not set}"
108130
131+
# The hypervisor root password belongs to this image, so derive it here
132+
# instead of importing the one the nested guest uses.
133+
PASSWORD=$(openssl passwd "password")
134+
export PASSWORD
135+
109136
envsubst '${SSH_KEY} ${PASSWORD} ${TAG}' \
110137
< ./.github/actions/test/integration/build/dev-user-butane.yaml \
111138
> ./.github/actions/test/integration/build/dev-user-butane-hv1.yaml
@@ -117,29 +144,28 @@ runs:
117144
butane --pretty --strict ./.github/actions/test/integration/build/dev-user-butane-hv1.yaml > "/opt/${TAG}-hv1.ign"
118145
butane --pretty --strict ./.github/actions/test/integration/build/dev-user-butane-hv2.yaml > "/opt/${TAG}-hv2.ign"
119146
120-
- name: Download ubuntu cloud image
121-
shell: bash
122-
run: |
123-
wget -q "https://cloud-images.ubuntu.com/minimal/releases/noble/release/ubuntu-24.04-minimal-cloudimg-amd64.img" -O /opt/ubuntu.qcow2
124-
125-
- name: Generate raw ubuntu image for CHV
126-
shell: bash
127-
run: |
128-
qemu-img convert -p -f qcow2 -O raw /opt/ubuntu.qcow2 /opt/ubuntu.raw
129-
130-
- name: Generate ubuntu cloud-init
147+
- name: Prepare the HyperVisor directory
131148
shell: bash
132149
run: |
133150
set -Eeuo pipefail
134-
: "${SSH_KEY:?the shared test SSH key is not set}"
135-
: "${PASSWORD:?the guest password is not set}"
136-
137-
RENDER_DIR=$(mktemp -d)
138-
trap 'rm -rf "$RENDER_DIR"' EXIT
139-
envsubst '${SSH_KEY} ${PASSWORD}' \
140-
< ./.github/actions/test/integration/build/user-data \
141-
> "$RENDER_DIR/user-data"
142-
genisoimage -output /opt/ubuntu-cloud-init-ds.iso -volid cidata -joliet -rock ./.github/actions/test/integration/build/meta-data "$RENDER_DIR/user-data"
151+
HV_DIR=/opt/hv
152+
KEY=/opt/ssh_host_ed25519_key
153+
[ -s "$KEY" ] || { echo "the shared test SSH key is missing: $KEY" >&2; exit 1; }
154+
155+
install -d "$HV_DIR"
156+
sudo install -m 0644 "/opt/${TAG}.qcow2" /var/lib/libvirt/images/HV1.qcow2
157+
sudo install -m 0644 "/opt/${TAG}.qcow2" /var/lib/libvirt/images/HV2.qcow2
158+
sudo install -m 0644 "/opt/${TAG}-hv1.ign" /var/lib/libvirt/images/HV1.ign
159+
sudo install -m 0644 "/opt/${TAG}-hv2.ign" /var/lib/libvirt/images/HV2.ign
160+
161+
render_hv() {
162+
local name=$1 mac=$2
163+
HV_NAME=$name MAC=$mac NETWORK=${HV_NETWORK:-default} \
164+
envsubst '${HV_NAME} ${MAC} ${NETWORK}' \
165+
< ./.github/actions/test/integration/build/hv.xml > "$HV_DIR/$name.xml"
166+
}
167+
render_hv HV1 52:54:00:12:34:56
168+
render_hv HV2 52:54:00:65:43:21
143169
144170
# - name: Upload artifacts
145171
# uses: actions/upload-artifact@v4

.github/actions/test/integration/setup/hv.xml renamed to .github/actions/test/integration/build/hv.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
</disk>
2020
<interface type='network'>
2121
<mac address='${MAC}' />
22-
<source network='default' />
22+
<source network='${NETWORK}' />
2323
<model type='virtio' />
2424
</interface>
2525
<console type='pty'>

‎.github/actions/test/integration/dependencies/action.yml‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,3 @@ runs:
3232
shell: bash
3333
run: |
3434
if [ -e /dev/kvm ]; then sudo chmod 666 /dev/kvm; fi
35-
36-
- name: oras
37-
uses: oras-project/setup-oras@1d808f7d7f6995cc68b7bf507bfe5c5446e1dc9d # v2
38-
with:
39-
version: 1.2.2
40-
41-
- name: butane
42-
shell: bash
43-
run: |
44-
BUTANE_VERSION="0.24.0"
45-
curl -LO "https://github.com/coreos/butane/releases/download/v${BUTANE_VERSION}/butane-x86_64-unknown-linux-gnu"
46-
chmod +x "butane-x86_64-unknown-linux-gnu"
47-
sudo mv "butane-x86_64-unknown-linux-gnu" /usr/local/bin/butane
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: guest
2+
description: Build the Ubuntu test guest and the shared test SSH identity
3+
runs:
4+
using: "composite"
5+
steps:
6+
- name: Generate test SSH key and password
7+
shell: bash
8+
run: |
9+
ssh-keygen -t ed25519 -f "/opt/ssh_host_ed25519_key" -N "" -C "user" -q
10+
chmod 600 /opt/ssh_host_ed25519_key
11+
SSH_KEY=$(cat /opt/ssh_host_ed25519_key.pub)
12+
echo "SSH_KEY=$SSH_KEY" >> $GITHUB_ENV
13+
PASSWORD=$(openssl passwd "password")
14+
echo "PASSWORD=$PASSWORD" >> $GITHUB_ENV
15+
16+
- name: Download ubuntu cloud image
17+
shell: bash
18+
run: |
19+
wget -q "https://cloud-images.ubuntu.com/minimal/releases/noble/release/ubuntu-24.04-minimal-cloudimg-amd64.img" -O /opt/ubuntu.qcow2
20+
21+
- name: Generate raw ubuntu image for CHV
22+
shell: bash
23+
run: |
24+
qemu-img convert -p -f qcow2 -O raw /opt/ubuntu.qcow2 /opt/ubuntu.raw
25+
26+
- name: Generate ubuntu cloud-init
27+
shell: bash
28+
run: |
29+
set -Eeuo pipefail
30+
: "${SSH_KEY:?the shared test SSH key is not set}"
31+
: "${PASSWORD:?the guest password is not set}"
32+
33+
RENDER_DIR=$(mktemp -d)
34+
trap 'rm -rf "$RENDER_DIR"' EXIT
35+
envsubst '${SSH_KEY} ${PASSWORD}' \
36+
< ./.github/actions/test/integration/guest/user-data \
37+
> "$RENDER_DIR/user-data"
38+
genisoimage -output /opt/ubuntu-cloud-init-ds.iso -volid cidata -joliet -rock ./.github/actions/test/integration/guest/meta-data "$RENDER_DIR/user-data"
File renamed without changes.
File renamed without changes.

‎.github/actions/test/integration/setup/action.yml‎

Lines changed: 41 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,17 @@ runs:
2323
EOF
2424
chmod 600 ~/.ssh/config
2525
26-
- name: Configure the default libvirt network
26+
- name: Boot the HyperVisors and configure the guests
2727
shell: bash
2828
run: |
29+
set -Eeuo pipefail
30+
HV_DIR=/opt/hv
31+
KEY=/opt/ssh_host_ed25519_key
32+
[ -s "$KEY" ] && [ -f "$KEY" ] \
33+
|| { echo "the shared test SSH key is missing: $KEY" >&2; exit 1; }
34+
[ -s "$HV_DIR/HV1.xml" ] && [ -s "$HV_DIR/HV2.xml" ] \
35+
|| { echo "the hypervisor directory lacks HV1.xml or HV2.xml: $HV_DIR" >&2; exit 1; }
36+
2937
NETWORK=${HV_NETWORK:-default}
3038
3139
# virsh net-info also succeeds for a defined network that is inactive,
@@ -46,108 +54,44 @@ runs:
4654
exit 1
4755
fi
4856
fi
49-
50-
# virbr-hv.xml carries the two reservations, but a pre-existing network
51-
# was never defined from it. Restore them by MAC, so a rerun adds none.
5257
add_host() {
5358
sudo virsh net-dumpxml "$NETWORK" | grep -q "mac='$1'" \
5459
|| sudo virsh net-update "$NETWORK" add ip-dhcp-host "<host mac='$1' ip='$2' name='$3'/>" --live --config
5560
}
5661
add_host 52:54:00:12:34:56 192.168.122.2 hv1
5762
add_host 52:54:00:65:43:21 192.168.122.3 hv2
5863
59-
- name: Copy ignition file
60-
shell: bash
61-
run: |
62-
set -Eeuo pipefail
63-
: "${TAG:?the image tag is not set}"
64-
sudo cp "/opt/${TAG}-hv1.ign" /var/lib/libvirt/images/HV1.ign
65-
sudo cp "/opt/${TAG}-hv2.ign" /var/lib/libvirt/images/HV2.ign
66-
67-
- name: Create HyperVisor 1
68-
shell: bash
69-
run: |
70-
set -Eeuo pipefail
71-
: "${TAG:?the image tag is not set}"
72-
HV_NAME=HV1 MAC=52:54:00:12:34:56 envsubst '${HV_NAME} ${MAC}' \
73-
< ./.github/actions/test/integration/setup/hv.xml \
74-
> ./.github/actions/test/integration/setup/hv1.xml
75-
sudo cp "/opt/${TAG}.qcow2" /var/lib/libvirt/images/HV1.qcow2
76-
77-
sudo virsh define ./.github/actions/test/integration/setup/hv1.xml
78-
sudo virsh start HV1
79-
80-
- name: Create HyperVisor 2
81-
shell: bash
82-
run: |
64+
# The runner home ships as 750; qemu must traverse it to reach the disks.
65+
sudo chmod o+x "$HOME"
66+
67+
for spec in "HV1 192.168.122.2" "HV2 192.168.122.3"; do
68+
set -- $spec
69+
name=$1
70+
ip=$2
71+
sudo virsh dominfo "$name" >/dev/null 2>&1 && { echo "refusing to replace a pre-existing domain: $name" >&2; exit 1; }
72+
sudo virsh define "$HV_DIR/$name.xml"
73+
sudo virsh start "$name"
74+
for ((t=1; t<=60; t++)); do
75+
ssh "$ip" true 2>/dev/null && break
76+
[ "$t" -lt 60 ] || { echo "timeout waiting for $name to respond to SSH" >&2; sudo cat "/var/log/$name.log" || true; exit 1; }
77+
sleep 5
78+
done
79+
scp -q "$KEY" "$ip:/opt/ssh_host_ed25519_key"
80+
scp -q "$HOME/.ssh/config" "$ip:/root/.ssh/config"
81+
scp -q ./.github/actions/test/integration/setup/virbr-vm.xml "$ip:/opt/virbr-vm.xml"
82+
ssh "$ip" "bash -s" <<'EOF'
8383
set -Eeuo pipefail
84-
: "${TAG:?the image tag is not set}"
85-
HV_NAME=HV2 MAC=52:54:00:65:43:21 envsubst '${HV_NAME} ${MAC}' \
86-
< ./.github/actions/test/integration/setup/hv.xml \
87-
> ./.github/actions/test/integration/setup/hv2.xml
88-
sudo cp "/opt/${TAG}.qcow2" /var/lib/libvirt/images/HV2.qcow2
89-
90-
sudo virsh define ./.github/actions/test/integration/setup/hv2.xml
91-
sudo virsh start HV2
92-
93-
- name: Configure SSH and libvirt on HyperVisors
94-
shell: bash
95-
run: |
96-
MAX_ITER=30
97-
98-
setup_hv() {
99-
local IP="$1"
100-
101-
# Configure SSH between HyperVisors
102-
scp /opt/ssh_host_ed25519_key "$IP:/opt/ssh_host_ed25519_key"
103-
scp "$HOME/.ssh/config" "$IP:/root/.ssh/config"
104-
ssh "$IP" << EOF
105-
chmod 700 /root/.ssh
106-
chmod 600 /root/.ssh/config
107-
chmod 600 /opt/ssh_host_ed25519_key
84+
chmod 700 /root/.ssh
85+
chmod 600 /root/.ssh/config /opt/ssh_host_ed25519_key
86+
mkdir -p /var/log/libvirt/ch
87+
systemctl start libvirtd
88+
virsh pool-destroy default || true
89+
virsh pool-undefine default || true
90+
virsh pool-define-as default dir --target /var/lib/libvirt/images
91+
virsh pool-build default; virsh pool-start default; virsh pool-autostart default
92+
virsh net-destroy default || true
93+
virsh net-undefine default || true
94+
virsh net-define /opt/virbr-vm.xml
95+
virsh net-start default; virsh net-autostart default
10896
EOF
109-
110-
# Set up libvirt storage pool and network
111-
scp ./.github/actions/test/integration/setup/virbr-vm.xml "$IP:/opt/virbr-vm.xml"
112-
ssh "$IP" << EOF
113-
systemctl start libvirtd
114-
115-
virsh pool-destroy default || true
116-
virsh pool-undefine default || true
117-
virsh pool-define-as default dir --target /var/lib/libvirt/images
118-
virsh pool-build default
119-
virsh pool-start default
120-
virsh pool-autostart default
121-
122-
virsh net-destroy default || true
123-
virsh net-undefine default || true
124-
virsh net-define /opt/virbr-vm.xml
125-
virsh net-start default
126-
virsh net-autostart default
127-
EOF
128-
}
129-
130-
wait_for_ssh() {
131-
local VM_NAME="$1"
132-
133-
for ((i=1; i<=MAX_ITER; i++)); do
134-
local IP=$(sudo virsh domifaddr "$VM_NAME" | awk '/ipv4/ {print $4}' | cut -d'/' -f1)
135-
if [ -z "$IP" ]; then
136-
echo "No IP address found for $VM_NAME. Retrying..."
137-
elif ssh "$IP" 'exit' 2>/dev/null; then
138-
echo "$VM_NAME is up at IP: $IP"
139-
setup_hv "$IP"
140-
break
141-
fi
142-
if (( i == MAX_ITER )); then
143-
echo "Timeout waiting for $VM_NAME to respond to SSH."
144-
sudo cat "/var/log/$VM_NAME.log"
145-
exit 1
146-
fi
147-
echo "Waiting for $VM_NAME to respond to SSH... ($i/$MAX_ITER)"
148-
sleep 10
149-
done
150-
}
151-
152-
wait_for_ssh HV1
153-
wait_for_ssh HV2
97+
done

‎.github/workflows/test.yml‎

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,10 @@ jobs:
2222
steps:
2323
- name: Checkout
2424
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
25-
- name: Install oras
26-
uses: oras-project/setup-oras@5e2f2482b30b0cb3e14e67f89a80c88c659a7c63 # v2
27-
with:
28-
version: 1.2.2
29-
- name: Validate image tag
30-
run: |
31-
if [ -z "${{ inputs.image_tag }}" ]; then
32-
echo "Error: image_tag is required"
33-
exit 1
34-
fi
35-
36-
echo "Verifying image ${{ inputs.image_tag }} exists in GHCR..."
37-
if ! digest=$(oras resolve ghcr.io/gardenlinux/gardenlinux-sci:${{ inputs.image_tag }} 2>&1); then
38-
echo "Error: Image tag '${{ inputs.image_tag }}' not found in ghcr.io/gardenlinux/gardenlinux-sci"
39-
echo "Resolve output: $digest"
40-
exit 1
41-
fi
42-
echo "Image tag present in GHCR (digest: ${digest:0:12}...)"
4325
- name: Install Dependencies
4426
uses: ./.github/actions/test/integration/dependencies
27+
- name: Prepare the test guest
28+
uses: ./.github/actions/test/integration/guest
4529
- name: Build
4630
uses: ./.github/actions/test/integration/build
4731
with:

0 commit comments

Comments
 (0)