Skip to content

Commit

Permalink
added arm support
Browse files Browse the repository at this point in the history
  • Loading branch information
fspv committed Dec 16, 2024
1 parent 1cbfd9a commit 2a281a5
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 66 deletions.
53 changes: 42 additions & 11 deletions .github/workflows/vagrant-up.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,27 @@ jobs:
run: sudo apt-get update

- name: install packages
run: sudo apt install -y virtualbox virtualbox-guest-utils virtualbox-guest-x11 vagrant git
run: sudo apt install -y virtualbox virtualbox-guest-utils virtualbox-guest-x11 vagrant git qemu-system libvirt-dev

- name: init submodules
run: git submodule update --init --recursive

- name: Show Vagrant version
run: VAGRANT_LOG=debug vagrant --version

- name: Install libvirt plugin
run: VAGRANT_LOG=debug vagrant plugin install vagrant-libvirt

vagrant-user:
runs-on: self-hosted

needs: vagrant-set-up
steps:
- name: Run vagrant user.yml
run: VAGRANT_LOG=debug vagrant --os=ubuntu/jammy64 --local --playbook=user.yml --headless up
run: VAGRANT_DEFAULT_PROVIDER=virtualbox VAGRANT_LOG=debug vagrant --os=ubuntu/jammy64 --local --playbook=user.yml --headless up

- name: Destroy vagrant user.yml
run: timeout -k 60 -s 9 60 vagrant destroy -f || true
run: VAGRANT_DEFAULT_PROVIDER=virtualbox timeout -k 60 -s 9 60 vagrant destroy -f || true
if: always()

- name: Destroy all virtualbox machines
Expand All @@ -52,10 +55,10 @@ jobs:
needs: vagrant-set-up
steps:
- name: Run vagrant common-desktop.yml
run: VAGRANT_LOG=debug vagrant --os=ubuntu/jammy64 --local --headless up
run: VAGRANT_DEFAULT_PROVIDER=virtualbox VAGRANT_LOG=debug vagrant --os=ubuntu/jammy64 --local --headless up

- name: Destroy vagrant common-desktop.yml
run: timeout -k 60 -s 9 60 vagrant destroy -f || true
run: VAGRANT_DEFAULT_PROVIDER=virtualbox timeout -k 60 -s 9 60 vagrant destroy -f || true
if: always()

- name: Destroy all virtualbox machines
Expand All @@ -68,10 +71,10 @@ jobs:
needs: vagrant-set-up
steps:
- name: Run vagrant common-minimal-desktop.yml
run: VAGRANT_LOG=debug vagrant --os=ubuntu/jammy64 --local --playbook=common-minimal-desktop.yml --headless up
run: VAGRANT_DEFAULT_PROVIDER=virtualbox VAGRANT_LOG=debug vagrant --os=ubuntu/jammy64 --local --playbook=common-minimal-desktop.yml --headless up

- name: Destroy vagrant common-minimal-desktop.yml
run: timeout -k 60 -s 9 60 vagrant destroy -f || true
run: VAGRANT_DEFAULT_PROVIDER=virtualbox timeout -k 60 -s 9 60 vagrant destroy -f || true
if: always()

- name: Destroy all virtualbox machines
Expand All @@ -84,10 +87,10 @@ jobs:
needs: vagrant-set-up
steps:
- name: Run vagrant user.yml
run: VAGRANT_LOG=debug vagrant --os=bento/ubuntu-24.04 --local --playbook=user.yml --headless up
run: VAGRANT_DEFAULT_PROVIDER=virtualbox VAGRANT_LOG=debug vagrant --os=bento/ubuntu-24.04 --local --playbook=user.yml --headless up

- name: Destroy vagrant user.yml
run: timeout -k 60 -s 9 60 vagrant destroy -f || true
run: VAGRANT_DEFAULT_PROVIDER=virtualbox timeout -k 60 -s 9 60 vagrant destroy -f || true
if: always()

- name: Destroy all virtualbox machines
Expand All @@ -100,12 +103,40 @@ jobs:
needs: vagrant-set-up
steps:
- name: Run vagrant common-desktop.yml
run: VAGRANT_LOG=debug vagrant --os=bento/ubuntu-24.04 --local --headless up
run: VAGRANT_DEFAULT_PROVIDER=virtualbox VAGRANT_LOG=debug vagrant --os=bento/ubuntu-24.04 --local --headless up

