Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Local Packer Box Versioning

Is it possible to version a box created/hosted entirely on my local machine using Packer without publishing it on the HashiCorp Atlas? When I do a vagrant box list I get something like the following:

vagrant box list
Win8        (virtualbox, 0)
dummy       (aws, 0)

Which shows the box version in the last column. I'd like to be able to change that number during the packing process. Their docs seem to suggest I can only get this functionality from using their Atlas:

if you want to support versioning, putting multiple providers at a single URL, pushing updates, analytics, and more, we recommend you add the box to HashiCorp's Atlas

like image 898
Joel B Avatar asked Aug 11 '15 21:08

Joel B


2 Answers

This is possible by mimicking what Vagrant expects from the HashiCorp Atlas API. Create a JSON file including the relevant box metadata as alluded to in their API docs(here on VagrantUp and here on Atlas):

{
  "description": "A long description of your box.",
  "short_description":"Short description",
  "name": "yourname/boxname",
  "versions": [
    {
      "version": "1.0.0",
      "status":"revoked",
      "description_html":null,
      "description_markdown":null,
      "created_at" : "2015-08-13T07:39:00.000Z",
      "updated_at" : "2015-08-13T07:39:00.000Z",
      "providers": [
        {
          "checksum": "foo",
          "checksum_type": "md5",
          "name": "virtualbox",
          "url": "file:////192.168.1.1/Vagrant/ubuntu-14-04-x64-virtualbox-1.0.0.box"
        }
      ]
    },
    {
      "version": "1.1.0",
      "status":"active",
      "description_html":null,
      "description_markdown":null,
      "created_at" : "2015-08-15T19:05:00.000Z",
      "updated_at" : "2015-08-15T19:05:00.000Z",
      "providers": [
        {
          "checksum": "bar",
          "checksum_type": "md5",
          "name": "virtualbox",
          "url": "file:////192.168.1.1/Vagrant/ubuntu-14-04-x64-virtualbox-1.1.0.box"
        }
      ]
    }
  ]
}

Save it as boxname.json (I don't think it's required, but that is the Atlas convention I believe). Then simply call it from you Vagrantfile as such

# Enable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
config.vm.box_check_update = true

# The path to the box metadata file
config.vm.box = "yourname/boxname"
config.vm.box_url = "file://./boxname.json"
like image 59
Joel B Avatar answered Nov 03 '22 19:11

Joel B


Here you can find detailed description - http://sysadm.pp.ua/linux/vagrant-versioning.html In general:

  1. Install web server(apache, nginx, etc.)
  2. Add Virtual host with JSON
  3. file, like in upward comment
  4. Upload packaged box to this host
  5. Add URL in Vagrant file to this JSON

Sample:

  • WEB server

            "name": "virtualbox",
            "url": "http://my-vagrant-repo.home.ua/ubuntu_16.04/Ubuntu16.04_1.0.0.box",
            "checksum_type": "md5",
            "checksum": "72f0b69b12bdac1307efee3537ea31aa"
    
  • Vagrant file

    config.vm.box = "Ubuntu 16.04"

    config.vm.box_url = "http://my-vagrant-repo.home.ua/ubuntu_16.04/ubuntu_16.04.json"

like image 1
alex Avatar answered Nov 03 '22 18:11

alex