From 429b4aad3f0ff3a5aab293d13eaae6c30cf38bbc Mon Sep 17 00:00:00 2001 From: Rui Lopes Date: Thu, 12 Jan 2023 15:05:17 +0000 Subject: [PATCH] set the vagrant box version to 0.0.0 this is especially convenient for having a stable libvirt disk file name that can be referenced in terraform projects --- .gitignore | 1 + Makefile | 16 ++++------------ box-metadata.sh | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 12 deletions(-) create mode 100755 box-metadata.sh diff --git a/.gitignore b/.gitignore index 0f7f35a..e198d08 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ packer_cache/ tmp/ *.box +*.box.json *.log output* *-packages.txt diff --git a/Makefile b/Makefile index e11c830..f5c6c1e 100644 --- a/Makefile +++ b/Makefile @@ -16,17 +16,13 @@ ubuntu-${VERSION}-amd64-libvirt.box: autoinstall-cloud-init-data/* provision.sh rm -f $@ PACKER_KEY_INTERVAL=10ms CHECKPOINT_DISABLE=1 PACKER_LOG=1 PACKER_LOG_PATH=$@.log PKR_VAR_vagrant_box=$@ \ packer build -only=qemu.ubuntu-amd64 -on-error=abort -timestamp-ui ubuntu.pkr.hcl - @echo BOX successfully built! - @echo to add to local vagrant install do: - @echo vagrant box add -f ubuntu-${VERSION}-amd64 $@ + @./box-metadata.sh libvirt ubuntu-${VERSION}-amd64 $@ ubuntu-${VERSION}-uefi-amd64-libvirt.box: tmp/libvirt-uefi-autoinstall-cloud-init-data/user-data autoinstall-cloud-init-data/* provision.sh ubuntu.pkr.hcl Vagrantfile-uefi.template rm -f $@ PACKER_KEY_INTERVAL=10ms CHECKPOINT_DISABLE=1 PACKER_LOG=1 PACKER_LOG_PATH=$@.log PKR_VAR_vagrant_box=$@ \ packer build -only=qemu.ubuntu-uefi-amd64 -on-error=abort -timestamp-ui ubuntu.pkr.hcl - @echo BOX successfully built! - @echo to add to local vagrant install do: - @echo vagrant box add -f ubuntu-${VERSION}-uefi-amd64 $@ + @./box-metadata.sh libvirt ubuntu-${VERSION}-uefi-amd64 $@ tmp/libvirt-uefi-autoinstall-cloud-init-data/user-data: autoinstall-cloud-init-data/user-data mkdir -p $(shell dirname $@) @@ -36,17 +32,13 @@ ubuntu-${VERSION}-amd64-virtualbox.box: autoinstall-cloud-init-data/* provision. rm -f $@ CHECKPOINT_DISABLE=1 PACKER_LOG=1 PACKER_LOG_PATH=$@.log PKR_VAR_vagrant_box=$@ \ packer build -only=virtualbox-iso.ubuntu-amd64 -on-error=abort -timestamp-ui ubuntu.pkr.hcl - @echo BOX successfully built! - @echo to add to local vagrant install do: - @echo vagrant box add -f ubuntu-${VERSION}-amd64 $@ + @./box-metadata.sh virtualbox ubuntu-${VERSION}-amd64 $@ ubuntu-${VERSION}-amd64-hyperv.box: tmp/hyperv-autoinstall-cloud-init-data/user-data autoinstall-cloud-init-data/* provision.sh ubuntu.pkr.hcl Vagrantfile.template rm -f $@ CHECKPOINT_DISABLE=1 PACKER_LOG=1 PACKER_LOG_PATH=$@.log PKR_VAR_vagrant_box=$@ \ packer build -only=hyperv-iso.ubuntu-amd64 -on-error=abort -timestamp-ui ubuntu.pkr.hcl - @echo BOX successfully built! - @echo to add to local vagrant install do: - @echo vagrant box add -f ubuntu-${VERSION}-amd64 $@ + @./box-metadata.sh hyperv ubuntu-${VERSION}-amd64 $@ # see https://docs.microsoft.com/en-us/windows-server/virtualization/hyper-v/supported-ubuntu-virtual-machines-on-hyper-v tmp/hyperv-autoinstall-cloud-init-data/user-data: autoinstall-cloud-init-data/user-data diff --git a/box-metadata.sh b/box-metadata.sh new file mode 100755 index 0000000..83f1881 --- /dev/null +++ b/box-metadata.sh @@ -0,0 +1,35 @@ +#!/bin/bash +set -euo pipefail + +provider="$1" +name="$2" +path="$3" + +# see https://developer.hashicorp.com/vagrant/docs/boxes/format#box-metadata +# see https://developer.hashicorp.com/vagrant/docs/boxes/format#box-file +# see https://github.com/hashicorp/packer-plugin-vagrant/blob/v1.0.3/post-processor/vagrant/libvirt.go#L100-L105 +# see https://github.com/vagrant-libvirt/vagrant-libvirt/blob/0.11.2/spec/unit/action/handle_box_image_spec.rb#L96-L125 +# see https://github.com/vagrant-libvirt/vagrant-libvirt/blob/0.11.2/lib/vagrant-libvirt/action/handle_box_image.rb +# see https://github.com/vagrant-libvirt/vagrant-libvirt/blob/0.11.2/docs/boxes.markdown +cat >"$path.json" <