Vagrant by example: Setting up Phantomjs

Vagrant is an amazing tool, especially switching between projects it comes in
handy to keep the dependencies separated. This works even better with puppet to
provision the machines in a reproducible fashion.

Installing vagrant

First things first, we need to install vagrant,
which has changed some time ago from being a gem to provide
installer packages. Installation now is really
simple, just download and install.

Setting up vagrant

To get of the ground lets setup an example box.

$ mkdir myproject && cd myproject
$ vagrant init precise32 http://files.vagrantup.com/precise32.box

This will download, and setup a basic box with ubuntu precise32.

Configure puppet

Inside the Vagrantfile we now configure vagrant to use
puppet, to provision the box for us. This will make
it easy to spin up a similar box whenever we need a new one.

http://gist-it.appspot.com/github/sideshowcoder/puppet-vagrant-by-example/blob/master/Vagrantfile?slice=55:76

Personally I prefer to modify the default vagrant behavior a bit and keep
everything puppet under puppet/* inside the project.

Setting up phantomjs

Now to the meat of this example, setting up phantomjs from the tarball download

Netinstall

Luckily the good guys from example42 provide a nice
puppet module to handle just these installs, it comes packaged with
puppi. Right now puppi seems a little much
such we just extract the netinstall code inside a module of its own and set it
up
inside the repo
Netinstall is a quite simple module, the only dependency we need to worry about
is the uri_parser which is implemented as a ruby extension and located in lib.
I also decided to rename netinstall.pp to init.pp since it is autoloaded
this way, and removed the puppi prefix.

http://gist-it.appspot.com/github/sideshowcoder/puppet-vagrant-by-example/blob/master/puppet/modules/netinstall/manifests/init.pp

Setting up the init.pp

Under manifests we can now create the custom init.pp in which we install
phantomjs and libfontconfig1 on which it depends.

http://gist-it.appspot.com/github/sideshowcoder/puppet-vagrant-by-example/blob/master/puppet/manifests/init.pp

Vagrant up

Now a simple

$ vagrant up

Will provision the machine with phantomjs installed, which we can test via after
provisioning is done.

$ vagrant ssh
$ phantomjs

Missed something?

Installing new packages is now easy as adding them to the init.pp file and
running

$ vagrant provision

Bundle all the dependencies!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s