本地 Packer Box 版本控制

Local Packer Box Versioning

是否可以使用 Packer 在我的本地计算机上完全对一个框 created/hosted 进行版本控制,而无需在 HashiCorp Atlas 上发布它?当我执行 vagrant box list 时,我得到如下内容:

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

在最后一列显示盒子版本。我希望能够在打包过程中更改该号码。他们的文档似乎建议我只能通过使用他们的 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

这可以通过模仿 Vagrant 对 HashiCorp Atlas API 的期望来实现。创建一个 JSON 文件,包括在他们的 API 文档(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"
        }
      ]
    }
  ]
}

将其另存为 boxname.json(我认为这不是必需的,但我相信这是 Atlas 惯例)。然后简单地从你那里调用它 Vagrantfile 就这样

# 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"

在这里你可以找到详细的描述 - http://sysadm.pp.ua/linux/vagrant-versioning.html 总的来说:

  1. 安装网络服务器(apache、nginx 等)
  2. 添加虚拟主机JSON
  3. 文件,喜欢在向上评论
  4. 上传打包好的盒子到本主机
  5. 将 Vagrant 文件中的 URL 添加到此 JSON

样本:

  • 网络服务器

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

    config.vm.box = "Ubuntu 16.04"

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