Skipping Provisioning by Saving a Preconfigured Vagrant Box

Why you might want to do this

Even though automatic provisioning with Vagrant is great, because it allows you to take a download a publicly available base image that takes up gigs of space and custom configure it with a very small, easily shareable repo, sometimes it would be really nice to skip provisioning, because it can take a long time. Downloading and setting up things like databases or Java or things with tons of dependencies can take a long time, and you also need an internet connection to do the provisioning. Sometimes, it would be nice to just have something preconfigured, so you don’t have to wait for the install process to go through. Preconfigured boxes will be bigger, but sometimes that’s ok. You have a larger download up front but don’t have to wait for the setup. So if you have a complicated provisioning process that takes a long time, this is what you can do.

Use an existing environment

If you already have a box, just vagrant up, and then vagrant ssh into it.

Otherwise, for the sake of making this post self-contained:

Terminal
1
2
3
4
5
$ mkdir vagrant_example
$ cd vagrant_example
$ vagrant init precise64 http://files.vagrantup.com/precise64.box
$ vagrant up
$ vagrant ssh

Now you can install some random program. We’ll install Appium:

Terminal
1
2
3
4
5
6
vagrant@precise64:~$ wget http://nodejs.org/dist/v0.10.20/node-v0.10.20-linux-x64.tar.gz
vagrant@precise64:~$ tar zxvf http://nodejs.org/dist/v0.10.20/node-v0.10.20-linux-x64.tar.gz
vagrant@precise64:~$ echo 'PATH="$PATH:$HOME/node-v0.10.20-linux-x64/bin"' >> ~/.bashrc
vagrant@precise64:~$ source ~/.bashrc
vagrant@precise64:~$ sudo npm install -g appium
vagrant@precise64:~$ sudo npm install wd

Finally, exit out of ssh with CTRL-D and type vagrant package. Vagrant will tell you where it puts the box. You can rename it, copy it, distribute it, and share it on a local network or on the internet.

Comments