Building Enterprise Drupal Sites with Acquia Build and Launch Tool (BLT)

Tags:

July 13, 2022 | Matthew Ramir
header image

Building the best Drupal websites starts with the best Drupal tooling. Nearly all modern Drupal websites are built using a “local environment” which gives developers a place to create exciting new features without affecting the production environment.

Getting a local environment configured and using it to perform daily tasks often requires a plethora of custom scripts and tools built by a DevOps guru. Tools like Drush and Lando make this process exponentially easier, but there is often still a need for custom scripts to simplify the lives of developers. The less time a developer spends on maintaining a local, the more time they can spend developing world-class web experiences.

As the Drupal practice at Bounteous has grown, so has our tooling. What was once a hodgepodge of custom, client-specific bash scripts, have evolved into reusable, pluggable tooling that can transfer from project to project - all built on Acquia’s Build and Launch Tool (BLT). 

BLT is a Drupal-specific extensible toolset designed to help you build, test, and deploy your code. It provides a vast array of commands to get you up and running quickly, including commands to configure your local, sync databases, or even run post-deployment tasks like config import. The majority of the BLT can be configured via a single YAML file, allowing you to hit the ground running on any sized Drupal project.

Compatibility with Drupal Sites

BLT can be installed via composer (a tool used to manage 3rd party PHP libraries) and it operates in a similar fashion to Drush. When installed, you are provided a new CLI tool at vendor/bin/blt which is used to trigger BLT commands. This CLI tool requires that your system be able to run PHP scripts, which is also needed for Composer and Drush commands. BLT frequently invokes Drush commands to complete its tasks. 

BLT comes configured “for Acquia” out of the box, but it doesn’t require an Acquia subscription to be used. At Bounteous, we use BLT for various clients and side projects, including Drupal sites hosted on custom infrastructure or by other Drupal providers like Pantheon. BLT’s flexibility and pluggability make it the perfect tool for any Drupal site hosted on any platform.

However, where BLT really shines is when it is used in conjunction with Acquia hosting. BLT’s default settings.php file comes baked with Drupal hosting best practices - including memcache and config split settings. It will also recognize when the tool is being used on Acquia hosting and automatically include the appropriate settings needed to connect to the platform. This means configuring your Drupal site for Acquia is as simple as configuring BLT!

Acquia BLT Plugins

BLT is built on Robo, a customizable and extensible PHP task runner. New commands can be easily installed via 3rd party packages, or through your own project’s configuration - blt recipes:blt:command:init will configure this for you. We have implemented custom BLT commands for everything from Acquia Cloud Site Factory (ACSF) management to Acquia Cloud IDE configuration.

Acquia and the larger Drupal community maintain a plethora of plugins that extend and enhance the BLT toolset. There are numerous integrations with local environment tools such as Lando, DDEV, and DrupalVM. Acquia also provides a number of plugins that offer better integrations with Acquia products. For example, there is a plugin for ACSF which provides commands to initialize and validate required settings files. 

Acquia keeps a list of plugins in their knowledge base which you can find here.

Installation & Configuration of Acquia Build and Launch Tool

Installing BLT is as simple and easy as installing Drupal’s contrib modules. We won’t cover the initial set-up of a new Drupal codebase (drupal.org has helpful guides on this), but assuming you have an existing codebase, BLT can be easily installed via composer.

composer require acquia/blt

During the initial installation of BLT, a YAML configuration file will be generated in your project root at blt/blt.yml. This file contains important metadata about the project and options that drive much of the behavior of the tool. The following is a snippet from the BLT configuration that drives the bounteous.com website. These settings are used in many places throughout the tool, and give us some basic information about the name of the project.

project:
 machine_name: bounteous
 human_name: 'Bounteous.com'
 # Used for enforcing correct git commit msg syntax.
 prefix: BCE

BLT Local Environment Setup

To work on a Drupal website, most developers use a “local environment” such as Lando or DrupalVm. Most of the common local environments in use by the Drupal community have a corresponding BLT plugin that can be leveraged to quickly configure and boot your local. These plugins are optional but are often handy when working on the initial configuration of a process. In the case of Lando, Mike Madison maintains a composer package that will perform the configuration (including adding a lando blt command) for us.

composer require --dev mikemadison13/blt-lando -W
blt recipes:vm:lando

Once your local environment is configured and booted, you can begin the setup of your Drupal site. There are a few different strategies we can take to set up Drupal with BLT. For existing sites, we typically sync the database from our staging environment to our local environment. BLT also supports installing a fresh site from existing config or from an install profile. The following is the local environment configuration for bounteous.com which we use to sync the database from our dev environment (the @bounteous.dev drush alias) to a local Lando environment.

# This will be used as the local domain for all developers.
 local:
   hostname: '${project.machine_name}.lndo.site'

# Sync db strategy
# drush sql-sync @bounteous.dev @self
# Valid values are install, sync, import.
setup:
  strategy: sync
drush:
# Set our source db.
  aliases:
    remote: 'bounteous.dev'
# optionally disable sanitizing data.
  sanitize: false

This configuration is used during the blt setup and blt sync commands.

BLT Frontend Compilation

No Drupal setup is complete without a frontend build process! BLT offers command hooks that allow you to execute custom commands at various points in the setup process. In the case of frontend hooks, they offer a way to execute our npm commands inside of our theme directly. Bounteous.com uses npm to compile the theme, but we can also use any other CLI tool here such as gulp. We can also specify the directory to run these commands in so that we don’t need to worry about execution context.

command-hooks:
 frontend-reqs:
   dir: ${docroot}/themes/custom/bounteous
   command: 'npm ci'
 frontend-assets:
   dir: ${docroot}/themes/custom/bounteous
   command: 'npm run build'

This configuration is triggered during the blt frontend command.

Drupal Setup

Once you have your local environment running and your blt.yml configuration set, it’s time to run the setup process! This will make any final tweaks to the codebase needed to bootstrap and install Drupal including:

  • Running composer install.
  • Creating a local settings.php file that points drupal to the appropriate database.
  • Running frontend tasks via blt frontend.
  • Running a database sync or running a site:install command.

This process can be triggered via the setup command:

blt setup

Once setup has been successfully run, a developer will have a functioning local Drupal site! 

Quick & Painless

Acquia BLT offers a quick, painless way to run and maintain a Drupal environment.
What was once the wild west of Drupal DevOps scripts has settled and matured into Acquia’s Build and Launch Tool. BLT offers many commands out of the box that allow us to get up and running quickly on a project. Its configuration and installation are dead simple, its internals are well thought out and easily customizable. BLT has been an integral part of many Bounteous Drupal builds. 

For more information on BLT, check out the following: