-
Notifications
You must be signed in to change notification settings - Fork 0
225 lines (215 loc) · 8.5 KB
/
single-node-guided.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
name: Sunbeam Single-node guided
on:
#push:
#branches: ["act"]
workflow_dispatch:
inputs:
hardware_profile:
description: 'Specs for each machine'
required: true
default: tutorial
type: choice
options:
- tutorial
permissions:
contents: read
env:
COLUMNS: 160 # default: 80
DEBIAN_FRONTEND: noninteractive
HARDWARE_PROFILE: ${{ inputs.hardware_profile || 'tutorial' }}
defaults:
run:
# act doesn't show a good summary of elapsed time of each step
shell: /usr/bin/time -f 'step: real\t%E' /bin/bash -ex {0}
jobs:
actionlint:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- name: Download actionlint
if: ${{ !env.ACT }}
id: get_actionlint
run: bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash)
- name: Check workflow files
run: |
# use a local binary if env.ACT
${{ steps.get_actionlint.outputs.executable || 'actionlint' }} -color \
.github/workflows/single-node-guided.yml
single-node-guided-tutorial:
name: Single-node Guided Tutorial
runs-on: ubuntu-24.04
needs: actionlint
steps:
- uses: actions/checkout@v4
- name: Set env
run: |
case "$HARDWARE_PROFILE" in
tutorial)
# https://canonical.com/microstack/docs/single-node-guided
echo CPU=4 >> "$GITHUB_ENV"
echo MEMORY=16 >> "$GITHUB_ENV"
echo DISK=100 >> "$GITHUB_ENV"
;;
*)
echo '::error:: Invalid hardware profile'
exit 1
;;
esac
# FIXME: use $GITHUB_STEP_SUMMARY
# shellcheck source=/dev/null
source "$GITHUB_ENV"
echo "::notice::Selected hardware profile: ${HARDWARE_PROFILE}.%0ACPU: ${CPU}%0AMEMORY: ${MEMORY}%0ADISK: ${DISK}"
- name: Check machine specs
run: |
# bare metal returns "none" with exit 1
systemd-detect-virt || true
cat /etc/os-release
lscpu
free -h
lsblk
lsblk -f
ip -br a
ip r
# resolvectl --no-pager
# TODO: check if greenfield or brownfield first
- name: Install prerequisites
if: ${{ !env.ACT }}
run: |
sudo apt-get update
sudo apt-get install -y uvtool j2cli
# make sure the default user is in the libvirt group.
# the "runner" user in Github workflow is not in the sudo
# group so it's not automatically added into the libvirt
# group.
sudo adduser "$USER" libvirt
- name: Download a VM image
if: ${{ !env.ACT }}
run: |
sudo -g libvirt uvt-simplestreams-libvirt sync release=noble arch=amd64
sudo -g libvirt uvt-simplestreams-libvirt query
- name: Prepare SSH, virtual network bridge, and virtual machines
if: ${{ !env.ACT }}
run: |
# SSH
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 -N ''
cat <<EOF | tee -a ~/.ssh/config
Host sunbeam-single-node-guided
User ubuntu
Hostname 192.168.124.6
EOF
# bridge
sudo -g libvirt virsh -c qemu:///system net-define /dev/stdin <<EOF
<network>
<name>sunbeam-virbr0</name>
<bridge name='sunbeam-virbr0' stp='off'/>
<forward mode='nat'/>
<ip address='192.168.124.1' netmask='255.255.255.0' />
</network>
EOF
sudo -g libvirt virsh -c qemu:///system net-autostart sunbeam-virbr0
sudo -g libvirt virsh -c qemu:///system net-start sunbeam-virbr0
- name: Clean up previous virtual machines
if: ${{ env.ACT }}
run: |
# FIXME: the requirement of FQDN is not documented well in each tutorial
sudo -g libvirt uvt-kvm destroy sunbeam-single-node-guided.localdomain || true
- name: Prepare a virtual machine
run: |
sudo -g libvirt uvt-kvm create \
--machine-type q35 \
--cpu "$CPU" \
--host-passthrough \
--memory "$((MEMORY * 1024))" \
--disk "$DISK" \
--unsafe-caching \
--bridge sunbeam-virbr0 \
--network-config /dev/stdin \
--ssh-public-key-file ~/.ssh/id_ed25519.pub \
--no-start \
sunbeam-single-node-guided.localdomain \
release=noble <<EOF
network:
version: 2
ethernets:
enp1s0:
dhcp4: false
dhcp6: false
accept-ra: false
addresses:
- 192.168.124.6/24
routes:
- to: default
via: 192.168.124.1
nameservers:
addresses:
- 192.168.124.1
EOF
# secondary NIC
sudo -g libvirt virsh -c qemu:///system attach-interface sunbeam-single-node-guided.localdomain \
network sunbeam-virbr0 \
--model virtio --config
sudo -g libvirt virsh -c qemu:///system start sunbeam-single-node-guided.localdomain
until ssh -oStrictHostKeyChecking=no sunbeam-single-node-guided -- 'cloud-init status --wait; ip -br a; lsblk'; do
sleep 5
done
- name: Sunbeam - Prepare manifest file
run: |
j2 -f yaml -o ./manifest.yaml .github/assets/workflows/single-node-guided/manifest.yaml.j2 - <<EOF
use_workaround: $USE_WORKAROUND
dockerhub_mirror_host: "${DOCKERHUB_MIRROR#http*://}"
EOF
scp ./manifest.yaml sunbeam-single-node-guided:
- name: Sunbeam - Prepare the machine
run: |
ssh sunbeam-single-node-guided -- sudo snap install openstack --channel 2024.1/edge
ssh sunbeam-single-node-guided -- 'sunbeam prepare-node-script --bootstrap | bash -x'
- name: Sunbeam - Bootstrap the cloud
run: |
# -t is necessary to see some progress in act env, LP:#2097451
# Also, without -t, somehow add-k8s command gets stuck in act env
# although it doesn't happen in GitHub runner.
# without -tt, GitHub runner's log should be quiet.
ssh sunbeam-single-node-guided -t -- sunbeam cluster bootstrap --manifest manifest.yaml
- name: Workaround - destroy localhost controller
run: |
# LP: #2095487
ssh sunbeam-single-node-guided -- juju destroy-controller localhost-localhost --no-prompt
- name: Workaround - enable debug logging
run: |
# LP: #2065490
ssh sunbeam-single-node-guided -- 'juju model-config -m admin/openstack-machines logging-config="<root>=INFO;unit=DEBUG"'
- name: Sunbeam - Configure the cloud
run: |
ssh sunbeam-single-node-guided -t -- sunbeam configure --openrc demo-openrc
- name: Sunbeam - Launch a VM
run: |
ssh sunbeam-single-node-guided -t -- sunbeam launch ubuntu --name test
- name: Sunbeam - Connect to the VM
run: |
# The cloud-init process inside the VM takes ~2 minutes to bring up the
# SSH service after the VM gets ACTIVE in OpenStack
sleep 5m
ssh sunbeam-single-node-guided -- '
set -ex
source demo-openrc
demo_floating_ip="$(openstack floating ip list -c Floating\ IP\ Address -f value | head -n1)"
ssh -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -i ~/snap/openstack/current/sunbeam "ubuntu@${demo_floating_ip}" -- cloud-init status --wait
'
- name: Smoke reboot testing
run: |
ssh sunbeam-single-node-guided -- sudo reboot
# wait some time to settle
sleep 10m
ssh sunbeam-single-node-guided -t -- '
set -ex
sunbeam launch ubuntu --name test-after-reboot
sleep 5m
source demo-openrc
ssh -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -i ~/snap/openstack/current/sunbeam -l ubuntu \
"$(openstack server show test-after-reboot --format yaml | grep -E -o 192\.168\.124\.[0-9]+)" -- cloud-init status --wait
'
- uses: actions/upload-artifact@v4
if: ${{ always() }}
with:
name: manifest.yaml
path: ./manifest.yaml