Image of an arrow

Modernize your deployment practices with Vagrant

Avatar

admin_sflinux

Vagrant LogoA recurring problem in the world of web development is the complexity associated with setting up a suitable environment for each new project. If we’re lucky, we have up-to-date textual information to perform that setup. Even in that shiny world where we’re lucky, the time required to follow those textual instructions vary depending on the technical skills of the developer. Even when those instructions are up-to-date, it’s not rare at all to routinely spend many hours trying to set this new environment up.

Here at SFL, we recently started integrating Vagrant to our projects in order to modernize our deployment methods and results so far are very encouraging.

What is Vagrant?

Vagrant is a command line library allowing to quickly create and provision virtual environments through VirtualBox. It allows, with one vagrant up command, to create a VM from scratch and automatically configure it to host your project. For the configuration part, it’s integrated with Puppet, which is good for us because that’s already what we used here at SFL to manage our machines.

Benefits

Environment setup speed. What used to be a more or less relevant set of textual instructions is now executable Puppet code. This means that a new developer being brought to a project has one single command to type:

fab deploy

and within minutes, the site is ready to be used locally.

Setup reliability. Gone are the times of textual instructions that fall into obsolescence and make new developers want to tear all their hair off (well, the hair tearing part is not entirely gone, but at least it’s not over environment setup anymore). If the Puppet code becomes incorrect over time, it’s very easy to spot immediately and correct it.

Homogenous deployment environments. There used to be a time when we developers had to describe to our sysadmins the production environment that we needed for a new project, and then they would do their best to understand what we meant and build it. Now, with Puppet, developers and sysadmins speak the same language. The same code that is used to build a local environment can be reliably used by sysadmins to replicate that environment elsewhere.

How to use it?

How you use Vagrant depends on the type of project you use it with. For example, our Django projects use a mix of Vagrant and Fabric to perform setup and deployment. The Puppet side takes care of “OS specific” setup (installing packages, configuring Apache, creating databases) and Fabric takes care of “Python code specific” setup (pushing the code to the environment, pip dependencies, South migrations).

I’ve published, on Github, a sample Vagrant-enabled Django project that looks a lot like what we do internally so you can easily experience the potential of that solution. If you have Git, VirtualBox, Vagrant and Fabric installed on your machine, you can run this project (from nothing) with these commands:

git clone https://github.com/savoirfairelinux/django-vagrant-demo
cd django-vagrant-demo/deploy
fab deploy

Then, you can visit http://demo-django.local:8080 and see the newly-deployed site.

The deploy script will ask for your sudo password because Vagrant and the Fabric script need to modify your /etc/hosts file to make demo-django.local to 127.0.0.1.

Leave a comment

Your email address will not be published. Required fields are marked *


Similar articles

Image of an arrow

Android development is always moving forward with new features to make building apps easier; UI construction with compose, dependency injection with Hilt, game development extensions, emoji compatibility libraries, the list goes on. New projects have no concerns leveraging these sorts of features. However, legacy projects have to find a balance when migrating to new software […]

Savoir-faire Linux participated in the tenth edition of DrupalCamp Montréal, which was held this year at Concordia University. It was the occasion to catch up with a good proportion of the Drupal developer community in Montreal, to exchange ideas with other companies that work with this technology, and to have an overview of how Drupal […]

When It Comes to Websites, Page Speed Matters! This article is motivated by our website project accomplished by our Integration Platforms and AI Department using Liferay 7 (the latest version of Liferay Portal) for one of our clients– a large Canadian corporation in telecommunications and media industry. Alexis, our front-end developer, shares with you his first-hand experience […]

Thumbnail image

Web Development Getting Started with Server-Side Rendering in Angular By Kévin Barralon This week we released a tutorial for developers using the Angular JavaScript framework to set them up with a pre-configured server-side rendering environment. This environment allows for the pre-rendering of an Angular site so that its contents can be made visible to robots […]

Thumbnail image

Server-Side Rendering Management: An Angular’s Novelty Imposing a Challenge Angular is a framework using the TypeScript Programming Language. Its 5th version (pentagonal-donut) was released in November 2017, containing new features and bugfixes. It is accompanied by the command line tool Angular CLI and new features such as a server-side rendering framework that has become very popular within the community of Angular […]