Nikita Pohrebniak,
Software
Development
Manager
Acquia BLT for the Win, or
How to speed up the project setup,
development and deployment
SPEAKER
2
Software Development Manager
ImageX
nikitap@imagexmedia.com
Nikita Pohrebniak
ABOUT IMAGEX
● Founded in 2001, have successfully
launched 500+ web initiatives
● Offices in Vancouver, Kelowna & Kiev
● 70 full-time web specialists, including
dedicated design/UX, SEO/digital
marketing teams
● Global offices provide broad time-zone
coverage, 20+ hours/day
● One of the highest rated customer satisfaction
scores globally for web agencies (Clutch.co)
● Higher education division with specialized
project team
● Bjorn Thomson & Laura Ballay, 15 years at UBC
& 10 Years at CMU & SFU, respectively
● Clients include: Stanford University, University
of Arizona, UC Irvine, CSU - Stanislaus, Trinity
University, YMCA
3
1 |
2 |
3 |
4 |
5 |
6 |
Yet another tool?! The Problem.
Acquia BLT. The Solution.
What’s under the hood? The key features and how
to speed up the development process using BLT.
Raising the bar: ways to use Acquia BLT by the
Technical Architects/Lead Developers.
What if I need more? No problem! Extending and
overriding Acquia BLT.
Q&A.
AGENDA
444
Yet another tool?
The problem.1
● Projects with different requirements and level of complexity.
● Various hosting platforms.
● Distributed teams.
● Lack of standards.
6
Yet another tool? The problem.
The following standard scripts and tools were required
● Boilerplate project, with Docksal in mind;
● Check the coding standards;
● Run the tests;
● Build script for Bitbucket Pipelines;
● Standardize the deployment process;
● Make everyone happy!
7
Yet another tool? The problem.
Acquia BLT.
The Solution.2
9
What’s under the hood
Acquia Build and Launch Tool. The Solution.
For the Technical Architects:
● Add Drupal VM to the project;
● Generate the multisite;
● Generate empty config_splits;
● Generate the default CI configuration;
● Build Artifacts.
● Even more.
For the Developers:
● Install/Reinstall Drupal;
● Add git hooks;
● Pull DB and Files from remote;
● Build the frontend assets;
● Run tests;
● Make coffee (Finally).
BLT Features for the
Developers.3
11
Install/Reinstall Drupal
BLT Features for the Developers.
● blt source:build //Generates all required files for a full build
● blt drupal:install
public function build() {
$this->invokeCommands([
'tests:behat:init:config',
// source:build:composer must run prior to blt:init:settings to ensure
// that scaffold files are present.
'source:build:composer',
'blt:init:git-hooks',
'blt:init:settings',
'source:build:frontend',
]);
$this->invokeHook("post-setup-build");
}
12
Git Hooks
BLT Features for the Developers.
● blt:init:git-hooks
13
Pull DB and Files from Remote
BLT Features for the Developers.
● blt drupal:sync:default:site
● blt drupal:sync:default:db
● blt drupal:sync:files
● blt drupal:sync:private-files
drush:
aliases:
remote: projectname.prod
local: self
ci: self
default_alias: '${drush.aliases.local}'
14
Build/compile the frontend assets
BLT Features for the Developers.
● source:build:frontend-reqs
● source:build:frontend-assets
● source:build:frontend
command-hooks:
frontend-reqs:
dir: '${project.theme.dir}'
command: 'npm install && cd ${docroot}/modules/custom/program_finder && npm install && cd
${docroot}/modules/custom/event_finder && npm install'
frontend-assets:
dir: '${project.theme.dir}'
command: 'npm run build && cd ${docroot}/modules/custom/program_finder && npm run build && cd
${docroot}/modules/custom/event_finder && npm run build'
15
Run tests
BLT Features for the Developers.
● blt tests:all
● tests:phpunit
● blt tests:behat
● blt tests:frontend
● blt validate:composer
● blt validate:phpcs
● blt validate:twig
● blt validate:yaml
● blt tests:security-updates
BLT Features for the
Technical Architects &
Lead Developers.
4
17
Add Drupal VM to the Project
BLT Features for the Technical Architects & Lead Developers.
● blt recipes:drupalvm:init
18
Generate the multisite
BLT Features for the Technical Architects & Lead Developers.
● blt recipes:multisite:init
blt recipes:multisite:init
This will generate a new site in the docroot/sites directory.
Site machine name (e.g. 'example') subsite
Local domain name [http://local.subsite.com]
Would you like to configure the local database credentials? (y/n) n
Default remote drush alias [subsite.remote]
Default local drush alias [subsite.local]
> blt:init:settings
Hash salt already exists.
New site generated at /var/www/docroot/sites/subsite
Drush aliases generated:
* @subsite.remote
Config directory created for new site at config/subsite
19
Generate empty config_splits
BLT Features for the Technical Architects & Lead Developers.
● blt recipes:config:init:splits
git:(master) ✗ blt recipes:config:init:splits
This command will generate configuration and directories for the following environment
based splits: Local, CI, Dev, Stage, and Prod.
[FilesystemFilesystemStack] mkdir ["/var/www/docroot/../config/envs/local"]
[FileWrite] Writing to
/var/www/docroot/../config/default/config_split.config_split.local.yml.
[FilesystemFilesystemStack] mkdir ["/var/www/docroot/../config/envs/ci"]
[FileWrite] Writing to
/var/www/docroot/../config/default/config_split.config_split.ci.yml.
[FilesystemFilesystemStack] mkdir ["/var/www/docroot/../config/envs/dev"]
[FileWrite] Writing to
/var/www/docroot/../config/default/config_split.config_split.dev.yml.
[FilesystemFilesystemStack] mkdir ["/var/www/docroot/../config/envs/stage"]
[FileWrite] Writing to
/var/www/docroot/../config/default/config_split.config_split.stage.yml.
[FilesystemFilesystemStack] mkdir ["/var/www/docroot/../config/envs/prod"]
[FileWrite] Writing to
/var/www/docroot/../config/default/config_split.config_split.prod.yml.
20
Generate the default CI configuration
BLT Features for the Technical Architects & Lead Developers.
● blt recipes:ci:gitlab:init
● blt recipes:ci:pipelines:init
● blt recipes:ci:probo:init
● blt recipes:ci:travis:init
stages:
- validate
- build
- test
- deploy
variables:
APP_NAME: Project
before_script:
- echo "hello world"
validate:
stage: validate
script:
- blt validate:all
build:
stage: build
script:
- composer validate --no-check-all --ansi
- composer install --ansi
- blt source:build --ansi --verbose
test:
stage: test
script:
- blt tests --define tests.run-server=true --ansi --no-interaction
--verbose
production:
stage: deploy
script:
- echo "Launching application"
environment:
name: production
url: http://$APP_NAME.example.com
only:
- master
21
Build and Deploy Artifacts
BLT Features for the Technical Architects & Lead Developers.
● blt artifact:build
● blt artifact:deploy
In blt.yml
drush:
aliases:
remote: projectname.prod
local: self
ci: self
default_alias : '${drush.aliases.local}'
In bitbucket-pipelines.yml
${BIN_DIR}/blt -vvv artifact:deploy --commit-msg "Bitbucket build - $BITBUCKET_BUILD_NUMBER, Commit
$BITBUCKET_COMMIT" --branch "$BITBUCKET_BRANCH" --no-interaction
22
Build and Deploy Artifacts
BLT Features for the Technical Architects & Lead Developers.
if ($options['dry-run']) {
$this->logger->warning("This will be a dry run, the artifact will not be pushed.");
}
$this->checkDirty($options);
if (isset($options['ignore-platform-reqs'])) {
$this->ignorePlatformReqs = $options['ignore-platform-reqs'];
}
if (!$options['tag'] && !$options['branch']) {
$this->createTag = $this->confirm("Would you like to create a tag?", $this->createTag);
}
$this->commitMessage = $this->getCommitMessage($options);
if ($options['tag'] || $this->createTag) {
// Warn if they're creating a tag and we won't tag the source for them.
if (!$this->tagSource) {
$this->say("Config option deploy.tag_source if FALSE. The source repo will not be tagged.");
}
$this->deployToTag($options);
}
else {
$this->deployToBranch($options);
}
23
And even more cool features
BLT Features for the Technical Architects & Lead Developers.
● blt recipes:simplesamlphp:init
● blt recipes:acsf:init:all
● blt recipes:behat:init
● blt recipes:aliases:init:acquia
● blt source:fix:php-standards
Extending and overriding
Acquia BLT.5
25
Extending and overriding Acquia BLT.
● Built with “Robo” and “Annotated Command”.
● Supports defining new custom commands.
● Allows hooking into existing commands.
● Replace/override a Robo command using “Replace Command Hook”.
● Disable command.
26
Define new command
Extending and overriding Acquia BLT.
● blt recipes:blt:command:init
**
* Defines commands in the "custom" namespace.
*/
class ExampleCommands extends BltTasks {
/**
* Print "Hello world!" to the console.
*
* @command custom:hello
* @description This is an example command.
*/
public function hello() {
$this->say("Hello world!" );
}
}
27
Hook into the existing command
Extending and overriding Acquia BLT.
/**
* Defines commands in the "custom" namespace.
*/
class ExampleCommands extends BltTasks {
/**
* This will be called before the `custom:hello` command is executed.
*
* @hook command-event custom:hello
*/
public function preExampleHello (ConsoleCommandEvent $event) {
$command = $event->getCommand();
$this->say("preCommandMessage hook: The {$command->getName()} command is about to run!" );
}
}
28
Replace/override a BLT command
Extending and overriding Acquia BLT.
class CustomHelloReplaceCommandHook {
/**
* Parameters must match original command method.
*
* @hook replace-command custom:hello
*/
public function myHelloReplacement () {
$this->say("Goodbye world!");
}
}
29
Disable command
Extending and overriding Acquia BLT.
In blt.yml
disable-targets:
custom:
hello: true
Q&A.
6
QUESTIONS?
31
Software Development Manager
ImageX
nikitap@imagexmedia.com
Nikita Pohrebniak

Acquia BLT for the Win, or How to speed up the project setup, development and deployment

  • 1.
    Nikita Pohrebniak, Software Development Manager Acquia BLTfor the Win, or How to speed up the project setup, development and deployment
  • 2.
  • 3.
    ABOUT IMAGEX ● Foundedin 2001, have successfully launched 500+ web initiatives ● Offices in Vancouver, Kelowna & Kiev ● 70 full-time web specialists, including dedicated design/UX, SEO/digital marketing teams ● Global offices provide broad time-zone coverage, 20+ hours/day ● One of the highest rated customer satisfaction scores globally for web agencies (Clutch.co) ● Higher education division with specialized project team ● Bjorn Thomson & Laura Ballay, 15 years at UBC & 10 Years at CMU & SFU, respectively ● Clients include: Stanford University, University of Arizona, UC Irvine, CSU - Stanislaus, Trinity University, YMCA 3
  • 4.
    1 | 2 | 3| 4 | 5 | 6 | Yet another tool?! The Problem. Acquia BLT. The Solution. What’s under the hood? The key features and how to speed up the development process using BLT. Raising the bar: ways to use Acquia BLT by the Technical Architects/Lead Developers. What if I need more? No problem! Extending and overriding Acquia BLT. Q&A. AGENDA 444
  • 5.
  • 6.
    ● Projects withdifferent requirements and level of complexity. ● Various hosting platforms. ● Distributed teams. ● Lack of standards. 6 Yet another tool? The problem.
  • 7.
    The following standardscripts and tools were required ● Boilerplate project, with Docksal in mind; ● Check the coding standards; ● Run the tests; ● Build script for Bitbucket Pipelines; ● Standardize the deployment process; ● Make everyone happy! 7 Yet another tool? The problem.
  • 8.
  • 9.
    9 What’s under thehood Acquia Build and Launch Tool. The Solution. For the Technical Architects: ● Add Drupal VM to the project; ● Generate the multisite; ● Generate empty config_splits; ● Generate the default CI configuration; ● Build Artifacts. ● Even more. For the Developers: ● Install/Reinstall Drupal; ● Add git hooks; ● Pull DB and Files from remote; ● Build the frontend assets; ● Run tests; ● Make coffee (Finally).
  • 10.
    BLT Features forthe Developers.3
  • 11.
    11 Install/Reinstall Drupal BLT Featuresfor the Developers. ● blt source:build //Generates all required files for a full build ● blt drupal:install public function build() { $this->invokeCommands([ 'tests:behat:init:config', // source:build:composer must run prior to blt:init:settings to ensure // that scaffold files are present. 'source:build:composer', 'blt:init:git-hooks', 'blt:init:settings', 'source:build:frontend', ]); $this->invokeHook("post-setup-build"); }
  • 12.
    12 Git Hooks BLT Featuresfor the Developers. ● blt:init:git-hooks
  • 13.
    13 Pull DB andFiles from Remote BLT Features for the Developers. ● blt drupal:sync:default:site ● blt drupal:sync:default:db ● blt drupal:sync:files ● blt drupal:sync:private-files drush: aliases: remote: projectname.prod local: self ci: self default_alias: '${drush.aliases.local}'
  • 14.
    14 Build/compile the frontendassets BLT Features for the Developers. ● source:build:frontend-reqs ● source:build:frontend-assets ● source:build:frontend command-hooks: frontend-reqs: dir: '${project.theme.dir}' command: 'npm install && cd ${docroot}/modules/custom/program_finder && npm install && cd ${docroot}/modules/custom/event_finder && npm install' frontend-assets: dir: '${project.theme.dir}' command: 'npm run build && cd ${docroot}/modules/custom/program_finder && npm run build && cd ${docroot}/modules/custom/event_finder && npm run build'
  • 15.
    15 Run tests BLT Featuresfor the Developers. ● blt tests:all ● tests:phpunit ● blt tests:behat ● blt tests:frontend ● blt validate:composer ● blt validate:phpcs ● blt validate:twig ● blt validate:yaml ● blt tests:security-updates
  • 16.
    BLT Features forthe Technical Architects & Lead Developers. 4
  • 17.
    17 Add Drupal VMto the Project BLT Features for the Technical Architects & Lead Developers. ● blt recipes:drupalvm:init
  • 18.
    18 Generate the multisite BLTFeatures for the Technical Architects & Lead Developers. ● blt recipes:multisite:init blt recipes:multisite:init This will generate a new site in the docroot/sites directory. Site machine name (e.g. 'example') subsite Local domain name [http://local.subsite.com] Would you like to configure the local database credentials? (y/n) n Default remote drush alias [subsite.remote] Default local drush alias [subsite.local] > blt:init:settings Hash salt already exists. New site generated at /var/www/docroot/sites/subsite Drush aliases generated: * @subsite.remote Config directory created for new site at config/subsite
  • 19.
    19 Generate empty config_splits BLTFeatures for the Technical Architects & Lead Developers. ● blt recipes:config:init:splits git:(master) ✗ blt recipes:config:init:splits This command will generate configuration and directories for the following environment based splits: Local, CI, Dev, Stage, and Prod. [FilesystemFilesystemStack] mkdir ["/var/www/docroot/../config/envs/local"] [FileWrite] Writing to /var/www/docroot/../config/default/config_split.config_split.local.yml. [FilesystemFilesystemStack] mkdir ["/var/www/docroot/../config/envs/ci"] [FileWrite] Writing to /var/www/docroot/../config/default/config_split.config_split.ci.yml. [FilesystemFilesystemStack] mkdir ["/var/www/docroot/../config/envs/dev"] [FileWrite] Writing to /var/www/docroot/../config/default/config_split.config_split.dev.yml. [FilesystemFilesystemStack] mkdir ["/var/www/docroot/../config/envs/stage"] [FileWrite] Writing to /var/www/docroot/../config/default/config_split.config_split.stage.yml. [FilesystemFilesystemStack] mkdir ["/var/www/docroot/../config/envs/prod"] [FileWrite] Writing to /var/www/docroot/../config/default/config_split.config_split.prod.yml.
  • 20.
    20 Generate the defaultCI configuration BLT Features for the Technical Architects & Lead Developers. ● blt recipes:ci:gitlab:init ● blt recipes:ci:pipelines:init ● blt recipes:ci:probo:init ● blt recipes:ci:travis:init stages: - validate - build - test - deploy variables: APP_NAME: Project before_script: - echo "hello world" validate: stage: validate script: - blt validate:all build: stage: build script: - composer validate --no-check-all --ansi - composer install --ansi - blt source:build --ansi --verbose test: stage: test script: - blt tests --define tests.run-server=true --ansi --no-interaction --verbose production: stage: deploy script: - echo "Launching application" environment: name: production url: http://$APP_NAME.example.com only: - master
  • 21.
    21 Build and DeployArtifacts BLT Features for the Technical Architects & Lead Developers. ● blt artifact:build ● blt artifact:deploy In blt.yml drush: aliases: remote: projectname.prod local: self ci: self default_alias : '${drush.aliases.local}' In bitbucket-pipelines.yml ${BIN_DIR}/blt -vvv artifact:deploy --commit-msg "Bitbucket build - $BITBUCKET_BUILD_NUMBER, Commit $BITBUCKET_COMMIT" --branch "$BITBUCKET_BRANCH" --no-interaction
  • 22.
    22 Build and DeployArtifacts BLT Features for the Technical Architects & Lead Developers. if ($options['dry-run']) { $this->logger->warning("This will be a dry run, the artifact will not be pushed."); } $this->checkDirty($options); if (isset($options['ignore-platform-reqs'])) { $this->ignorePlatformReqs = $options['ignore-platform-reqs']; } if (!$options['tag'] && !$options['branch']) { $this->createTag = $this->confirm("Would you like to create a tag?", $this->createTag); } $this->commitMessage = $this->getCommitMessage($options); if ($options['tag'] || $this->createTag) { // Warn if they're creating a tag and we won't tag the source for them. if (!$this->tagSource) { $this->say("Config option deploy.tag_source if FALSE. The source repo will not be tagged."); } $this->deployToTag($options); } else { $this->deployToBranch($options); }
  • 23.
    23 And even morecool features BLT Features for the Technical Architects & Lead Developers. ● blt recipes:simplesamlphp:init ● blt recipes:acsf:init:all ● blt recipes:behat:init ● blt recipes:aliases:init:acquia ● blt source:fix:php-standards
  • 24.
  • 25.
    25 Extending and overridingAcquia BLT. ● Built with “Robo” and “Annotated Command”. ● Supports defining new custom commands. ● Allows hooking into existing commands. ● Replace/override a Robo command using “Replace Command Hook”. ● Disable command.
  • 26.
    26 Define new command Extendingand overriding Acquia BLT. ● blt recipes:blt:command:init ** * Defines commands in the "custom" namespace. */ class ExampleCommands extends BltTasks { /** * Print "Hello world!" to the console. * * @command custom:hello * @description This is an example command. */ public function hello() { $this->say("Hello world!" ); } }
  • 27.
    27 Hook into theexisting command Extending and overriding Acquia BLT. /** * Defines commands in the "custom" namespace. */ class ExampleCommands extends BltTasks { /** * This will be called before the `custom:hello` command is executed. * * @hook command-event custom:hello */ public function preExampleHello (ConsoleCommandEvent $event) { $command = $event->getCommand(); $this->say("preCommandMessage hook: The {$command->getName()} command is about to run!" ); } }
  • 28.
    28 Replace/override a BLTcommand Extending and overriding Acquia BLT. class CustomHelloReplaceCommandHook { /** * Parameters must match original command method. * * @hook replace-command custom:hello */ public function myHelloReplacement () { $this->say("Goodbye world!"); } }
  • 29.
    29 Disable command Extending andoverriding Acquia BLT. In blt.yml disable-targets: custom: hello: true
  • 30.
  • 31.