What is Vagrant?
Who uses Vagrant?
Why developers like Vagrant?
Here are some stack decisions, common use cases and reviews by companies and developers who chose Vagrant in their tech stack.
Often enough I have to explain my way of going about setting up a CI/CD pipeline with multiple deployment platforms. Since I am a bit tired of yapping the same every single time, I've decided to write it up and share with the world this way, and send people to read it instead ;). I will explain it on "live-example" of how the Rome got built, basing that current methodology exists only of readme.md and wishes of good luck (as it usually is ;)).
It always starts with an app, whatever it may be and reading the readmes available while Vagrant and VirtualBox is installing and updating. Following that is the first hurdle to go over - convert all the instruction/scripts into Ansible playbook(s), and only stopping when doing a clear
vagrant up or
vagrant reload we will have a fully working environment. As our Vagrant environment is now functional, it's time to break it! This is the moment to look for how things can be done better (too rigid/too lose versioning? Sloppy environment setup?) and replace them with the right way to do stuff, one that won't bite us in the backside. This is the point, and the best opportunity, to upcycle the existing way of doing dev environment to produce a proper, production-grade product.
I should probably digress here for a moment and explain why. I firmly believe that the way you deploy production is the same way you should deploy develop, shy of few debugging-friendly setting. This way you avoid the discrepancy between how production work vs how development works, which almost always causes major pains in the back of the neck, and with use of proper tools should mean no more work for the developers. That's why we start with Vagrant as developer boxes should be as easy as
vagrant up, but the meat of our product lies in Ansible which will do meat of the work and can be applied to almost anything: AWS, bare metal, docker, LXC, in open net, behind vpn - you name it.
We must also give proper consideration to monitoring and logging hoovering at this point. My generic answer here is to grab Elasticsearch, Kibana, and Logstash. While for different use cases there may be better solutions, this one is well battle-tested, performs reasonably and is very easy to scale both vertically (within some limits) and horizontally. Logstash rules are easy to write and are well supported in maintenance through Ansible, which as I've mentioned earlier, are at the very core of things, and creating triggers/reports and alerts based on Elastic and Kibana is generally a breeze, including some quite complex aggregations.
If we are happy with the state of the Ansible it's time to move on and put all those roles and playbooks to work. Namely, we need something to manage our CI/CD pipelines. For me, the choice is obvious: TeamCity. It's modern, robust and unlike most of the light-weight alternatives, it's transparent. What I mean by that is that it doesn't tell you how to do things, doesn't limit your ways to deploy, or test, or package for that matter. Instead, it provides a developer-friendly and rich playground for your pipelines. You can do most the same with Jenkins, but it has a quite dated look and feel to it, while also missing some key functionality that must be brought in via plugins (like quality REST API which comes built-in with TeamCity). It also comes with all the common-handy plugins like Slack or Apache Maven integration.
The exact flow between CI and CD varies too greatly from one application to another to describe, so I will outline a few rules that guide me in it: 1. Make build steps as small as possible. This way when something breaks, we know exactly where, without needing to dig and root around. 2. All security credentials besides development environment must be sources from individual Vault instances. Keys to those containers should exist only on the CI/CD box and accessible by a few people (the less the better). This is pretty self-explanatory, as anything besides dev may contain sensitive data and, at times, be public-facing. Because of that appropriate security must be present. TeamCity shines in this department with excellent secrets-management. 3. Every part of the build chain shall consume and produce artifacts. If it creates nothing, it likely shouldn't be its own build. This way if any issue shows up with any environment or version, all developer has to do it is grab appropriate artifacts to reproduce the issue locally. 4. Deployment builds should be directly tied to specific Git branches/tags. This enables much easier tracking of what caused an issue, including automated identifying and tagging the author (nothing like automated regression testing!).
Speaking of deployments, I generally try to keep it simple but also with a close eye on the wallet. Because of that, I am more than happy with AWS or another cloud provider, but also constantly peeking at the loads and do we get the value of what we are paying for. Often enough the pattern of use is not constantly erratic, but rather has a firm baseline which could be migrated away from the cloud and into bare metal boxes. That is another part where this approach strongly triumphs over the common Docker and CircleCI setup, where you are very much tied in to use cloud providers and getting out is expensive. Here to embrace bare-metal hosting all you need is a help of some container-based self-hosting software, my personal preference is with Proxmox and LXC. Following that all you must write are ansible scripts to manage hardware of Proxmox, similar way as you do for Amazon EC2 (ansible supports both greatly) and you are good to go. One does not exclude another, quite the opposite, as they can live in great synergy and cut your costs dramatically (the heavier your base load, the bigger the savings) while providing production-grade resiliency.
We use Vagrant because we do cross-platform development, and because many of those that use our code are on Windows machines. Vagrant doesn't take over the network stack like Docker does, nor does it force us to use Hyper-V. It also allows us to spin up windows machines if needed.
Ultimately our environment is one based on virtual machines, so Vagrant just made way more sense than Docker Compose for us, even though much of our automation code is run on Linux.
We use Vagrant because it is the best toolchain for having a standardized development environment that is readily provisoned with just a single command on macOS, Linux, and Windows.
There's a lot of things that could be better; the thing I dislike the most is how Vagrant configuration file is a Ruby script with weird semantics around conditionals, which makes it its own special language to learn. They would have been a lot better off with the configuration approach taken by Xen (where the configuration file was a straightforward Python system).
Also, it's error messages are optimized too much for people developing Vagrant itself, and not enough for helping end users who are using Vagrant, which means one has to google often to figure out what the actual problem is.
Still, I don't think there's a better alternative for a development environment that Just Works for hundreds of developers. Docker isn't really designed for the development environment use case in my view, since it's optimized for throwing away state and getting a clean one when you make changes, and that's sometimes really not what you want. And having to SSH into a remote development environment has significant latency and editor setup costs that in my view make it a backup plan, not the main way to do things.
We use DigitalOcean mainly to provide remote development environments for Zulip contributors in situations where developing locally using our Vagrant setup isn't practical. There's a range of reasons:
- Situations where one needs a public IP address and SSL certificate (e.g. Facebook's OAuth system require that even for testing)
- Giving a contributor a development environment when their computer doesn't have the few GB of free RAM needed to run one locally
- Developer sprints, where our snapshot-based system can provision a working development environment for a potential new contributor in under a minute. This use case is particularly great because a machine that one only needs for 3 days is essentially free with Digital Ocean's pricing.
- A backup development environment when someone's laptop is being repaired.
One could do all of this with many hosting providers, but we've found it particularly convenient to use Digital Ocean for these applications.
We use VirtualBox primarily as a Vagrant provider for macOS for the Zulip development environment. It's totally reasonable software for providing a convenient virtual machine setup on macOS (and for debugging when things go wrong, which is mostly how we use it since the Vagrant provider for macOS just works).
Our local development environment is powered by Vagrant, on which we run a Laravel Homestead box. Vagrant
- Up And SSH
- Synced Folders