From 3393d8f64991c669c02f1ec1a49225e628219f0c Mon Sep 17 00:00:00 2001 From: Alexandre Pujol Date: Tue, 18 Jul 2023 22:22:08 +0100 Subject: [PATCH] test: improve vm image generation --- tests/Makefile | 2 +- .../packer/init/archlinux-gnome.user-data.yml | 4 ++++ tests/packer/init/archlinux-kde.user-data.yml | 9 +++++--- tests/packer/init/clean.sh | 4 +++- tests/packer/init/init.sh | 3 ++- tests/packer/init/ubuntu-server.user-data.yml | 3 +++ tests/packer/main.pkr.hcl | 5 +++- tests/packer/src/monitors.xml | 23 +++++++++++++++++++ tests/packer/ubuntu.pkr.hcl | 2 +- 9 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 tests/packer/src/monitors.xml diff --git a/tests/Makefile b/tests/Makefile index 47a0b24e..7e4a440c 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -21,7 +21,7 @@ $(PACKERS): make --directory=../ package dist=${@} packer build -force -var version=${VERSION} \ -var disk_size=${disk} -var flavor="${flavor}" \ - -only=main.qemu.${@}-${flavor} packer/ + -only=qemu.${@}-${flavor} packer/ lint: @packer fmt packer/ diff --git a/tests/packer/init/archlinux-gnome.user-data.yml b/tests/packer/init/archlinux-gnome.user-data.yml index 96efe79f..97815bc7 100644 --- a/tests/packer/init/archlinux-gnome.user-data.yml +++ b/tests/packer/init/archlinux-gnome.user-data.yml @@ -1,6 +1,9 @@ #cloud-config hostname: ${hostname} +locale: en_IE +keyboard: + layout: ie ssh_pwauth: true users: @@ -45,6 +48,7 @@ packages: # Install Applications - firefox + - chromium - terminator runcmd: diff --git a/tests/packer/init/archlinux-kde.user-data.yml b/tests/packer/init/archlinux-kde.user-data.yml index fcd9a6ee..a466915a 100644 --- a/tests/packer/init/archlinux-kde.user-data.yml +++ b/tests/packer/init/archlinux-kde.user-data.yml @@ -1,6 +1,9 @@ #cloud-config hostname: ${hostname} +locale: en_IE +keyboard: + layout: ie ssh_pwauth: true users: @@ -38,14 +41,14 @@ packages: - networkmanager # Install Graphical Interface - - xorg-server - - plasma + - plasma-meta + - plasma-wayland-session - sddm - konsole - - kde-applications # Install Applications - firefox + - chromium - terminator runcmd: diff --git a/tests/packer/init/clean.sh b/tests/packer/init/clean.sh index 0e7b0856..8fe366d5 100644 --- a/tests/packer/init/clean.sh +++ b/tests/packer/init/clean.sh @@ -61,7 +61,9 @@ clean_arch() { _msg "Pacman clean configuration" pacman -Syu --noconfirm - pacman -Rsccn --noconfirm "$(pacman -Qdtq)" + pacman -Qdtq | while IFS='' read -r pkg; do + pacman -Rsccn --noconfirm "$pkg" + done pacman -Scc --noconfirm } diff --git a/tests/packer/init/init.sh b/tests/packer/init/init.sh index e51c74ac..a8075f30 100644 --- a/tests/packer/init/init.sh +++ b/tests/packer/init/init.sh @@ -17,6 +17,7 @@ readonly DISTRIBUTION main() { install -dm0750 -o "$SUDO_USER" -g "$SUDO_USER" "/home/$SUDO_USER/Projects/" "/home/$SUDO_USER/.config/" install -Dm0644 -o "$SUDO_USER" -g "$SUDO_USER" $SRC/.bash_aliases "/home/$SUDO_USER/.bash_aliases" + install -Dm0644 -o "$SUDO_USER" -g "$SUDO_USER" $SRC/monitors.xml "/home/$SUDO_USER/.config/monitors.xml" install -Dm0644 -o "$SUDO_USER" -g "$SUDO_USER" $SRC/htoprc "/home/$SUDO_USER/.config/htop/htoprc" install -Dm0644 $SRC/parser.conf /etc/apparmor/parser.conf install -Dm0644 $SRC/site.local /etc/apparmor.d/tunables/multiarch.d/site.local @@ -28,7 +29,7 @@ main() { debian | ubuntu) apt-get update -y apt-get install -y apparmor-profiles build-essential config-package-dev \ - debhelper devscripts htop qemu-guest-agent rsync vim + debhelper devscripts htop rsync vim dpkg -i $SRC/apparmor.d_*_all.deb ;; diff --git a/tests/packer/init/ubuntu-server.user-data.yml b/tests/packer/init/ubuntu-server.user-data.yml index 992c4bed..1e40f32d 100644 --- a/tests/packer/init/ubuntu-server.user-data.yml +++ b/tests/packer/init/ubuntu-server.user-data.yml @@ -1,6 +1,9 @@ #cloud-config hostname: ${hostname} +locale: en_IE +keyboard: + layout: ie ssh_pwauth: true users: diff --git a/tests/packer/main.pkr.hcl b/tests/packer/main.pkr.hcl index b039a8a5..ca198342 100644 --- a/tests/packer/main.pkr.hcl +++ b/tests/packer/main.pkr.hcl @@ -3,7 +3,6 @@ # SPDX-License-Identifier: GPL-2.0-only build { - name = "main" sources = [ "source.qemu.archlinux-gnome", "source.qemu.archlinux-kde", @@ -12,6 +11,7 @@ build { "source.qemu.ubuntu-server", ] + # Upload local files provisioner "file" { destination = "/tmp" sources = ["${path.cwd}/packer/src"] @@ -29,6 +29,7 @@ build { sources = ["${path.cwd}/../apparmor.d_${var.version}_all.deb"] } + # Wait for cloud-init to finish provisioner "shell" { execute_command = "echo '${var.password}' | sudo -S sh -c '{{ .Vars }} {{ .Path }}'" inline = [ @@ -37,11 +38,13 @@ build { ] } + # Install local files and config provisioner "shell" { script = "${path.cwd}/packer/init/init.sh" execute_command = "echo '${var.password}' | sudo -S sh -c '{{ .Vars }} {{ .Path }}'" } + # Minimize the image provisioner "shell" { script = "${path.cwd}/packer/init/clean.sh" execute_command = "echo '${var.password}' | sudo -S sh -c '{{ .Vars }} {{ .Path }}'" diff --git a/tests/packer/src/monitors.xml b/tests/packer/src/monitors.xml new file mode 100644 index 00000000..b1713658 --- /dev/null +++ b/tests/packer/src/monitors.xml @@ -0,0 +1,23 @@ + + + + 0 + 0 + 1 + yes + + + Virtual-1 + RHT + QEMU Monitor + 0x00000000 + + + 1920 + 1080 + 60 + + + + + diff --git a/tests/packer/ubuntu.pkr.hcl b/tests/packer/ubuntu.pkr.hcl index 40536dfc..5c5355a7 100644 --- a/tests/packer/ubuntu.pkr.hcl +++ b/tests/packer/ubuntu.pkr.hcl @@ -22,7 +22,7 @@ source "qemu" "ubuntu-server" { output_directory = "${var.output}/" vm_name = "${var.prefix}${source.name}.qcow2" boot_wait = "10s" - firmware = "/usr/share/edk2-ovmf/x64/OVMF_CODE.fd" + firmware = "${var.firmware}" shutdown_command = "echo ${var.password} | sudo -S /sbin/shutdown -hP now" cd_label = "cidata" cd_content = {