From 5b40c9a79e3fc7e1f3c762a7dac27b76da9a6cab Mon Sep 17 00:00:00 2001 From: Greg Hellings Date: Wed, 25 May 2022 01:40:52 -0500 Subject: [PATCH] Spread build source defs more evenly --- sources/build.pkr.hcl | 30 ++++++++++++ sources/inputs.pkr.hcl | 69 ++++++++++++++++++++++++++++ sources/qemu.pkr.hcl | 101 ----------------------------------------- test.sh | 2 +- 4 files changed, 100 insertions(+), 102 deletions(-) create mode 100644 sources/build.pkr.hcl create mode 100644 sources/inputs.pkr.hcl diff --git a/sources/build.pkr.hcl b/sources/build.pkr.hcl new file mode 100644 index 0000000..d57ed9f --- /dev/null +++ b/sources/build.pkr.hcl @@ -0,0 +1,30 @@ +build { + sources = ["source.qemu.x86_64"] + + provisioner "ansible" { + playbook_file = "ansible/playbook.yml" + galaxy_file = "ansible/requirements.yml" + } + + provisioner "shell" { + scripts = [ + "scripts/minimize.sh" + ] + } + + post-processors { + post-processor "vagrant" { + keep_input_artifact = true + compression_level = 9 + output = "${local.name}.box" + vagrantfile_template = "vagrant/${var.arch}.rb" + } + + post-processor "vagrant-cloud" { + name = "upload" + box_tag = "greg-hellings/${local.name}" + version = local.build + version_description = local.description + } + } +} diff --git a/sources/inputs.pkr.hcl b/sources/inputs.pkr.hcl new file mode 100644 index 0000000..009de0f --- /dev/null +++ b/sources/inputs.pkr.hcl @@ -0,0 +1,69 @@ +variable "iso" { + type = map(string) + description = "A map containing the URL and checksum for the ISO file" +} + +variable "distro" { + type = string + default = "unknown" +} + +variable "arch" { + type = string + default = "x86_64" +} + +variable "version" { + type = string + description = "The distro version being specified" +} + +variable "boot_wait" { + type = string + default = "20s" + description = "Length of time to wait before entering boot commands" +} + +variable "ssh" { + type = map(string) + default = { + username = "vagrant" + password = "vagrant" + } +} + +variable "boot_command" { + type = list(string) + default = [] +} + +variable "ssh_handshake_attempts" { + type = number + default = 100 +} + +variable "shutdown_command" { + type = string + default = "sudo systemctl poweroff" +} + +variable "disk_size" { + type = string + default = "20G" +} + +variable "headless" { + type = bool + default = true +} + +locals { + name = "${var.distro}-${var.version}-${var.arch}" + build = formatdate("YYYYMMDDhh", timestamp()) + description = templatefile("../README.box.md", { + distro = var.distro + arch = var.arch + version = var.version + build = local.build + }) +} diff --git a/sources/qemu.pkr.hcl b/sources/qemu.pkr.hcl index 5944e89..6995cde 100644 --- a/sources/qemu.pkr.hcl +++ b/sources/qemu.pkr.hcl @@ -1,73 +1,3 @@ -variable "iso" { - type = map(string) - description = "A map containing the URL and checksum for the ISO file" -} - -variable "distro" { - type = string - default = "unknown" -} - -variable "arch" { - type = string - default = "x86_64" -} - -variable "version" { - type = string - description = "The distro version being specified" -} - -variable "boot_wait" { - type = string - default = "20s" - description = "Length of time to wait before entering boot commands" -} - -variable "ssh" { - type = map(string) - default = { - username = "vagrant" - password = "vagrant" - } -} - -variable "boot_command" { - type = list(string) - default = [] -} - -variable "ssh_handshake_attempts" { - type = number - default = 100 -} - -variable "shutdown_command" { - type = string - default = "sudo systemctl poweroff" -} - -variable "disk_size" { - type = string - default = "20G" -} - -variable "headless" { - type = bool - default = true -} - -locals { - name = "${var.distro}-${var.version}-${var.arch}" - build = formatdate("YYYYMMDDhh", timestamp()) - description = templatefile("../README.box.md", { - distro = var.distro - arch = var.arch - version = var.version - build = local.build - }) -} - source "qemu" "x86_64" { iso_url = var.iso.url iso_checksum = var.iso.checksum @@ -88,34 +18,3 @@ source "qemu" "x86_64" { qemuargs = [["-serial", "stdio"]] shutdown_command = var.shutdown_command } - -build { - sources = ["source.qemu.x86_64"] - - provisioner "ansible" { - playbook_file = "ansible/playbook.yml" - galaxy_file = "ansible/requirements.yml" - } - - provisioner "shell" { - scripts = [ - "scripts/minimize.sh" - ] - } - - post-processors { - post-processor "vagrant" { - keep_input_artifact = true - compression_level = 9 - output = "${local.name}.box" - vagrantfile_template = "vagrant/${var.arch}.rb" - } - - post-processor "vagrant-cloud" { - name = "upload" - box_tag = "greg-hellings/${local.name}" - version = local.build - version_description = local.description - } - } -} diff --git a/test.sh b/test.sh index 7e81f1e..7b8854b 100755 --- a/test.sh +++ b/test.sh @@ -4,7 +4,7 @@ set -exo pipefail build="${1}" -packer build -var headless=false -var-file distros/${build}.pkrvars.hcl -except=upload sources/qemu.pkr.hcl +packer build -var headless=false -var-file distros/${build}.pkrvars.hcl -except=upload sources/ vagrant box add -f --name test ${build}.box vagrant up vagrant ssh -c "ls -la ~/"