diff --git a/tests/boxes.yml b/tests/boxes.yml index b8501d5e..09017f8a 100644 --- a/tests/boxes.yml +++ b/tests/boxes.yml @@ -20,6 +20,12 @@ boxes: ram: '6144' cpu: '6' + - name: debian-server + box: aa-debian-server + uefi: true + ram: '6144' + cpu: '6' + - name: opensuse-kde box: aa-opensuse-kde uefi: true diff --git a/tests/packer/archlinux.pkr.hcl b/tests/packer/archlinux.pkr.hcl index a7994ea2..c0c61fe0 100644 --- a/tests/packer/archlinux.pkr.hcl +++ b/tests/packer/archlinux.pkr.hcl @@ -20,9 +20,9 @@ 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}.qcow2" boot_wait = "10s" - shutdown_command = "echo ${var.password} | sudo shutdown -hP now" + shutdown_command = "echo ${var.password} | sudo -S shutdown -hP now" cd_label = "cidata" cd_content = { "meta-data" = "" @@ -31,7 +31,7 @@ source "qemu" "archlinux-gnome" { username = "${var.username}" password = "${var.password}" ssh_key = file("${var.ssh_publickey}") - hostname = "${var.prefix}-${source.name}" + hostname = "${var.prefix}${source.name}" } ) } @@ -55,9 +55,9 @@ source "qemu" "archlinux-kde" { disk_detect_zeroes = "unmap" disk_discard = "unmap" output_directory = "${var.output}" - vm_name = "${var.prefix}-${source.name}.qcow2" + vm_name = "${var.prefix}${source.name}.qcow2" boot_wait = "10s" - shutdown_command = "echo ${var.password} | sudo shutdown -hP now" + shutdown_command = "echo ${var.password} | sudo -S shutdown -hP now" cd_label = "cidata" cd_content = { "meta-data" = "" @@ -66,7 +66,7 @@ source "qemu" "archlinux-kde" { username = "${var.username}" password = "${var.password}" ssh_key = file("${var.ssh_publickey}") - hostname = "${var.prefix}-${source.name}" + hostname = "${var.prefix}${source.name}" } ) } diff --git a/tests/packer/src/init.sh b/tests/packer/init/init.sh similarity index 100% rename from tests/packer/src/init.sh rename to tests/packer/init/init.sh diff --git a/tests/packer/main.pkr.hcl b/tests/packer/main.pkr.hcl index c6aa8ea1..6c3e455a 100644 --- a/tests/packer/main.pkr.hcl +++ b/tests/packer/main.pkr.hcl @@ -32,22 +32,26 @@ build { inline = [ "while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for Cloud-Init...'; sleep 20; done", "cloud-init clean", # Remove logs and artifacts so cloud-init can re-run - "sh /tmp/src/init.sh" ] } + provisioner "shell" { + script = "${path.cwd}/packer/init/init.sh" + execute_command = "echo '${var.password}' | sudo -S sh -c '{{ .Vars }} {{ .Path }}'" + } + provisioner "shell" { script = "${path.cwd}/packer/init/clean.sh" execute_command = "echo '${var.password}' | sudo -S sh -c '{{ .Vars }} {{ .Path }}'" } post-processor "vagrant" { - output = "${var.iso_dir}/packer_${var.prefix}-${source.name}.box" + output = "${var.base_dir}/packer_${var.prefix}${source.name}.box" } post-processor "shell-local" { inline = [ - "vagrant box add --force --name ${var.prefix}-${source.name} ${var.iso_dir}/packer_${var.prefix}-${source.name}.box" + "vagrant box add --force --name ${var.prefix}${source.name} ${var.base_dir}/packer_${var.prefix}${source.name}.box" ] } diff --git a/tests/packer/ubuntu.pkr.hcl b/tests/packer/ubuntu.pkr.hcl index dcea5eb0..40536dfc 100644 --- a/tests/packer/ubuntu.pkr.hcl +++ b/tests/packer/ubuntu.pkr.hcl @@ -4,9 +4,9 @@ source "qemu" "ubuntu-server" { disk_image = true - iso_url = "https://cloud-images.ubuntu.com/${var.release.ubuntu}/current/${var.release.ubuntu}-server-cloudimg-amd64.img" - iso_checksum = "file:https://cloud-images.ubuntu.com/${var.release.ubuntu}/current/SHA256SUMS" - iso_target_path = "${var.iso_dir}/${source.name}-cloudimg-amd64.img" + 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" cpus = 4 memory = 2048 disk_size = "${var.disk_size}" @@ -20,7 +20,7 @@ source "qemu" "ubuntu-server" { disk_detect_zeroes = "unmap" disk_discard = "unmap" output_directory = "${var.output}/" - vm_name = "${var.prefix}-${source.name}.qcow2" + vm_name = "${var.prefix}${source.name}.qcow2" boot_wait = "10s" firmware = "/usr/share/edk2-ovmf/x64/OVMF_CODE.fd" shutdown_command = "echo ${var.password} | sudo -S /sbin/shutdown -hP now" @@ -32,7 +32,7 @@ source "qemu" "ubuntu-server" { username = "${var.username}" password = "${var.password}" ssh_key = file("${var.ssh_publickey}") - hostname = "${var.prefix}-${source.name}" + hostname = "${var.prefix}${source.name}" } ) } diff --git a/tests/packer/variables.pkr.hcl b/tests/packer/variables.pkr.hcl index c6b7465e..34bd650a 100644 --- a/tests/packer/variables.pkr.hcl +++ b/tests/packer/variables.pkr.hcl @@ -40,6 +40,12 @@ variable "iso_dir" { default = "/var/lib/libvirt/images" } +variable "base_dir" { + description = "Final packer image output directory" + type = string + default = "/var/lib/libvirt/images" +} + variable "output" { description = "Output build directory" type = string @@ -49,7 +55,7 @@ variable "output" { variable "prefix" { description = "Image name prefix" type = string - default = "aa" + default = "aa-" } variable "version" { @@ -58,18 +64,30 @@ variable "version" { default = "0.001" } -variable "release" { - description = "Distribution release to use" - type = map(string) - default = { - "ubuntu" : "jammy", # 22.04 LTS - "debian" : "bullseye", # 11 - "opensuse" : "9", - } -} - variable "flavor" { - description = "Distribution flavor to use (-desktop, -gnome, -kde...)" + description = "Distribution flavor to use (server, desktop, gnome, kde...)" type = string default = "" } + +variable "release" { + description = "Distribution metadata to use" + type = map(object({ + codename = string + version = string + })) + default = { + "ubuntu" : { + codename = "jammy", + version = "22.04.2", + }, + "debian" : { + codename = "bullseye", + version = "11", + } + "opensuse" : { + codename = "tumbleweed", + version = "", + } + } +}