通过 http 获取 vagrant box 定义
Getting vagrant box definition by http
我们公司有几个 vagrant boxes 和他们的 Vagrantfiles 目前非常相似,重现我正在处理的问题的最小代码是
Vagrant.configure("2") do |config|
config.vm.box = "some_box_name"
case RbConfig::CONFIG['host_os']
when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
config.vm.box_url = "file:////smbhost.ourintra.net/VagrantBoxes/" + config.vm.box + ".json"
when /darwin|mac os/
config.vm.box_url = "file:///Volumes/VagrantBoxes/" + config.vm.box + ".json"
else
config.vm.box_url = "file:///media/VagrantBoxes/" + config.vm.box + ".json"
end
config.vm.network :public_network
end
some_box_name.json 将 link 到实际的 .box 文件:
{
"name":"some_box_name",
"versions":[
{
"version":"1.1337",
"status":"active",
"providers":[
{
"name":"virtualbox",
"url":"http://httphost.ourintra.net/Public/VagrantBoxes/some_box_name-1337.box"
}
]
}
]
}
上面的解决方案适用于我和我的同事,但我不喜欢每次都安装 VagrantBoxes,我相信应该有更优雅的方法,所以我尝试参考 json http(它位于 httphost 上的 .box 文件附近):
Vagrant.configure("2") do |config|
config.vm.box = "some_box_name"
config.vm.box_url = "http://httphost.ourintra.net/Public/VagrantBoxes/" + config.vm.box + ".json"
config.vm.network :public_network
end
此解决方案无效:
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'some_box_name' could not be found. Attempting to find and install...
default: Box Provider: virtualbox
default: Box Version: >= 0
==> default: Box file was not detected as metadata. Adding it directly...
==> default: Adding box 'some_box_name' (v0) for provider: virtualbox
default: Downloading: http:/httphost.ourintra.net/Public/VagrantBoxes/some_box_name.json
The box failed to unpackage properly. Please verify that the box
file you're trying to add is not corrupted and that enough disk space
is available and then try again.
The output from attempting to unpackage (if any):
bsdtar: Error opening archive: Unrecognized archive format
我相信 vagrant 认为我正在尝试为它提供直接的 .box url,但我不想这样做,因为 box 文件名在每次构建和 .json 名称是静态的。是否可以通过更改 Vagrantfiles 而不对远程文件布局做太多更改来解决此问题?
我找到了答案 in the similar question on superuser,我的问题出在网络服务器返回的 Content-Type 中。解决方案:
Content-Type: application/json
我们公司有几个 vagrant boxes 和他们的 Vagrantfiles 目前非常相似,重现我正在处理的问题的最小代码是
Vagrant.configure("2") do |config|
config.vm.box = "some_box_name"
case RbConfig::CONFIG['host_os']
when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
config.vm.box_url = "file:////smbhost.ourintra.net/VagrantBoxes/" + config.vm.box + ".json"
when /darwin|mac os/
config.vm.box_url = "file:///Volumes/VagrantBoxes/" + config.vm.box + ".json"
else
config.vm.box_url = "file:///media/VagrantBoxes/" + config.vm.box + ".json"
end
config.vm.network :public_network
end
some_box_name.json 将 link 到实际的 .box 文件:
{
"name":"some_box_name",
"versions":[
{
"version":"1.1337",
"status":"active",
"providers":[
{
"name":"virtualbox",
"url":"http://httphost.ourintra.net/Public/VagrantBoxes/some_box_name-1337.box"
}
]
}
]
}
上面的解决方案适用于我和我的同事,但我不喜欢每次都安装 VagrantBoxes,我相信应该有更优雅的方法,所以我尝试参考 json http(它位于 httphost 上的 .box 文件附近):
Vagrant.configure("2") do |config|
config.vm.box = "some_box_name"
config.vm.box_url = "http://httphost.ourintra.net/Public/VagrantBoxes/" + config.vm.box + ".json"
config.vm.network :public_network
end
此解决方案无效:
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'some_box_name' could not be found. Attempting to find and install...
default: Box Provider: virtualbox
default: Box Version: >= 0
==> default: Box file was not detected as metadata. Adding it directly...
==> default: Adding box 'some_box_name' (v0) for provider: virtualbox
default: Downloading: http:/httphost.ourintra.net/Public/VagrantBoxes/some_box_name.json
The box failed to unpackage properly. Please verify that the box
file you're trying to add is not corrupted and that enough disk space
is available and then try again.
The output from attempting to unpackage (if any):
bsdtar: Error opening archive: Unrecognized archive format
我相信 vagrant 认为我正在尝试为它提供直接的 .box url,但我不想这样做,因为 box 文件名在每次构建和 .json 名称是静态的。是否可以通过更改 Vagrantfiles 而不对远程文件布局做太多更改来解决此问题?
我找到了答案 in the similar question on superuser,我的问题出在网络服务器返回的 Content-Type 中。解决方案:
Content-Type: application/json