Drupal 8 contributed modules using Docker
Auteur(s) de l'article
For a fair amount of time I'm contributing to Drupal in the form of Contributed Modules, patches to Core and Documentation.
To be franc - I don't want to read the story. Bring me to the Docker usage
During my journey as a contributor I have been stuck trying to solve some simple problems:
- How to contribute to many modules without having to Bootstrap a Drupal project for each of them ?
- How to tests those modules in a different version of Drupal to ensure compatibility and stability ?
- How could I accelerate my development by isolating my modules from each other ?
- When one of my contributed modules required 3rd-party integration (Solr, Elasticsearch, Redis), How can I isolate the installation of it ?
This article outlines my experience learning to contribute to Drupal and why I created Drupal Docker Container for Contributions. A Docker image for Drupal contributors giving a solution to quickly setup a Docker for both contributed modules or contributed themes.
The Bad Fish Paradigm
My journey started 4 years ago. During my first year of contribution I had a single "Drupal Sandbox" project and decided to symlinked all contributed modules I developed for in the
modules/contrib
directory.Some would say I put all my eggs in one basket ... But guess what ? Yes I did, and it worked ....
Well it worked, until I developed 20+ contributed modules symlinked on the same "Drupal Sandbox".
Imagine dealing with each modules being in a pretty unstable release (
Imagine dealing with each modules being in a pretty unstable release (
dev
branch FTW 🎉), sometimes requiring different version of the same dependency or just not being compatibly with the same Drupal version.I got stuck and everything explode spectacularly 💣 💥.
The Spaghetti Catalyst
Well obviously having one single "Drupal Sandbox" project was not a pretty good idea.
So I decided to split my "Drupal Sandbox" into multiple "Drupal Sandboxes" each by Drupal version I wanted to support ("Drupal Sandbox 8.6", "Drupal Sandbox 8.8", ...).
This solution solved my incompatible dependencies problem and my cascade of unstable modules as I isolated every module into its own Sandbox when it was necessary.
This solution solved my incompatible dependencies problem and my cascade of unstable modules as I isolated every module into its own Sandbox when it was necessary.
At this time, I was an active maintainer of Travis CI, a Travis solution to test Drupal modules with PHPUnit. I added it on each of my projects and used the used it for automated testing on CI - allowing me to tests multiple versions of Drupal on CI.
Once again, it worked .... I had to deal with many "Drupal Sandboxes" (growing each days), but it works.
Well it worked, until I had to deal with bigger contributed modules requiring different PHP versions and requiring 3rd-party such as Redis, Solr Elasticsearch (obviously each of them in many disparate versions for backward compatibilities :party:).
Once more, imagine me trying to make sense of all those Spaghetti "Drupal Sandboxes", having different symlinked projects, connected to 3rd-party software (each one in a different random port 😵) ...
Once more, imagine me trying to make sense of all those Spaghetti "Drupal Sandboxes", having different symlinked projects, connected to 3rd-party software (each one in a different random port 😵) ...
I got overwhelmed by all those "Drupal Sandboxes" and Services 🙀 .
The Space Whale Resurgence
Well ... Obviously working locally was driving me crazy. I had to figure out how to works with those modules in a complete new way.
I decided to get the problem upside down.
I decided to get the problem upside down.
Docker seems promising, it solves the isolations problems, the server architecture versions and it will accelerate my development by containerising all the necessary services ... Bonus point, it will make my modules way more easy to contribute to 💪 .
So I dive into this exciting new idea.
I started looking for Drupal Docker images and found a bunch of them Docker Hub.
Unfortunately, my dreams fade quickly 😿 ... all of those images serve the same purpose, integrate Docker into a complete Drupal project, none of them was made for standalone modules/themes contributions.
Unfortunately, my dreams fade quickly 😿 ... all of those images serve the same purpose, integrate Docker into a complete Drupal project, none of them was made for standalone modules/themes contributions.
Well ... nothing seems to exist as I need it ... Then I decided to create my own, extending the official Drupal images for standardization and stability .
How to use this image
Create a
Dockerfile
file at the root level of your contributed modules/themesYou may want to update the default
BASE_IMAGE_TAG
to be used following your module current supporting version.- Then create a
docker-compose.yml
file in the same location and update the mounted volume name to match your custom module name
Spin up the Docker integration
(Optionally) You may want to setup a different Drupal Docker versions for testing, then use the build argument
BASE_IMAGE_TAG
Travis Integration example
Now having a Docker working environment, let's use it to run our tests inside our containers.
Create a
.travis.yml
file at the root level of your repositoryFeedback
At any point during the contributing process I would love to help! For help with a specific problem you can open an issue on GitHub.
Usage examples
- Template Whisperer
Functional (Browser) and Kernel tests - CKEditor Non-breaking space Plugin
Functional (Javascript) and Kernel tests - Commerce Google Tag Manager Enhanced Ecommerce
Functional (Browser), Unit and Kernel tests - Backerymails
Functional (Browser) and Kernel tests - Bamboo Twig
Functional (Browser) and Kernel tests - Loco Translate
Functional (Browser), Unit and Kernel tests - Potion
Unit and Kernel tests - Commerce TrustedShops
Functional (Browser), Unit and Kernel tests - Vercel deploy
Functional (Browser) tests
Sources
For the most curious of you, here are some sources of additional information that inspired the creation of this article.
Github (21 August, 2020). Drupal Docker Container for Contributions
Seen on https://github.com/wengerk/docker-drupal-for-contrib
Seen on https://github.com/wengerk/docker-drupal-for-contrib
Tess Flynn (07 August, 2020). Drupal Development with Docker
Seen on https://drupalize.me/series/drupal-development-docker
Seen on https://drupalize.me/series/drupal-development-docker
Drupal Documentation (21 August, 2020). Docker based development environment
Seen on https://www.drupal.org/node/2736447
Seen on https://www.drupal.org/node/2736447
Pierre Abreu (14 April, 2019). Improve Drupal 8 performance on Docker and OSX
Seen on https://medium.com/faun/improve-drupal-8-perf...
Seen on https://medium.com/faun/improve-drupal-8-perf...
Gerardo Fernández (19 December, 2019). How to integrate Docker into a Symfony-based project
Seen on https://medium.com/@ger86/how-to-integrate-...
Seen on https://medium.com/@ger86/how-to-integrate-...