Setup a MapServer Development Environment With Vagrant and Chef

A month ago, I watched a DjangoCon 2012 presentation of Julien Phalip named Boosting teamwork with Vagrant. For those who are not familiar with Vagrant, it’s a tool that allows you to create and configure lightweight, reproducible and portable development environments. In the presentation, the case study #1 shows how he built a complete development environment for djangoproject.com. I found it very interesting that a user can setup itself and hence be ready very quickly to contribute to the project.

I’ve been wanted to try Vagrant for a while now and I thought it would be useful to build something similar for mapserver. To help the setup, I also decided to use Chef Solo, which is a tool that allows you to abstract definitions as source code to describe how you want each part of your infrastructure to be built. In my case, I wanted to automate the various configuration tasks rather than doing them by hands.

Before starting the tutorial, you might be interested in learning more about:

Goal

The goal was to get a complete development environment (Ubuntu precise 32bits) with all the following requirements:

  • Configure and install mapserver (branch master, 6.2 and 6.0).
  • Configure and build mapserver docs
  • Configure mapserver msautotest
  • Install Postgresql server, create DB, load msautotest DB data
  • Install and configure web server
  • Serve mapserver as cgi and fastcgi (All versions)
  • Serve mapserver docs website

To setup these requirements, I’ve built a chef cookbook to take care of everything. You won’t have to configure the environment by hands. The tutorial has been tested on a Linux machine but should work properly on Windows and Mac with some adaptations.

Prerequisites

You need the following softwares installed before doing the tutorial.

  • Virtualbox
  • Ruby 1.9, Ruby Bundler and some module dependencies (libxslt, libxml2)

    • For Windows, you can probably find binaries easily.
    • For Mac, I would suggest that you use homebrew.
    • On a Debian/Ubuntu machine, you can use the following command:
1
2
3
  sudo apt-get install ruby1.9.1 ruby1.9.1-dev libxslt-dev libxml2-dev
  sudo gem1.9.1 install bundler

Setup

  • Download the mapserver environment config files. This contains everything you need to make the development environment.
1
2
wget http://dl.alanb.ca/mapserver-dev-1.0.0.tar.gz
tar -zxvf mapserver-dev-1.0.0.tar.gz
  • Setup the ruby environment. This will install all needed ruby modules in the working directory.
1
2
cd mapserver-dev-1.0.0
bundle
  • You might want to take a look at the Vagranfile and edit some config options:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# -*- mode: ruby -*-

require 'berkshelf/vagrant'

Vagrant::Config.run do |config|

  config.vm.host_name = "mapserver-dev"
  config.vm.box = "precise32"
  config.vm.box_url = "http://files.vagrantup.com/precise32.box"

  config.vm.network :hostonly, "192.168.33.2"

  # Modify this if port 8002 or 2202 are already used.
  config.vm.forward_port  80, 8002
  config.vm.forward_port  22, 2202

  # You can comment this if you don't want to share your home directory, or add
  # any other share folders you need in your dev environment. It is known that
  # this share method is slower than a nfs share, so you may be interested in
  # http://docs-v1.vagrantup.com/v1/docs/nfs.html
  config.vm.share_folder "v-data", "/vagrant_data", "~"

  config.ssh.max_tries = 40
  config.ssh.timeout   = 120

  # Set the virtual environment resource.
  config.vm.customize ["modifyvm", :id, "--cpus", 2]
  config.vm.customize ["modifyvm", :id, "--memory", 1024]

  # do not touch...
  config.vm.provision :chef_solo do |chef|
    chef.run_list = [
      "recipe[mapserver-dev::default]"
    ]
  end

end
  • Make the virtual environment. This will download, setup and install everything.
1
bundle exec vagrant up

This step might take several minutes to complete.

Conclusion

When the setup is finished, you should have a complete development environment for the mapserver project.

  • Basic Vagrant commands:

    • Start the virtual machine: bundle exec vagrant up

    • Stop the virtual machine: bundle exec vagrant halt

    • Destroy the virtual machine: bundle exec vagrant destroy

  • You can log in the machine with one of the following methods:

    • In the working directory of the environment: bundle exec vagrant ssh

    • ssh (user: vagrant, pw: vagrant) ssh -p 2202 vagrant@localhost

  • The source code of the different mapserver versions, mapserver doc and msautotest are in /home/vagrant/src.

  • You can run the msautotest with the usual python run_test.py command. All tests should be succeeded, including postgresql/postgis ones.

  • You can rebuild the doc using make html.

  • Mapserver executables are served by apache2:

Project

The chef mapserver dev cookbook is on github, feel free to contribute.

TODO

In the future versions of the chef mapserver dev cookbook, mapcache and tinyows will be added.

Comments