Recently a coworker of mine (@hectcastro) turned me on to Vagrant. In their words: “Vagrant is a tool for building and distributing virtualized development environments.” What does that mean for me? No more installing all sorts of madness for the variety of servers I need to work with in our somewhat mixed-technology environment. In essence, disposable VMs for local development once Chef is configured to provision the machines properly. Because I needed to update an older ColdFusion application last week, and didn’t have it installed, I figured it was as good an excuse as any to kick the tires a little. Here’s what I did:
- Install Vagrant
$ gem install vagrant
- Install their Lucid Box
$ vagrant box add base http://files.vagrantup.com/lucid32.box
- Create a new folder, initialize vagrant and checkout the chef repo. Vagrant will end up sharing this folder with the VM, which makes it handy for moving extraneous files around.
$ mkdir YOUR_FOLDER $ cd YOUR_FOLDER $ vagrant init $ git clone gitosis@MYREPO:cfenv-chef.git
- Modify the
Vagrantfileto change the VM specs, base box, IP you’ll access it on, and set up chef provisioning. Here are the relevant lines from my setup:# Every Vagrant virtual environment requires a box to build off of. config.vm.box = "lucid32" # Assign this VM to a host only network IP, allowing you to access it # via the IP. config.vm.network "33.33.33.50" # Boost the RAM slightly and give it a reasonable name config.vm.customize do |vm| vm.memory_size = 512 vm.name = "CFEnv" end # Enable provisioning with chef solo, specifying a cookbooks path (relative # to this Vagrantfile), and adding some recipes and/or roles. # config.vm.provision :chef_solo do |chef| chef.cookbooks_path = "cfenv-chef/cookbooks" chef.roles_path = "cfenv-chef/roles" chef.add_role "cfserver" end
- Bring it up! (It takes a few minutes the first time.) When it’s done you should have CF running on port 8500 of the ip you specified in the
Vagrantfile. It’s installed in/opt/coldfusionif you need to find it, and the administrator password is set by the chef cookbook.$ vagrant up
- What I do after this is share folders into the CF root so I can edit locally, but run in the VM. Here’s two examples which you can modify to your own taste (also in
Vagrantfile):config.vm.share_folder "kw-core", "/opt/coldfusion/wwwroot/core", "~/Sites/core" config.vm.share_folder "kw", "/opt/coldfusion/wwwroot/knowledge", "~/Sites/knowledge"
- To see your changes to the file shares, run a
vagrant reload. If you modify the chef stuff, you can run avagrant provisionto kick off a chef run. Because of the way I set up the chef recipe, that will also have the side effect of restarting CF. Just for reference, you can log into the box withvagrant ssh. That’s it!
“But where is the link to this chef repo!” you ask? Well, because I developed it just for myself I embedded the CF installer in it (which isn’t open source). However, because some co-workers have shown some interest, I’ll change a few things and try to get up it publicly. More importantly, I was able to provision a machine for local development without having to install any of the footprint of the app server I really didn’t want to install locally, and think this could be a very powerful solution for developing in a mixed-technology enviroment, or even in a single tech workplace for consistency of dev setups.
UPDATE: I moved the installer of the repo and pushed it to github with slightly modified directions.
