From 28515a5667939704eaa0266b00c4227136cf655c Mon Sep 17 00:00:00 2001 From: Nobuto Murata Date: Wed, 12 Feb 2025 11:09:40 +0900 Subject: [PATCH] draft for single-node-guided --- .../workflows/sunbeam-single-node-guided.yml | 210 ++++++++++++++++++ 1 file changed, 210 insertions(+) create mode 100644 .github/workflows/sunbeam-single-node-guided.yml diff --git a/.github/workflows/sunbeam-single-node-guided.yml b/.github/workflows/sunbeam-single-node-guided.yml new file mode 100644 index 0000000..66e9a73 --- /dev/null +++ b/.github/workflows/sunbeam-single-node-guided.yml @@ -0,0 +1,210 @@ +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 '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: ${{ steps.get_actionlint.outputs.executable || 'actionlint' }} -color + sunbeam-single-node-guided-tutorial: + name: Sunbeam 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=50 >> "$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 < + sunbeam-virbr0 + + + + + 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-machine-single-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 \ + single-node-guided.localdomain \ + release=noble <