Tools we use at work - part 2 - Docker

In the first article about the tools we use, we described our project management and communication tools. Today we will show you how we manage development environments.

Local copy

In Droptica each programmer works on a local copy of the website. Each task is completed and committed to a separate Git branch and pushed to a remote repository.

Our standard desktop system is Ubuntu therefore for a long time we got away with just installing Apache, Mysql and PHP locally. Most of the time this is enough to set up and successfully work on a project. As time goes by however, projects we work on get more and more complex and need additional software and services to work (eg. Apache Solr, Elasticsearch, Memcache, Redis, ffmpeg converted etc). PHP7 came out and with it the need to run some of the projects on PHP7 while some are still sitting on PHP5. All this made working on multiple projects at the same time more difficult.

Docker

Docker helped us solve this problem. In a nutshell docker enables you to run services and apps in isolated containers. For example you can simultaneously run Apache with PHP7 and with PHP5 in 2 containers the same project or have 2 different versions of Mysql. Each project has it's own environment encapsulated in containers and a developer can have multiple projects running locally without interference.

As great as Docker is however it is not too user friendly. If is operated from the commandline and requires you to type long, difficult to structure commands to set up more complicated environments. To help with that we use docker-compose which allows you to declare containers and their setup in a YML file.

That was already great but we still encountered drawbacks. It's great to set up Apache, Mysql and PHP in linked containers, but how do you then get to it and work with it? There is no drush, there may be other tools you might want to use like fabric, compass, gulp and the likes, which should not really be installed in your production images. To manage this we created Docker-Drupal- an application written in python which helps us with development. After installing it you have access to a docker-drupal command. This command uses our 'development' docker image which attaches itself to the environment and can execute commands for you. This image by default has drush installed and a few more elements. Depending on a project we often add additional elements. The docker-drupal app is easily extensible. You can add your own commands and actions. For example you could write a function which will import 2 databases, execute a migration script, enable a few modules and rebuild search API indexes.

Since introduction of docker-drupal, starting on a new project in Droptica usually requires cloning the repository and running "drocker-drupal up && drocker-drupal build" and after a few minutes a new fully working website is available for the developer in an environment identical to the one in production with all the services in the same versions. Docker-drupal was written by our team members Tomasz Wodzikowski and Damian Sikora. The demonstration in form of the video is available at youtube.

Summary

Docker and some of its plugins are one of our most basic tools. When dealing with Drupal development, we have no need to use other means of preparing the server envirmonment. In my opinion it is great and elastic solution. On an annual basis, it saves us many manhours.