简体   繁体   English

从预下载的无业游民框创建Packer映像

[英]Creating Packer Image from Pre-downloaded vagrant box

I downloaded a Ubuntu 64 Trust vagrant box for vagrant and fired it up and it works fine. 我下载了一个Ubuntu 64 Trust vagrant框用于流浪汉并将其启动,并且工作正常。

vagrant box add /local/path/to/downloaded/box.box
vagrant init
vagrant up
vagrant ssh

I made sure to use a script to update the system, create users, enable port forwarding, generate ssh keys, install dependencies etc. upon startup from the Vagrant file itself. 从Vagrant文​​件本身启动时,我确保使用脚本来更新系统,创建用户,启用端口转发,生成ssh密钥,安装依赖项等。 It also copies a flask and postgres web app from my local environment into the vagrant machine to be run on apache, and it all works fine. 它还将本地环境中的flask和postgres Web应用程序复制到可在apache上运行的流浪机器中,并且一切正常。 finally packed the box manually using: 最后使用以下命令手动包装盒子:

vagrant package --base box-name

Only then did I learn about Packer. 直到那时我才了解Packer。 (face palm) (脸掌)

I learnt that you can automate this whole process. 我了解到您可以使整个过程自动化。 So right now, I have my flask and Postgres web app, and a pre-downloaded vagrant box. 因此,现在,我有了我的烧瓶和Postgres Web应用程序,以及一个预下载的流浪汉盒子。 I have gone through the documentation and I'm fairly comfortable with writing the packer templates, provisioning them, setting up builders etc. It's marvelous. 我已经阅读了文档,并且非常熟悉编写打包程序模板,对其进行配置,设置构建器等。这非常了不起。

But all the examples and docs have to do with downloading the Ubuntu ISO, configuring it according to the template, and converting it into a platform deployable image for either Amazon, Digital Ocean, Google, azure etc etc and to finally use a post-process to turn it into a vagrant box. 但是所有示例和文档都与下载Ubuntu ISO,根据模板进行配置以及将其转换为适用于Amazon,Digital Ocean,Google,azure等的平台可部署映像有关,并最终使用了后期处理把它变成一个无聊的盒子

They don't talk about using a pre downloaded vagrant box to do the same. 他们没有谈论使用预下载的无用信息框来执行相同的操作。 My question is, if it is possible to use a pre downloaded vagrant box along with packer to create a machine image for platforms that are supported by amazon, azure etc? 我的问题是,是否有可能使用预下载的无业游民框以及打包程序来为亚马逊,天青等支持的平台创建机器映像?

If so, how may I go about it? 如果是这样,我该怎么办?

You cannot take an existing vagrant box as an input for a packer builder. 您不能将现有的无用信息框作为打包程序构建器的输入。 Along the new versions packer has added a lot of new builder so you can build a new packer image from existing virtual VM , for amazon you can have input as existing EBS drive , existing amazon instance , or amazon chroot etc etc .. you should check the packer builder doc 沿着新版本,packer添加了很多新的生成器,因此您可以从现有的虚拟VM构建新的packer映像,对于Amazon,您可以输入现有的EBS驱动器现有的Amazon实例Amazon chroot等。打包机生成器文档

As mentioned by Frédéric, it is possible to use the virtualbox-ovf/vmware-vmx builders to take an existing VM as input to Packer, run provisioning and then output a new box. 如Frédéric所述,可以使用virtualbox-ovf / vmware-vmx构建器将现有的VM用作Packer的输入,运行配置,然后输出一个新框。 For your use case, you can use one of these builders and set the source_path variable to the ovf/vmx file associated with the box you want to start from. 对于您的用例,可以使用这些构建器之一,并将source_path变量设置为与要从其开始的框关联的ovf / vmx文件。

For example, if you added the official Ubuntu Trusty box using: 例如,如果您使用以下命令添加了官方的Ubuntu Trusty框

vagrant box add ubuntu/trusty64

you should end up with an ovf file that you can use in your virtualbox-ovf builder's source_path variable at the following location: 您应该最终得到一个ovf文件,该文件可以在以下位置的virtualbox-ovf构建器的source_path变量中使用:

$HOME/.vagrant.d/boxes/ubuntu-VAGRANTSLASH-trusty64/20160908.0.0/virtualbox/box.ovf

Notes: 笔记:

  • We use the above process with the vmware-vmx builder, but I haven't tested using the virtualbox-ovf builder. 我们将上述过程与vmware-vmx构建器一起使用,但是我尚未使用virtualbox-ovf构建器进行测试。 My understanding is that they work similarly. 我的理解是它们的工作方式相似。
  • The above example is using the official box from Atlas, but you should be able to find a similar directory structure under ~/.vagrant.d/boxes/ for any local boxes you have already downloaded 上面的示例使用的是Atlas的官方文件~/.vagrant.d/boxes/ ,但是对于已经下载的任何本地文件~/.vagrant.d/boxes/ ,您都可以在~/.vagrant.d/boxes/下找到类似的目录结构
  • The path to the ovf will change when new boxes are released, but it shouldn't be difficult to script or manually update the path to the new version as needed. 发行新盒子时,ovf的路径将更改,但是编写脚本或根据需要手动将路径更新为新版本并不难。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM