简体   繁体   English

使用Packer从“无业游民”框创建VM映像?

[英]Create a VM image from a Vagrant box using Packer?

I know that I can use Packer to create my own VM images in a scripted way. 我知道我可以使用Packer以脚本方式创建自己的VM映像。 If I use the VirtualBox builder, I can choose from one of two flavors: Building everything from scratch, or building on top of an existing VM. 如果使用VirtualBox构建器,则可以选择以下两种方式之一:从头开始构建所有内容,或者在现有VM之上构建。

Basically, what I would like to achieve is to build on top of an existing Vagrant box (Ubuntu 15.04 with Docker by Boxcutter). 基本上,我想实现的目标是在现有的Vagrant盒(Boxcutter的Docker的Ubuntu 15.04)的基础上构建。

Is this possible using Packer, and if so, how? 是否可以使用Packer,如果可以,如何? I was not able to find anything on this in the documentation. 我在文档中找不到任何内容。 The samples always only refer to OVF/OVA files. 这些示例始终仅引用OVF / OVA文件。 Any hints? 有什么提示吗?

This isn't really a workflow natively supported by Packer, but you could write a small shell script to download the Vagrant box, export the OVF and then kick off Packer's virtualbox-ovf builder. 这实际上不是Packer本身支持的工作流程,但是您可以编写一个小的Shell脚本来下载Vagrant框,导出OVF,然后启动Packer的virtualbox-ovf构建器。

The shell script (note this is hardcoded to the 1.1.0 version of the box) Shell脚本(请注意,此脚本已硬编码到包装盒的1.1.0版本中)

#!/bin/sh

vagrant init boxcutter/ubuntu1504-docker
vagrant up --provider virtualbox --no-provision
vagrant halt

rm -rf output-virtualbox-ovf
packer build packer.json

packer.json packer.json

{
  "variables": {
    "home": "{{env `HOME`}}"
  },
  "builders": [{
    "type": "virtualbox-ovf",
    "source_path": "{{user `home`}}/.vagrant.d/boxes/boxcutter-VAGRANTSLASH-ubuntu1504-docker/1.1.0/virtualbox/box.ovf",
    "ssh_username": "vagrant",
    "ssh_password": "vagrant",
    "ssh_wait_timeout": "30s",
    "shutdown_command": "echo 'packer' | sudo -S shutdown -P now"
  }],
  "provisioners": [{
    "type": "shell",
    "inline": ["echo 'my additional provisioning steps'"]
  }],
  "post-processors": [{
    "type": "vagrant",
    "keep_input_artifact": true,
    "output": "box/modified-boxcutter-VAGRANTSLASH-ubuntu1504-docker.box"
  }]
}

This will create a new Vagrant box packaged up in box/modified-boxcutter-VAGRANTSLASH-ubuntu1504-docker.box . 这将创建一个打包在box/modified-boxcutter-VAGRANTSLASH-ubuntu1504-docker.box中的新的Vagrant盒子。

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

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