- name: Destroy vagrant common-desktop.yml
run: timeout -k 60 -s 9 60 vagrant destroy -f || true
run: VAGRANT_DEFAULT_PROVIDER=virtualbox timeout -k 60 -s 9 60 vagrant destroy -f || true
if: always()

- name: Destroy all virtualbox machines
run: VBoxManage list vms | awk -F'"' '/.*ansible-playbooks.*/ {print $2}' | xargs -I {} VBoxManage unregistervm {} --delete
if: always()

vagrant-common-devserver-2404:
runs-on: self-hosted

needs: vagrant-set-up
steps:
- name: Run vagrant common-devserver.yml
run: VAGRANT_DEFAULT_PROVIDER=virtualbox VAGRANT_LOG=debug vagrant --os=bento/ubuntu-24.04 --local --playbook=common-devserver.yml --headless up

- name: Destroy vagrant common-devserver.yml
run: VAGRANT_DEFAULT_PROVIDER=virtualbox timeout -k 60 -s 9 60 vagrant destroy -f || true
if: always()

- name: Destroy all virtualbox machines
run: VBoxManage list vms | awk -F'"' '/.*ansible-playbooks.*/ {print $2}' | xargs -I {} VBoxManage unregistervm {} --delete
if: always()

vagrant-common-devserver-2404-arm64:
runs-on: self-hosted

needs: vagrant-set-up
steps:
- name: Run vagrant common-devserver.yml
run: VAGRANT_DEFAULT_PROVIDER=libvirt VAGRANT_LOG=debug vagrant --os=cloud-image/ubuntu-24.04 --local --playbook=common-devserver.yml --headless up

- name: Destroy vagrant common-devserver.yml
run: VAGRANT_DEFAULT_PROVIDER=libvirt timeout -k 60 -s 9 60 vagrant destroy -f || true
if: always()
52 changes: 50 additions & 2 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@ opts = GetoptLong.new(
["--local", GetoptLong::NO_ARGUMENT],
["--headless", GetoptLong::NO_ARGUMENT],
["--playbook", GetoptLong::OPTIONAL_ARGUMENT],
["--architecture", GetoptLong::OPTIONAL_ARGUMENT],
["--os", GetoptLong::OPTIONAL_ARGUMENT],
["-f", GetoptLong::OPTIONAL_ARGUMENT]
["-f", GetoptLong::OPTIONAL_ARGUMENT],
# Pass arguments to actual vagrant, but they're not used here
["--provider", GetoptLong::OPTIONAL_ARGUMENT],
["--help", GetoptLong::OPTIONAL_ARGUMENT],
["--debug", GetoptLong::OPTIONAL_ARGUMENT]
)

local = false
gui = true
os = "ubuntu/focal64"
playbook = "common-desktop.yml"
architecture = "amd64"

opts.each do |opt, arg|
case opt
Expand All @@ -26,30 +32,68 @@ opts.each do |opt, arg|
gui = false
when "--playbook"
playbook = arg
when "--architecture"
architecture = arg
end
end

# Example:
# * vagrant --os=ubuntu/jammy64 --playbook=user.yml --local --headless up
# * vagrant --os=bento/ubuntu-24.04 --playbook=common-desktop.yml --local up
# * vagrant --os=cloud-image/ubuntu-24.04 --local --headless --architecture=arm64 up --provider libvirt
#
# Known problems:
# * Sometimes disk fails to set up (systemd waits on disk uuid), `vagrant destroy` and try again in this case


Vagrant.configure("2") do |config|
if architecture == "arm64"
config.vagrant.plugins = "vagrant-libvirt"
config.vm.box_architecture = architecture
end
config.vm.synced_folder ".", "/vagrant"

# https://developer.hashicorp.com/vagrant/docs/vagrantfile/machine_settings
config.vm.box = os
config.vm.boot_timeout = 600

# Need to run `vagrant provision` explicitly for that to work
config.trigger.after [:provision] do |trigger|
trigger.name = "Reboot after provisioning"
trigger.run = { :inline => "vagrant reload" }
end

# https://vagrant-libvirt.github.io/vagrant-libvirt/configuration.html
# Currently libvirt is only used for arm64. However, to destroy arm machines
# even if the architecture argument is not passed, we need to set all the
# libvirt options anyway, in particular to make this fix work
# https://github.com/vagrant-libvirt/vagrant-libvirt/pull/1329/files
config.vm.provider "libvirt" do |libvirt|
# Give more resources, OOMs by default
libvirt.memory = 8000
# Max 8 cores allowed for arm cpu
libvirt.cpus = [`nproc`.to_i, 8].min
libvirt.machine_type = "virt"
# https://libvirt.org/formatdomain.html
# In this mode, the cpu element describes the CPU that should be presented
# to the guest. This is the default when no mode attribute is specified.
# This mode makes it so that a persistent guest will see the same hardware
# no matter what host the guest is booted on.
libvirt.cpu_mode = "custom"
libvirt.cpu_model = "cortex-a57"
libvirt.driver = "qemu"
libvirt.machine_arch = "aarch64"
# Enable UEFI, refuses to work otherwise
libvirt.nvram = true
libvirt.loader = "/usr/share/AAVMF/AAVMF_CODE.no-secboot.fd"
# Errors otherwise
libvirt.inputs = []
end

config.vm.provider "virtualbox" do |vb|
# Give more resources, OOMs by default
vb.memory = 8000
vb.cpus = 8
vb.cpus = `nproc`.to_i

# Make UI fast
vb.gui = gui
Expand All @@ -66,6 +110,8 @@ Vagrant.configure("2") do |config|
config.vm.provision "shell", env: {}, inline: <<-SHELL
set -uex
systemctl disable systemd-networkd.service
rm -f /etc/resolv.conf
echo "nameserver 8.8.8.8" > /etc/resolv.conf
Expand Down Expand Up @@ -117,6 +163,8 @@ Vagrant.configure("2") do |config|
config.vm.provision "shell", env: {}, inline: <<-SHELL
set -uex
systemctl disable systemd-networkd.service
rm -f /etc/resolv.conf
echo "nameserver 8.8.8.8" > /etc/resolv.conf
Expand Down
3 changes: 1 addition & 2 deletions roles/common-tools/vars/Fedora.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
common_tools:
- libxml2
common_tools: []
9 changes: 1 addition & 8 deletions roles/common-tools/vars/Ubuntu.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,2 @@
---
common_tools:
- pgpgpg
- iputils-ping
- iputils-arping
- lm-sensors
- psensor
- fancontrol
- aptitude
common_tools: []
43 changes: 0 additions & 43 deletions roles/common-tools/vars/main.yml
Original file line number Diff line number Diff line change
@@ -1,48 +1,5 @@
common_tools:
- mc
- curl
- wget
- tcpdump
- strace
- ltrace
- htop
- iotop
- ngrep
- lsscsi
- lsof
- vnstat
- bash-completion
- parted
- gdisk
- tree
- telnet
- man-db
- inotify-tools
- rlwrap
- dmidecode
- iftop
- dnsutils
- atop
- vim
- neovim
- net-tools
- less
- sudo
- nasm
- mercurial
- fping
- kpartx
- powertop
- testdisk
- ebtables
- nmap
- ipython3
- mtr-tiny
- whois
- pciutils
- sysstat
- linux-tools-common
- tmux

common_tools_x86_64:
- syslinux
5 changes: 5 additions & 0 deletions roles/libvirtd/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- name: libvirtd restart
systemd:
name: libvirtd
state: restarted
daemon_reload: yes
9 changes: 9 additions & 0 deletions roles/libvirtd/tasks/configs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Fix error similar to this: https://old.reddit.com/r/virtualization/comments/mjm1ow/virtmanager_error_when_creating_vm_unable_to/
# TODO: figure out how to fix it correctly
- name: config disable apparmor for libvirt
lineinfile:
path: /etc/libvirt/qemu.conf
regexp: '.*security_driver.*'
line: 'security_driver = "none"'
notify:
- libvirtd restart
1 change: 1 addition & 0 deletions roles/libvirtd/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
- import_tasks: packages.yml
- import_tasks: configs.yml
- import_tasks: services.yml

0 comments on commit 2a281a5

Please sign in to comment.