diff --git a/tests/packer/builds.pkr.hcl b/tests/packer/builds.pkr.hcl new file mode 100644 index 00000000..976518bf --- /dev/null +++ b/tests/packer/builds.pkr.hcl @@ -0,0 +1,70 @@ +# apparmor.d - Full set of apparmor profiles +# Copyright (C) 2023 Alexandre Pujol +# SPDX-License-Identifier: GPL-2.0-only + +build { + sources = [ + "source.qemu.archlinux-gnome", + "source.qemu.archlinux-kde", + "source.qemu.debian-server", + "source.qemu.opensuse-kde", + "source.qemu.ubuntu-desktop", + "source.qemu.ubuntu-server", + ] + + # Upload local files + provisioner "file" { + destination = "/tmp" + sources = ["${path.cwd}/packer/src"] + } + + provisioner "file" { + only = ["qemu.archlinux-gnome", "qemu.archlinux-kde"] + destination = "/tmp/src/" + sources = ["${path.cwd}/../apparmor.d-${var.version}-x86_64.pkg.tar.zst"] + } + + provisioner "file" { + only = ["qemu.opensuse-*"] + destination = "/tmp/src/" + sources = ["${path.cwd}/../apparmor.d-${var.version}*.rpm"] + } + + provisioner "file" { + only = ["qemu.debian-server", "qemu.ubuntu-server", "qemu.ubuntu-desktop"] + destination = "/tmp/src/" + 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 = [ + "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 + ] + } + + # 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 }}'" + } + + post-processor "vagrant" { + 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.base_dir}/packer_${var.prefix}${source.name}.box" + ] + } + +} diff --git a/tests/packer/main.pkr.hcl b/tests/packer/main.pkr.hcl index ddb7c3a5..742edf49 100644 --- a/tests/packer/main.pkr.hcl +++ b/tests/packer/main.pkr.hcl @@ -2,63 +2,15 @@ # Copyright (C) 2023 Alexandre Pujol # SPDX-License-Identifier: GPL-2.0-only -build { - sources = [ - "source.qemu.archlinux-gnome", - "source.qemu.archlinux-kde", - "source.qemu.debian-server", - "source.qemu.opensuse-kde", - "source.qemu.ubuntu-desktop", - "source.qemu.ubuntu-server", - ] - - # Upload local files - provisioner "file" { - destination = "/tmp" - sources = ["${path.cwd}/packer/src"] +packer { + required_plugins { + ansible = { + source = "github.com/hashicorp/ansible" + version = "~> 1" + } + qemu = { + source = "github.com/hashicorp/qemu" + version = "~> 1" + } } - - provisioner "file" { - only = ["qemu.archlinux-gnome", "qemu.archlinux-kde"] - destination = "/tmp/src/" - sources = ["${path.cwd}/../apparmor.d-${var.version}-x86_64.pkg.tar.zst"] - } - - provisioner "file" { - only = ["qemu.debian-server", "qemu.ubuntu-server", "qemu.ubuntu-desktop"] - destination = "/tmp/src/" - 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 = [ - "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 - ] - } - - # 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 }}'" - } - - post-processor "vagrant" { - 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.base_dir}/packer_${var.prefix}${source.name}.box" - ] - } - -} \ No newline at end of file +}