This repository contains an example packer configuration for building a custom vagrant base box for virtualbox, and a vagrant configuration for using that base box.
To use the contents of this repo you will need the following installed
- VirtualBox - http://www.virtualbox.org/
- Vagrant - http://www.vagrantup.com/
- Packer - http://www.packer.io
Packer installation involves downloading the package for your OS (most Mac users will want the amd64 package) and moving the contents of the zip file to an executable path such as /usr/bin
This repo is setup to create an Ubuntu 13.10 Server image pre-loaded with:
- Apache 2.4
- PHP 5.5 w/ Extensions
- GD
- MySQL
- Memcached
- XDebug
- PHPUnit
- Composer
- MySQL 5.5
- Node.js w/
- Grunt
- Bower
- NodeUnit
- Memcached
- Imagemagick
- git
- vim
- wget
- zip/unzip
MySQL is setup with a root password of vagrant
.
Note that this config does NOT install Puppet or Chef, as they are not needed when all packages are pre-installed.
##Packer Config
The packer configuration consists of three parts:
- The packer json file
ubuntu.json
- The
preseed.cfg
file used instruct the linux installer - Post-install scripts in
scripts/
which are executed in the order defined in the json file.vagrant.sh
which sets up the ssh key and password-less sudo needed by vagrant to admin the VMvboxguest.sh
which installs the VirtualBox Guess Additionspackages.sh
which installs our pre-provisioned software packagescompact.sh
which cleans up the machine and prepares it for boxing
Start the build process by invoking this command from inside the packer
folder of this repo.
packer build ubuntu.json
Packer will download the Ubuntu install iso as well as the VirtualBox Guest Additions and then launch a virtualbox vm to perform the installation in. This entire process requires no user input, so just let it run. The terminal will tell you what Packer is currently doing while the VM is running. After ubuntu installation completes the VM will restart and packer will run the post-install scripts. This entire process will take 10-15 minutes.
Once packer reports "Build 'virtualbox-iso' finished." and exits, you will find a ready to use .box file in the build/
folder. This file will be somewhere around 560MB in size.
##Vagrant Config
Launch the vagrant configuration by invoking this command from inside the vagrant
folder of this repo.
vagrant up
Vagrant will automatically import the box generated by Packer under the name packer-built
. (Note that if you rebuild the image after launching this vagrant config, you will need to remove the "packer-built" box from vagrant before you'll get the new build.)
After the VM is booted it will provision the configuration files using the provisioning/initial-setup.sh
file. This is a plain bash script that simply copies various config files from the provisioning/files
folder.
Once the VM boots, you can visit http://192.168.56.151/ to confirm that Apache is running (it should display the phpinfo() output).
Apache is configured with a virtualhost of mypacker.dev
to load from /srv/www
.
PHP is configured with error reporting set to display all errors and to log errors to vagrant/srv/logs
. A mail catcher script is also setup which causes all calls to mail()
to output to vagrant/srv/logs/fakemail
instead of attempting to send the email.
A .bashrc file is setup to add the vagrant/bin/
folder to the execute path, allowing any scripts added to it to be called directly.
##More Information
- Packer Docs: Getting Started
- Packer, Vagrant and your Infrastructure
- Building Vagrant Machines with Packer: A step-by-step Guide
- Mischa Taylor maintains a huge collection of packer configurations: https://github.com/misheska/basebox-packer