Create a virtual machine image from a vagrant box with Packer?

I know that I can use Packer to create my own VM images with a script. If I use the VirtualBox builder, I can choose one of two options: create everything from scratch or build on top of an existing virtual machine.

Basically, what I would like to achieve is build on top of an existing Vagrant box (Ubuntu 15.04 with Docker by Boxcutter).

Is it possible to use Packer, and if so, how? I could not find anything in the documentation. Samples always refer to OVF / OVA files only. Any clues?

+5
source share
1 answer

This is actually not a workflow supported by Packer, but you can write a small shell script to load the Vagrant box, export OVF, and then run Packer virtualbox-ovf .

Shell script (note that this is tightly bound to version 1.1.0 version)

#!/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

 { "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 in box/modified-boxcutter-VAGRANTSLASH-ubuntu1504-docker.box .

+5
source

All Articles