From 03b777340d4b17957c7533d20bc3f8fca5a6dff8 Mon Sep 17 00:00:00 2001 From: Alexandre Pujol Date: Sun, 6 Oct 2024 22:01:39 +0100 Subject: [PATCH] tests(packer): update & cleanup tests images. --- tests/Makefile | 2 +- tests/packer/archlinux.pkr.hcl | 80 +------------ tests/packer/builds.pkr.hcl | 30 +++-- tests/packer/debian.pkr.hcl | 86 +------------- .../packer/init/archlinux-xfce.user-data.yml | 92 +++++++++++++++ .../packer/init/opensuse-gnome.user-data.yml | 43 +++++++ ...ata.yml => ubuntu22-desktop.user-data.yml} | 0 ...ata.yml => ubuntu24-desktop.user-data.yml} | 20 ++-- ...data.yml => ubuntu24-server.user-data.yml} | 0 tests/packer/opensuse.pkr.hcl | 19 ++-- tests/packer/ubuntu.pkr.hcl | 106 +++--------------- tests/packer/variables.pkr.hcl | 16 +-- 12 files changed, 202 insertions(+), 292 deletions(-) create mode 100644 tests/packer/init/archlinux-xfce.user-data.yml create mode 100644 tests/packer/init/opensuse-gnome.user-data.yml rename tests/packer/init/{ubuntu-desktop.user-data.yml => ubuntu22-desktop.user-data.yml} (100%) rename tests/packer/init/{ubuntu-desktop24.user-data.yml => ubuntu24-desktop.user-data.yml} (76%) rename tests/packer/init/{ubuntu-server.user-data.yml => ubuntu24-server.user-data.yml} (100%) diff --git a/tests/Makefile b/tests/Makefile index de4a15f78..8bf5f6182 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -21,7 +21,7 @@ $(BASE): @make --directory=../ package dist=${@} @packer build -force -var version=${VERSION} \ -var disk_size=${disk} -var flavor="${flavor}" \ - -only=qemu.${@}-${flavor} packer/ + -only=qemu.${@} packer/ lint: @packer fmt --check packer/ diff --git a/tests/packer/archlinux.pkr.hcl b/tests/packer/archlinux.pkr.hcl index c445b632a..41a2627d5 100644 --- a/tests/packer/archlinux.pkr.hcl +++ b/tests/packer/archlinux.pkr.hcl @@ -2,43 +2,7 @@ # Copyright (C) 2023-2024 Alexandre Pujol # SPDX-License-Identifier: GPL-2.0-only -source "qemu" "archlinux-server" { - disk_image = true - iso_url = "https://geo.mirror.pkgbuild.com/images/latest/Arch-Linux-x86_64-cloudimg.qcow2" - iso_checksum = "file:https://geo.mirror.pkgbuild.com/images/latest/Arch-Linux-x86_64-cloudimg.qcow2.SHA256" - iso_target_path = "${var.iso_dir}/archlinux-cloudimg-amd64.img" - cpu_model = "host" - cpus = 6 - memory = 4096 - disk_size = "10G" - accelerator = "kvm" - headless = true - ssh_username = var.username - ssh_password = var.password - ssh_port = 22 - ssh_wait_timeout = "1000s" - disk_compression = true - disk_detect_zeroes = "unmap" - disk_discard = "unmap" - output_directory = var.output - vm_name = "${var.prefix}${source.name}.qcow2" - boot_wait = "10s" - shutdown_command = "echo ${var.password} | sudo -S shutdown -hP now" - cd_label = "cidata" - cd_content = { - "meta-data" = "" - "user-data" = templatefile("${path.cwd}/packer/init/${source.name}.user-data.yml", - { - username = "${var.username}" - password = "${var.password}" - ssh_key = file("${var.ssh_publickey}") - hostname = "${var.prefix}${source.name}" - } - ) - } -} - -source "qemu" "archlinux-gnome" { +source "qemu" "archlinux" { disk_image = true iso_url = "https://geo.mirror.pkgbuild.com/images/latest/Arch-Linux-x86_64-cloudimg.qcow2" iso_checksum = "file:https://geo.mirror.pkgbuild.com/images/latest/Arch-Linux-x86_64-cloudimg.qcow2.SHA256" @@ -57,54 +21,18 @@ source "qemu" "archlinux-gnome" { disk_detect_zeroes = "unmap" disk_discard = "unmap" output_directory = var.output - vm_name = "${var.prefix}${source.name}.qcow2" + vm_name = "${var.prefix}${source.name}-${var.flavor}.qcow2" boot_wait = "10s" shutdown_command = "echo ${var.password} | sudo -S shutdown -hP now" cd_label = "cidata" cd_content = { "meta-data" = "" - "user-data" = templatefile("${path.cwd}/packer/init/${source.name}.user-data.yml", + "user-data" = templatefile("${path.cwd}/packer/init/${source.name}-${var.flavor}.user-data.yml", { username = "${var.username}" password = "${var.password}" ssh_key = file("${var.ssh_publickey}") - hostname = "${var.prefix}${source.name}" - } - ) - } -} - -source "qemu" "archlinux-kde" { - disk_image = true - iso_url = "https://geo.mirror.pkgbuild.com/images/latest/Arch-Linux-x86_64-cloudimg.qcow2" - iso_checksum = "file:https://geo.mirror.pkgbuild.com/images/latest/Arch-Linux-x86_64-cloudimg.qcow2.SHA256" - iso_target_path = "${var.iso_dir}/archlinux-cloudimg-amd64.img" - cpu_model = "host" - cpus = 6 - memory = 4096 - disk_size = var.disk_size - accelerator = "kvm" - headless = true - ssh_username = var.username - ssh_password = var.password - ssh_port = 22 - ssh_wait_timeout = "1000s" - disk_compression = true - disk_detect_zeroes = "unmap" - disk_discard = "unmap" - output_directory = var.output - vm_name = "${var.prefix}${source.name}.qcow2" - boot_wait = "10s" - shutdown_command = "echo ${var.password} | sudo -S shutdown -hP now" - cd_label = "cidata" - cd_content = { - "meta-data" = "" - "user-data" = templatefile("${path.cwd}/packer/init/${source.name}.user-data.yml", - { - username = "${var.username}" - password = "${var.password}" - ssh_key = file("${var.ssh_publickey}") - hostname = "${var.prefix}${source.name}" + hostname = "${var.prefix}${source.name}-${var.flavor}" } ) } diff --git a/tests/packer/builds.pkr.hcl b/tests/packer/builds.pkr.hcl index c37e768ac..33288e6b5 100644 --- a/tests/packer/builds.pkr.hcl +++ b/tests/packer/builds.pkr.hcl @@ -4,18 +4,12 @@ build { sources = [ - "source.qemu.archlinux-gnome", - "source.qemu.archlinux-kde", - "source.qemu.archlinux-server", - "source.qemu.debian-gnome", - "source.qemu.debian-kde", - "source.qemu.debian-server", - "source.qemu.opensuse-gnome", - "source.qemu.opensuse-kde", - "source.qemu.ubuntu-desktop", - "source.qemu.ubuntu-desktop24", - "source.qemu.ubuntu-server", - "source.qemu.ubuntu-server24", + "source.qemu.archlinux", + "source.qemu.debian", + "source.qemu.fedora", + "source.qemu.opensuse", + "source.qemu.ubuntu22", + "source.qemu.ubuntu24", ] # Upload local files @@ -25,26 +19,28 @@ build { } provisioner "file" { - only = ["qemu.archlinux-gnome", "qemu.archlinux-kde", "qemu.archlinux-server"] + only = ["qemu.archlinux"] destination = "/tmp/src/" - sources = ["${path.cwd}/../apparmor.d-${var.version}-1-x86_64.pkg.tar.zst"] + sources = [ + "${path.cwd}/../apparmor.d-${var.version}-1-x86_64.pkg.tar.zst", + ] } provisioner "file" { - only = ["qemu.opensuse-*"] + only = ["qemu.opensuse"] destination = "/tmp/src/" sources = ["${path.cwd}/../apparmor.d-${var.version}-1.x86_64.rpm"] } provisioner "file" { - only = ["qemu.debian-server", "qemu.debian-gnome", "qemu.debian-kde", "qemu.ubuntu-server", "qemu.ubuntu-server24", "qemu.ubuntu-desktop", "qemu.ubuntu-desktop24"] + only = ["qemu.debian", "qemu.ubuntu22", "qemu.ubuntu24"] destination = "/tmp/src/" sources = ["${path.cwd}/../apparmor.d_${var.version}-1_amd64.deb"] } # Wait for cloud-init to finish provisioner "shell" { - except = ["qemu.opensuse-*"] + except = ["qemu.opensuse"] execute_command = "echo '${var.password}' | sudo -S sh -c '{{ .Vars }} {{ .Path }}'" inline = [ "while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for Cloud-Init...'; sleep 20; done", diff --git a/tests/packer/debian.pkr.hcl b/tests/packer/debian.pkr.hcl index 38f33116f..7fd176b6e 100644 --- a/tests/packer/debian.pkr.hcl +++ b/tests/packer/debian.pkr.hcl @@ -2,14 +2,14 @@ # Copyright (C) 2023-2024 Alexandre Pujol # SPDX-License-Identifier: GPL-2.0-only -source "qemu" "debian-server" { +source "qemu" "debian" { disk_image = true iso_url = "https://cdimage.debian.org/images/cloud/${var.release.debian.codename}/latest/debian-${var.release.debian.version}-genericcloud-amd64.qcow2" iso_checksum = "file:https://cdimage.debian.org/images/cloud/${var.release.debian.codename}/latest/SHA512SUMS" iso_target_path = "${var.iso_dir}/debian-cloudimg-amd64.img" cpu_model = "host" - cpus = 4 - memory = 2048 + cpus = 6 + memory = 4096 disk_size = var.disk_size accelerator = "kvm" headless = true @@ -20,89 +20,15 @@ source "qemu" "debian-server" { disk_compression = true disk_detect_zeroes = "unmap" disk_discard = "unmap" - output_directory = "${var.output}/" - vm_name = "${var.prefix}${source.name}.qcow2" + output_directory = var.output + vm_name = "${var.prefix}${source.name}-${var.flavor}.qcow2" boot_wait = "10s" firmware = var.firmware shutdown_command = "echo ${var.password} | sudo -S /sbin/shutdown -hP now" cd_label = "cidata" cd_content = { "meta-data" = "" - "user-data" = templatefile("${path.cwd}/packer/init/${source.name}.user-data.yml", - { - username = "${var.username}" - password = "${var.password}" - ssh_key = file("${var.ssh_publickey}") - hostname = "${var.prefix}${source.name}" - } - ) - } -} - -source "qemu" "debian-gnome" { - disk_image = true - iso_url = "https://cdimage.debian.org/images/cloud/${var.release.debian.codename}/latest/debian-${var.release.debian.version}-genericcloud-amd64.qcow2" - iso_checksum = "file:https://cdimage.debian.org/images/cloud/${var.release.debian.codename}/latest/SHA512SUMS" - iso_target_path = "${var.iso_dir}/debian-cloudimg-amd64.img" - cpu_model = "host" - cpus = 4 - memory = 2048 - disk_size = var.disk_size - accelerator = "kvm" - headless = true - ssh_username = var.username - ssh_password = var.password - ssh_port = 22 - ssh_wait_timeout = "1000s" - disk_compression = true - disk_detect_zeroes = "unmap" - disk_discard = "unmap" - output_directory = "${var.output}/" - vm_name = "${var.prefix}${source.name}.qcow2" - boot_wait = "10s" - firmware = var.firmware - shutdown_command = "echo ${var.password} | sudo -S /sbin/shutdown -hP now" - cd_label = "cidata" - cd_content = { - "meta-data" = "" - "user-data" = templatefile("${path.cwd}/packer/init/${source.name}.user-data.yml", - { - username = "${var.username}" - password = "${var.password}" - ssh_key = file("${var.ssh_publickey}") - hostname = "${var.prefix}${source.name}" - } - ) - } -} - -source "qemu" "debian-kde" { - disk_image = true - iso_url = "https://cdimage.debian.org/images/cloud/${var.release.debian.codename}/latest/debian-${var.release.debian.version}-genericcloud-amd64.qcow2" - iso_checksum = "file:https://cdimage.debian.org/images/cloud/${var.release.debian.codename}/latest/SHA512SUMS" - iso_target_path = "${var.iso_dir}/debian-cloudimg-amd64.img" - cpu_model = "host" - cpus = 4 - memory = 2048 - disk_size = var.disk_size - accelerator = "kvm" - headless = true - ssh_username = var.username - ssh_password = var.password - ssh_port = 22 - ssh_wait_timeout = "1000s" - disk_compression = true - disk_detect_zeroes = "unmap" - disk_discard = "unmap" - output_directory = "${var.output}/" - vm_name = "${var.prefix}${source.name}.qcow2" - boot_wait = "10s" - firmware = var.firmware - shutdown_command = "echo ${var.password} | sudo -S /sbin/shutdown -hP now" - cd_label = "cidata" - cd_content = { - "meta-data" = "" - "user-data" = templatefile("${path.cwd}/packer/init/${source.name}.user-data.yml", + "user-data" = templatefile("${path.cwd}/packer/init/${source.name}-${var.flavor}.user-data.yml", { username = "${var.username}" password = "${var.password}" diff --git a/tests/packer/init/archlinux-xfce.user-data.yml b/tests/packer/init/archlinux-xfce.user-data.yml new file mode 100644 index 000000000..1cc18f556 --- /dev/null +++ b/tests/packer/init/archlinux-xfce.user-data.yml @@ -0,0 +1,92 @@ +#cloud-config + +hostname: ${hostname} +locale: en_IE +keyboard: + layout: ie + +ssh_pwauth: true +users: + - name: ${username} + plain_text_passwd: ${password} + shell: /bin/bash + ssh_authorized_keys: + - ${ssh_key} + lock_passwd: false + sudo: ALL=(ALL) NOPASSWD:ALL + +package_update: true +package_upgrade: true +package_reboot_if_required: false +packages: + # Install core packages + - apparmor + - base-devel + - firewalld + - qemu-guest-agent + - rng-tools + - spice-vdagent + + # Install usefull core packages + - bash-completion + - git + - htop + - man + - pass + - python-notify2 + - vim + - wget + + # Install basic services + - networkmanager + - cups + - cups-pdf + - system-config-printer + + # Install Graphical Interface + - xfce4 + - xfce4-goodies + - lightdm + - lightdm-gtk-greeter + + # Install Applications + - firefox + - chromium + - terminator + +runcmd: + # Regenerate grub.cfg + - grub-mkconfig -o /boot/grub/grub.cfg + + # Remove swapfile + - swapoff -a + - rm -rf /swap/ + - sed -e "/swap/d" -i /etc/fstab + + # Enable core services + - systemctl enable apparmor + - systemctl enable auditd + - systemctl enable lightdm.service + - systemctl enable NetworkManager + - systemctl enable rngd + - systemctl enable avahi-daemon + - systemctl enable systemd-timesyncd.service + +write_files: + # Enable AppArmor in kernel parameters + - path: /etc/default/grub + append: true + content: | + GRUB_CMDLINE_LINUX_DEFAULT="$GRUB_CMDLINE_LINUX_DEFAULT lsm=landlock,lockdown,yama,integrity,apparmor,bpf" + + # Set some bash aliases + - path: /etc/skel/.bashrc + append: true + content: | + [[ -f ~/.bash_aliases ]] && source ~/.bash_aliases + + # Setup shared directory + - path: /etc/fstab + append: true + content: | + 0a31bc478ef8e2461a4b1cc10a24cc4 /home/user/Projects/apparmor.d virtiofs defaults 0 1 diff --git a/tests/packer/init/opensuse-gnome.user-data.yml b/tests/packer/init/opensuse-gnome.user-data.yml new file mode 100644 index 000000000..b54bb458e --- /dev/null +++ b/tests/packer/init/opensuse-gnome.user-data.yml @@ -0,0 +1,43 @@ +#cloud-config + +hostname: ${hostname} +locale: en_IE +keyboard: + layout: ie + +ssh_pwauth: true +users: + - name: ${username} + plain_text_passwd: ${password} + shell: /bin/bash + ssh_authorized_keys: + - ${ssh_key} + lock_passwd: false + sudo: ALL=(ALL) NOPASSWD:ALL + +package_update: true +package_upgrade: true +package_reboot_if_required: false +packages: + - apparmor-profiles + - bash-completion + - distribution-release + - git + - golang-packaging + - htop + - make + - rpmbuild + - vim + +write_files: + # Set some bash aliases + - path: /home/${username}/.bashrc + append: true + content: | + [[ -f ~/.bash_aliases ]] && source ~/.bash_aliases + + # Setup shared directory + - path: /etc/fstab + append: true + content: | + 0a31bc478ef8e2461a4b1cc10a24cc4 /home/user/Projects/apparmor.d virtiofs defaults 0 1 diff --git a/tests/packer/init/ubuntu-desktop.user-data.yml b/tests/packer/init/ubuntu22-desktop.user-data.yml similarity index 100% rename from tests/packer/init/ubuntu-desktop.user-data.yml rename to tests/packer/init/ubuntu22-desktop.user-data.yml diff --git a/tests/packer/init/ubuntu-desktop24.user-data.yml b/tests/packer/init/ubuntu24-desktop.user-data.yml similarity index 76% rename from tests/packer/init/ubuntu-desktop24.user-data.yml rename to tests/packer/init/ubuntu24-desktop.user-data.yml index 30a82279a..3c3807e29 100644 --- a/tests/packer/init/ubuntu-desktop24.user-data.yml +++ b/tests/packer/init/ubuntu24-desktop.user-data.yml @@ -2,6 +2,8 @@ # Based on https://github.com/canonical/autoinstall-desktop +# https://github.com/canonical/ubuntu-desktop-provision/blob/main/README.md + hostname: ${hostname} locale: en_IE keyboard: @@ -22,7 +24,7 @@ package_upgrade: true package_reboot_if_required: false packages: - ubuntu-desktop - - linux-generic-hwe-22.04 + - linux-generic-hwe-24.04 - qemu-guest-agent - spice-vdagent - terminator @@ -49,14 +51,14 @@ runcmd: # Remove other packages present by default in Ubuntu Server but not # normally present in Ubuntu Desktop. - - >- - apt-get -y purge - ubuntu-server ubuntu-server-minimal netplan.io cloud-init - binutils byobu curl dmeventd finalrd gawk - kpartx mdadm ncurses-term needrestart open-iscsi - sg3-utils ssh-import-id sssd thin-provisioning-tools tmux - sosreport screen open-vm-tools motd-news-config lxd-agent-loader - landscape-common fonts-ubuntu-console ethtool + # - >- + # apt-get -y purge + # ubuntu-server ubuntu-server-minimal netplan.io cloud-init + # binutils byobu curl dmeventd finalrd gawk + # kpartx mdadm ncurses-term needrestart open-iscsi + # sg3-utils ssh-import-id sssd thin-provisioning-tools tmux + # sosreport screen open-vm-tools motd-news-config lxd-agent-loader + # landscape-common fonts-ubuntu-console ethtool # Finally, remove things only installed as dependencies of other things # we have already removed. diff --git a/tests/packer/init/ubuntu-server.user-data.yml b/tests/packer/init/ubuntu24-server.user-data.yml similarity index 100% rename from tests/packer/init/ubuntu-server.user-data.yml rename to tests/packer/init/ubuntu24-server.user-data.yml diff --git a/tests/packer/opensuse.pkr.hcl b/tests/packer/opensuse.pkr.hcl index de9bafacb..49ba09f70 100644 --- a/tests/packer/opensuse.pkr.hcl +++ b/tests/packer/opensuse.pkr.hcl @@ -3,16 +3,13 @@ # SPDX-License-Identifier: GPL-2.0-only # TODO: Fully automate the creation of the base image -# To save some dev time, 'base_opensuse_kde' is manually created from the opensuse iso with: -# - KDE -# - username/password defined in the variables -# - cloud-init installed and enabled -source "qemu" "opensuse-kde" { +source "qemu" "opensuse" { disk_image = true - iso_url = "${var.iso_dir}/base_opensuse_kde.qcow2" - iso_checksum = "sha256:62a174725bdf26981d15969e53461b89359f7763450cbfd3e258d4035731279b" - iso_target_path = "${var.iso_dir}/base_opensuse_kde.qcow2" + iso_url = "${var.base_dir}/base-tumbleweed-gnome.qcow2" + iso_checksum = "sha256:223ed62160ef4f1a4f21b69c574f552a07eee6ef66cf66eef2b49c5a7c4864f4" + iso_target_path = "${var.base_dir}/base-tumbleweed-gnome.qcow2" + cpu_model = "host" cpus = 6 memory = 4096 disk_size = var.disk_size @@ -25,15 +22,15 @@ source "qemu" "opensuse-kde" { disk_compression = true disk_detect_zeroes = "unmap" disk_discard = "unmap" - output_directory = "${var.iso_dir}/packer/" - vm_name = "${var.prefix}${source.name}.qcow2" + output_directory = var.output + vm_name = "${var.prefix}${source.name}-${var.flavor}.qcow2" boot_wait = "10s" firmware = var.firmware shutdown_command = "echo ${var.password} | sudo shutdown -hP now" cd_label = "cidata" cd_content = { "meta-data" = "" - "user-data" = templatefile("${path.cwd}/packer/init/${source.name}.user-data.yml", + "user-data" = templatefile("${path.cwd}/packer/init/${source.name}-${var.flavor}.user-data.yml", { username = "${var.username}" password = "${var.password}" diff --git a/tests/packer/ubuntu.pkr.hcl b/tests/packer/ubuntu.pkr.hcl index 344a8bf43..052b460da 100644 --- a/tests/packer/ubuntu.pkr.hcl +++ b/tests/packer/ubuntu.pkr.hcl @@ -2,14 +2,14 @@ # Copyright (C) 2023-2024 Alexandre Pujol # SPDX-License-Identifier: GPL-2.0-only -source "qemu" "ubuntu-server" { +source "qemu" "ubuntu22" { disk_image = true - iso_url = "https://cloud-images.ubuntu.com/${var.release.ubuntu.codename}/current/${var.release.ubuntu.codename}-server-cloudimg-amd64.img" - iso_checksum = "file:https://cloud-images.ubuntu.com/${var.release.ubuntu.codename}/current/SHA256SUMS" - iso_target_path = "${var.iso_dir}/ubuntu-cloudimg-amd64.img" + iso_url = "https://cloud-images.ubuntu.com/${var.release.ubuntu22.codename}/current/${var.release.ubuntu22.codename}-server-cloudimg-amd64.img" + iso_checksum = "file:https://cloud-images.ubuntu.com/${var.release.ubuntu22.codename}/current/SHA256SUMS" + iso_target_path = "${var.iso_dir}/ubuntu22-cloudimg-amd64.img" cpu_model = "host" - cpus = 4 - memory = 2048 + cpus = 6 + memory = 4096 disk_size = var.disk_size accelerator = "kvm" headless = true @@ -20,15 +20,15 @@ source "qemu" "ubuntu-server" { disk_compression = true disk_detect_zeroes = "unmap" disk_discard = "unmap" - output_directory = "${var.output}/" - vm_name = "${var.prefix}${source.name}.qcow2" + output_directory = var.output + vm_name = "${var.prefix}${source.name}-${var.flavor}.qcow2" boot_wait = "10s" firmware = var.firmware shutdown_command = "echo ${var.password} | sudo -S /sbin/shutdown -hP now" cd_label = "cidata" cd_content = { "meta-data" = "" - "user-data" = templatefile("${path.cwd}/packer/init/${source.name}.user-data.yml", + "user-data" = templatefile("${path.cwd}/packer/init/${source.name}-${var.flavor}.user-data.yml", { username = "${var.username}" password = "${var.password}" @@ -39,14 +39,14 @@ source "qemu" "ubuntu-server" { } } -source "qemu" "ubuntu-server24" { +source "qemu" "ubuntu24" { disk_image = true iso_url = "https://cloud-images.ubuntu.com/${var.release.ubuntu24.codename}/current/${var.release.ubuntu24.codename}-server-cloudimg-amd64.img" iso_checksum = "file:https://cloud-images.ubuntu.com/${var.release.ubuntu24.codename}/current/SHA256SUMS" - iso_target_path = "${var.iso_dir}/ubuntu-${var.release.ubuntu24.codename}-cloudimg-amd64.img" + iso_target_path = "${var.iso_dir}/ubuntu24-cloudimg-amd64.img" cpu_model = "host" - cpus = 4 - memory = 2048 + cpus = 6 + memory = 4096 disk_size = var.disk_size accelerator = "kvm" headless = true @@ -57,89 +57,15 @@ source "qemu" "ubuntu-server24" { disk_compression = true disk_detect_zeroes = "unmap" disk_discard = "unmap" - output_directory = "${var.output}/" - vm_name = "${var.prefix}${source.name}.qcow2" + output_directory = var.output + vm_name = "${var.prefix}${source.name}-${var.flavor}.qcow2" boot_wait = "10s" firmware = var.firmware shutdown_command = "echo ${var.password} | sudo -S /sbin/shutdown -hP now" cd_label = "cidata" cd_content = { "meta-data" = "" - "user-data" = templatefile("${path.cwd}/packer/init/ubuntu-server.user-data.yml", - { - username = "${var.username}" - password = "${var.password}" - ssh_key = file("${var.ssh_publickey}") - hostname = "${var.prefix}${source.name}" - } - ) - } -} - -source "qemu" "ubuntu-desktop" { - disk_image = true - iso_url = "https://cloud-images.ubuntu.com/${var.release.ubuntu.codename}/current/${var.release.ubuntu.codename}-server-cloudimg-amd64.img" - iso_checksum = "file:https://cloud-images.ubuntu.com/${var.release.ubuntu.codename}/current/SHA256SUMS" - iso_target_path = "${var.iso_dir}/ubuntu-cloudimg-amd64.img" - cpu_model = "host" - cpus = 6 - memory = 4096 - disk_size = var.disk_size - accelerator = "kvm" - headless = true - ssh_username = var.username - ssh_password = var.password - ssh_port = 22 - ssh_wait_timeout = "10000s" - disk_compression = true - disk_detect_zeroes = "unmap" - disk_discard = "unmap" - output_directory = "${var.output}/" - vm_name = "${var.prefix}${source.name}.qcow2" - boot_wait = "10s" - firmware = var.firmware - shutdown_command = "echo ${var.password} | sudo -S /sbin/shutdown -hP now" - cd_label = "cidata" - cd_content = { - "meta-data" = "" - "user-data" = templatefile("${path.cwd}/packer/init/${source.name}.user-data.yml", - { - username = "${var.username}" - password = "${var.password}" - ssh_key = file("${var.ssh_publickey}") - hostname = "${var.prefix}${source.name}" - } - ) - } -} - -source "qemu" "ubuntu-desktop24" { - disk_image = true - iso_url = "https://cloud-images.ubuntu.com/${var.release.ubuntu24.codename}/current/${var.release.ubuntu24.codename}-server-cloudimg-amd64.img" - iso_checksum = "file:https://cloud-images.ubuntu.com/${var.release.ubuntu24.codename}/current/SHA256SUMS" - iso_target_path = "${var.iso_dir}/ubuntu-${var.release.ubuntu24.codename}-cloudimg-amd64.img" - cpu_model = "host" - cpus = 6 - memory = 4096 - disk_size = var.disk_size - accelerator = "kvm" - headless = false - ssh_username = var.username - ssh_password = var.password - ssh_port = 22 - ssh_wait_timeout = "10000s" - disk_compression = true - disk_detect_zeroes = "unmap" - disk_discard = "unmap" - output_directory = "${var.output}/" - vm_name = "${var.prefix}${source.name}.qcow2" - boot_wait = "10s" - firmware = var.firmware - shutdown_command = "echo ${var.password} | sudo -S /sbin/shutdown -hP now" - cd_label = "cidata" - cd_content = { - "meta-data" = "" - "user-data" = templatefile("${path.cwd}/packer/init/${source.name}.user-data.yml", + "user-data" = templatefile("${path.cwd}/packer/init/${source.name}-${var.flavor}.user-data.yml", { username = "${var.username}" password = "${var.password}" diff --git a/tests/packer/variables.pkr.hcl b/tests/packer/variables.pkr.hcl index 5a1cc17e8..c9ca4b62c 100644 --- a/tests/packer/variables.pkr.hcl +++ b/tests/packer/variables.pkr.hcl @@ -22,12 +22,6 @@ variable "ssh_publickey" { default = "~/.ssh/id_ed25519.pub" } -variable "ssh_privatekey" { - description = "Path to the ssh private key" - type = string - default = "~/.ssh/id_ed25519" -} - variable "disk_size" { description = "Disk size of the VM to build" type = string @@ -49,7 +43,7 @@ variable "base_dir" { variable "firmware" { description = "Path to the UEFI firmware" type = string - default = "/usr/share/edk2-ovmf/x64/OVMF_CODE.fd" + default = "/usr/share/edk2/x64/OVMF_CODE.fd" } variable "output" { @@ -83,7 +77,7 @@ variable "release" { version = string })) default = { - "ubuntu" : { + "ubuntu22" : { codename = "jammy", version = "22.04.2", }, @@ -99,5 +93,11 @@ variable "release" { codename = "tumbleweed", version = "", } + "fedora" : { + codename = "40", + version = "1.14", + } } } + +}