Every developer on the team had a different operating system, a different version of Java, a differently configured Tomcat. The result? “Works on my machine” became our unofficial motto. Then we discovered Vagrant and everything changed.
The problem: snowflake environments¶
In a team of twelve developers we had at least five different configurations. Someone on Windows 7, someone on Windows 8, two colleagues on Ubuntu, one on Fedora. Everyone had a different JDK version, different environment variables, a different way of running the local database. Onboarding a new colleague took two days — two days of setting up the environment, finding the right library versions, solving mysterious errors.
Vagrant: a virtual machine as code¶
Vagrant from HashiCorp lets you describe a development environment in a single file — the Vagrantfile. It is a Ruby DSL, but you do not need to know Ruby. A few lines and you have a virtual machine with precisely defined software.
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.network "forwarded_port", guest: 8080, host: 8080
config.vm.network "forwarded_port", guest: 5432, host: 5432
config.vm.provision "shell", path: "provision.sh"
config.vm.provider "virtualbox" do |vb|
vb.memory = "2048"
vb.cpus = 2
end
end
The provisioning script installs JDK 7, Tomcat 7, PostgreSQL 9.3, and Maven 3.1 —
exactly the versions we need. No surprises, no deviations. A new developer joins,
clones the repo, runs vagrant up, and has a running environment within 10 minutes.
Multi-machine setup¶
For more complex projects, Vagrant allows you to define multiple machines in one Vagrantfile. Each machine has its own IP on a private network. This lets us simulate the production topology locally — application server + database server + message broker.
Shared folders link source code from the host system into the VM. The developer writes code in their preferred IDE on the host; compilation happens inside the VM.
Provisioning: Shell vs. Chef vs. Puppet¶
Vagrant supports several provisioners. We started with a shell script —
understandable for everyone. The important thing is that provisioning is
idempotent — you can run it multiple times without side effects. When you
add a new dependency, a vagrant provision is all it takes and everyone has it.
Problems¶
Performance: VirtualBox on older laptops runs slowly. Shared folders via Guest Additions are slow — NFS is better, but does not work easily on Windows. Box size: Over a gigabyte; downloading takes time. Docker vs. Vagrant: We hear about Docker and are wondering whether containers will replace VMs. For now they are complementary tools.
Vagrant saved us hundreds of hours¶
Since introducing Vagrant, onboarding is a matter of minutes, not days. Everyone works on an identical environment. If you have a team larger than two people, Vagrant is an investment that pays off on the first day.
Need help with implementation?
Our experts can help with design, implementation, and operations. From architecture to production.
Contact us