Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the version number of a Vagrant box using a Packer build?

The version of the box that is added is always v0; how can I change this value? For example, when I do a vagrant box list, my box is always version v0.

I'm creating a VirtualBox Vagrant "box" using Packer, but I can't figure out how to set the version of the box output.

The Packer build command consumes a builder JSON file

$ packer build builder.json

...

==> virtualbox-iso (vagrant): Creating Vagrant box for 'virtualbox' provider
    virtualbox-iso (vagrant): Copying from artifact: dist-28/ion-disk001.vmdk
    virtualbox-iso (vagrant): Copying from artifact: dist-28/ion.ovf
    virtualbox-iso (vagrant): Renaming the OVF to box.ovf...
    virtualbox-iso (vagrant): Compressing: Vagrantfile
    virtualbox-iso (vagrant): Compressing: box.ovf
    virtualbox-iso (vagrant): Compressing: ion-disk001.vmdk
    virtualbox-iso (vagrant): Compressing: metadata.json

and the output of the Packer step above is Vagrant box called packer_virtualbox-iso_virtualbox.box, which I then add to Vagrant using

$ vagrant box add BOX_NAME packer_virtualbox-iso_virtualbox.box
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'BOX_NAME' (v0) for provider: 
    box: Unpacking necessary files from: file:///packer/packer_virtualbox-iso_virtualbox.box
==> box: Successfully added box 'BOX_NAME' (v0) for 'virtualbox'!

I want to change the value v0 to something else. This is the contents of builder.json

{
  "builders": [
    {
      "type": "virtualbox-iso",
      "vm_name": "ion-${ION_BUILD_NUMBER}",
      "output_directory": "dist-${ION_BUILD_NUMBER}",
      "iso_url": "${ISO_URL}",
      "iso_checksum": "${MD5}",
      ...
    }
  ],
  "post-processors": [
    "vagrant"
  ]
}
like image 463
activedecay Avatar asked Sep 15 '25 06:09

activedecay


1 Answers

There was an issue fixed so you can now provide your own metadata.json file

see the content of the box metadata

{
  "name": "xxxx",
  "description": "xxxx",
  "versions": [
    {
      "version": "0.1.0",
      "providers": [
        {
          "name": "virtualbox",
        }
      ]
    }
  ]
}
like image 90
Frederic Henri Avatar answered Sep 17 '25 19:09

Frederic Henri