Skip to content

Commit

Permalink
set the vagrant box version to 0.0.0
Browse files Browse the repository at this point in the history
this is especially convenient for having a stable libvirt disk file name that can be referenced in terraform projects
  • Loading branch information
rgl committed Jan 12, 2023
1 parent 5bc801f commit 429b4aa
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
packer_cache/
tmp/
*.box
*.box.json
*.log
output*
*-packages.txt
Expand Down
16 changes: 4 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 $@)
Expand All @@ -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
Expand Down
35 changes: 35 additions & 0 deletions box-metadata.sh
Original file line number Diff line number Diff line change
@@ -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" <<EOF
{
"name": "$name",
"versions": [
{
"version": "0.0.0",
"providers": [
{
"name": "$provider",
"url": "$path"
}
]
}
]
}
EOF
cat <<EOF
Add the Vagrant Box with:
vagrant box add -f $name $path.json
EOF

0 comments on commit 429b4aa

Please sign in to comment.