From 3aa07e4d64a4509376fabce4f4d97e858fcc49fe Mon Sep 17 00:00:00 2001 From: Alexandre Pujol Date: Sun, 19 Nov 2023 16:09:25 +0000 Subject: [PATCH] tests(packer): add arch-server and ubuntu 24.04 images. --- tests/boxes.yml | 12 +++ tests/packer/archlinux.pkr.hcl | 35 +++++++++ tests/packer/builds.pkr.hcl | 6 +- .../init/archlinux-server.user-data.yml | 76 +++++++++++++++++++ tests/packer/ubuntu.pkr.hcl | 36 +++++++++ tests/packer/variables.pkr.hcl | 4 + 6 files changed, 167 insertions(+), 2 deletions(-) create mode 100644 tests/packer/init/archlinux-server.user-data.yml diff --git a/tests/boxes.yml b/tests/boxes.yml index ee7f32ec..6b82d1d6 100644 --- a/tests/boxes.yml +++ b/tests/boxes.yml @@ -14,6 +14,12 @@ boxes: ram: '6144' cpu: '6' + - name: arch-server + box: aa-archlinux-server + uefi: false + ram: '6144' + cpu: '6' + - name: ubuntu-desktop box: aa-ubuntu-desktop uefi: true @@ -26,6 +32,12 @@ boxes: ram: '6144' cpu: '6' + - name: ubuntu-server24 + box: aa-ubuntu-server24 + uefi: true + ram: '6144' + cpu: '6' + - name: debian-server box: aa-debian-server uefi: true diff --git a/tests/packer/archlinux.pkr.hcl b/tests/packer/archlinux.pkr.hcl index 5f08d1a4..f6a13bf5 100644 --- a/tests/packer/archlinux.pkr.hcl +++ b/tests/packer/archlinux.pkr.hcl @@ -2,6 +2,41 @@ # Copyright (C) 2023 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" + 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}" + } + ) + } +} + source "qemu" "archlinux-gnome" { disk_image = true iso_url = "https://geo.mirror.pkgbuild.com/images/latest/Arch-Linux-x86_64-cloudimg.qcow2" diff --git a/tests/packer/builds.pkr.hcl b/tests/packer/builds.pkr.hcl index 6334b5fd..f275b2c2 100644 --- a/tests/packer/builds.pkr.hcl +++ b/tests/packer/builds.pkr.hcl @@ -6,11 +6,13 @@ build { sources = [ "source.qemu.archlinux-gnome", "source.qemu.archlinux-kde", + "source.qemu.archlinux-server", "source.qemu.debian-server", "source.qemu.debian-gnome", "source.qemu.opensuse-kde", "source.qemu.ubuntu-desktop", "source.qemu.ubuntu-server", + "source.qemu.ubuntu-server24", ] # Upload local files @@ -20,7 +22,7 @@ build { } provisioner "file" { - only = ["qemu.archlinux-gnome", "qemu.archlinux-kde"] + only = ["qemu.archlinux-gnome", "qemu.archlinux-kde", "qemu.archlinux-server"] destination = "/tmp/src/" sources = ["${path.cwd}/../apparmor.d-${var.version}-1-x86_64.pkg.tar.zst"] } @@ -32,7 +34,7 @@ build { } provisioner "file" { - only = ["qemu.debian-server", "qemu.debian-gnome", "qemu.ubuntu-server", "qemu.ubuntu-desktop"] + only = ["qemu.debian-server", "qemu.debian-gnome", "qemu.ubuntu-server", "qemu.ubuntu-server24", "qemu.ubuntu-desktop"] destination = "/tmp/src/" sources = ["${path.cwd}/../apparmor.d_${var.version}-1_amd64.deb"] } diff --git a/tests/packer/init/archlinux-server.user-data.yml b/tests/packer/init/archlinux-server.user-data.yml new file mode 100644 index 00000000..062f3132 --- /dev/null +++ b/tests/packer/init/archlinux-server.user-data.yml @@ -0,0 +1,76 @@ +#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 + - qemu-guest-agent + - rng-tools + - spice-vdagent + + # Install usefull core packages + - bash-completion + - git + - htop + - man + - pass + - python-notify2 + - vim + - wget + +runcmd: + + # Regenerate grub.cfg + - [ grub-mkconfig, -o, /boot/grub/grub.cfg ] + + # Enable core services + - [ systemctl, enable, apparmor ] + - [ systemctl, enable, auditd ] + - [ systemctl, enable, rngd ] + - [ systemctl, enable, systemd-timesyncd.service ] + +write_files: + + # Network configuration + - path: /etc/systemd/network/20-wired.network + owner: 'root:root' + permissions: '0644' + content: | + [Match] + Name=en* + + [Network] + DHCP=yes + + [DHCPv4] + RouteMetric=10 + + # 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 diff --git a/tests/packer/ubuntu.pkr.hcl b/tests/packer/ubuntu.pkr.hcl index 012f9725..1be15ea8 100644 --- a/tests/packer/ubuntu.pkr.hcl +++ b/tests/packer/ubuntu.pkr.hcl @@ -38,6 +38,42 @@ source "qemu" "ubuntu-server" { } } +source "qemu" "ubuntu-server24" { + 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" + 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/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" diff --git a/tests/packer/variables.pkr.hcl b/tests/packer/variables.pkr.hcl index a6a50553..727411f8 100644 --- a/tests/packer/variables.pkr.hcl +++ b/tests/packer/variables.pkr.hcl @@ -87,6 +87,10 @@ variable "release" { codename = "jammy", version = "22.04.2", }, + "ubuntu24" : { + codename = "noble", + version = "24.04", + }, "debian" : { codename = "bookworm", version = "12",