As developers, we all want to maximize the use of the tools we've become familiar with. For me, this is BLT by Acquia. Since BLT fits with Acquia's workflows and Acquia Cloud, it's not designed to work with Pantheon, which has a different setup and development workflow.
This article will help you make tweaks so that BLT can work with Pantheon. The setup in this article is deliberately simple in order to explain the approach and concept. The real world setup is usually much more complex and depends on the needs of each project.
Also in this article, we will implement a simple CI/CD pipeline to conduct a seamless flow of continuous integration from the developer's code to the phase where code is delivered to the deployment server.
To be as thorough as possible, we will break the article into two parts:
- Part 1: We'll explain what parts make up the system and why they're important.
- Part 2: We'll show you how to implement the setup.
TL;DR: if you're already familiar with BLT and Pantheon, go to How to Set Up BLT and GitLab CI to Work with Pantheon Hosting (Part 2). Otherwise, read on.
Part 1: What and Why
The CI/CD Pipelines
A typical Drupal project includes a Drupal code base, version control software (Git), dependencies management tools (Composer, NPM, Bower), and development and production environments.
The pipelines connect all parts of the projects together and orchestrate them to do their jobs at the right moment, thus creating a flow of updates from developers to the deployment server.
In our setup, the workflow looks like this:
- Developers push code to GitLab.
- GitLab CI gets triggered and spins up a GitLab runner, which is a build instance. GitLab runners run each and every task as defined in the
.gitlab-ci.yml.
Tasks are:- Code sniffing
- Installing composer dependencies
- Run npm or gulp tasks to build front-end assets
- Run tests if needed
- Sanitize and build artifacts
- Push the artifact above to Pantheon.
Pipelines done right can increase product quality thanks to the layers of validation. It can also increase the speed of deployment, which means that new features and bug fixes will reach deployment faster.
Pantheon
Pantheon is one of the biggest names in Drupal hosting. Pantheon's main workflow includes the three main environments Dev-Test-Live and Multidev, which creates extra development environments that development teams can use to test feature branches before merging back to Dev.
Acquia BLT
In some big Drupal projects where many developers are involved, automation is required and managing configurations across many Dev-Stage-Preprod-Prod environments becomes complicated. Things can easily become chaotic due to the different ways each member of the team approaches problems.
Acquia BLT is a suite of tools that wraps around your Drupal project, which helps you manage team projects in a more standardized way. It also adds an automation layer on top of Drupal, making the implementation of continuous integration and deployment easier.
Some notable features of BLT:
- Local Git hooks: Sniffing coding standard on each commit, or even setting a standard pattern on git commits. This is very useful, for example, when we have the git commit pattern set to
00000 - description of commit
, which helps track down the commit and the task in PM tools such as Jira or Redmine. - Automation tasks: Tasks such as compiling front-end assets and composer install.
- Artifact generation: Creating production-only artifacts. Generating a safe artifact to deploy to another git repo involves a lot of steps. During the process of generating artifacts, BLT goes into directory
${project.root}/deploy
, checks out the main code base, installs dependencies, builds front-end assets, sanitizes the code base, and creates an artifact ready to deploy. This process is complex given the amount of tasks to run and the amount of files to include or exclude from the artifact. BLT is built on a set of best practices in Drupal development and does the heavy lifting in sanitizing and preparing the code. - CI/CD: Works with Acquia Cloud pipelines and Travis CI or GitLab CI.
An Example
In some projects, we had to integrate Drupal with Okta authentication using module simplesamlphp_auth. Okta configuration needed to be declared in vendor/simplesamlphp/simplesamlphp/config/config.php
, and this could be erased when running composer install. Then we needed to add the extra commands post-install-cmd
or post-update-cmd
to remember to patch the SimpleSAMLphp
package with our configuration.
It's manageable, but when a new developer comes onboard, you'll need to explain all these details again and again.
With BLT, it's simple to set up simplesamlphp_auth: add a SimpleSAMLphp
to blt/blt.yml
, then BLT will remember to include your config from ${project.root}/simplesamlphp/config
during the deployment.
This is a simple use case that we like from BLT. Even if you're experienced and can handle all DevOps and automation tasks by writing your script, it's still hard to synchronize your brain with your colleagues'. This setup allows you to automatically include your config during deployment so you don't have to go through all the steps again.
Implementation of the Setup
In How to Set Up BLT and GitLab CI to Work with Pantheon Hosting (Part 2), we'll go into the details of the setup and show you how to run a Drupal site wrapped by BLT on a Pantheon server.