Professional Documents
Culture Documents
Drupal 8
Composer Workflows for Drupal 8
Kevin Moll
Appnovation Technologies
Sr. Developer
kmoll
@kevinjmoll
Composer Workflows for Drupal 8
Pablo Fabregat
Appnovation Technologies
Automation Engineer
pmatias
@darth_pablitt
What we’ll cover today
○ What is Composer
○ Composer commands
○ What are packages
○ Where are packages
○ What do we do with private packages
○ Plugins and useful enhancements for Composer
○ How we work this into our automated build
process
Dependency Management in
Drupal
History
○ Manually install dependencies
○ Drush commands
○ Drush Make
Composer
Installation
https://getcomposer.org/doc/00-intro.md
What is Composer?
“Composer is a tool for dependency management in PHP. It
allows you to declare the libraries your project depends on and
it will manage (install/update) them for you” - Composer
Documentation
https://getcomposer.org/doc/00-intro.md
Packages
What is a Package?
Packages
○ namespace
○ name
○ composer.json file
{
"name": "symfony/yaml",
"require": {
"type": "library",
"php": ">=5.3.9"
"description": "Symfony Yaml Component",
},
"keywords": [],
"autoload": {
"homepage": "https://symfony.com",
"psr-4": { "Symfony\\Component\\Yaml\\": "" },
"license": "MIT",
"exclude-from-classmap": [
"authors": [
"/Tests/"
{
]
"name": "Fabien Potencier",
},
"email": "fabien@symfony.com"
"minimum-stability": "dev",
},
"extra": {
{
"branch-alias": {
"name": "Symfony Community",
"dev-master": "2.8-dev"
"homepage": "https://symfony.com/contributors"
}
}
}
],
Defining Dependencies
Repositories
https://packagist.drupal-composer.org
Drupal.org packages endpoint
https://packages.drupal.org/8
Toran Proxy
https://toranproxy.com/
Toran Proxy
○ Packagist proxy
○ Install on your own servers
○ Add packages not available to public
○ Acts as a redundant backup
Packagist
Github
Toran
Drupal Packagist
Semantic Versioning
major.minor.patch
Semver
○ Allows versions to give developers more information
○ Major version: Backwards capability breaking
○ Minor version: Feature Updates (non-BC breaking)
○ Patch version: Bug fixes
Defining versions in Composer
Version Constraints
Exact
○ Example: 1.0.2
Version Constraints
Range
○ >=1.0
○ >= 1.0 < 2.0
○ 1.0 - 2.0 (This is inclusive)
○ Equivalent to >=1.0.0 <=2.0.0
Version Constraints
Wildcard
○ 1.2.*
Equivalent to >=1.2.0 <1.3
○ 1.*
Equivalent to >=1.0.0 <2.0
Version Constraints
Wildcard
○ *
Any and all versions
Do not do this!
Do not do this!
Do not do this!
Version Constraints
Next Significant Release Operators
○ Defaults to dev
○ Can specify --stable
○ Can specify --dev
○ Default can be listed in composer.json or on command line with
‘minimum-stability’
○ Can be overridden by each package when specifying the version
"require": {
"php": ">=5.5.9",
"symfony/class-loader": "~2.8",
"symfony/console": "~2.8",
"symfony/dependency-injection": "~2.8",
"symfony/event-dispatcher": "~2.8",
"symfony/http-foundation": "~2.8",
"symfony/http-kernel": "~2.8",
"symfony/routing": "~2.8",
"symfony/serializer": "~2.8",
"symfony/translation": "~2.8",
"symfony/validator": "~2.8",
"symfony/process": "~2.8",
"symfony/polyfill-iconv": "~1.0",
"symfony/yaml": "~2.8",
"twig/twig": "^1.23.1",
"doctrine/common": "2.5.*",
"doctrine/annotations": "1.2.*",
"guzzlehttp/guzzle": "^6.2.1",
[…]
}
Install vs. Update
Install vs. Update
Install
"extra": {
"installer-paths": {
"web/core": ["type:drupal-core"],
"web/modules/contrib/{$name}": ["type:drupal-module"],
"web/profiles/contrib/{$name}": ["type:drupal-profile"],
"web/themes/contrib/{$name}": ["type:drupal-theme"],
"drush/contrib/{$name}": ["type:drupal-drush"]
},
"patches": {},
"branch-alias": {}
}
Composer installers
"scripts": {
"drupal-scaffold": "DrupalComposer\\DrupalScaffold\\Plugin::scaffold",
"post-install-cmd": [
"DrupalProject\\composer\\ScriptHandler::buildScaffold",
"DrupalProject\\composer\\ScriptHandler::createRequiredFiles"
],
"post-update-cmd": [
"DrupalProject\\composer\\ScriptHandler::buildScaffold",
"DrupalProject\\composer\\ScriptHandler::createRequiredFiles"
]
},
A Quick Example
The Big Picture
Creating a site from scratch
Initialise
○ Create the “ placeholder" repository with some hooks and composer.json
○ Install composer
○ hirak/Prestissimo FTW
○ Run composer
○ Do some cleanup
○ Push to Github
Do not ask any
Let’s create a new Minimum-stability
interactive We want any 1.0
project! allowed
version below 2.0
question
composer create-project --no-interaction --stability dev org/repo:~1
/path/to/project
--repository-url="https://user:pass@toranprivateurl.com/repo/private/"
Go Acquia
○ We clone our Acquia repository
○ Generate the settings.php file
○ Generate some extra files
Sync!
drush site-install
That’s nice, I want my D8 config
Propagate!
Recap
Deploying Changes
Behind the scenes
○ We cloned both Github and Acquia
○ Installed Prestissimo
○ Ran Composer Install
○ Sync’d
○ Imported D8 Config
○ Drush cache-rebuild
Q&A
JOIN US FOR
CONTRIBUTION SPRINTS
First Time Sprinter Workshop - 9:00-12:00 - Room Wicklow2A
Mentored Core Sprint - 9:00-18:00 - Wicklow Hall 2B
General Sprints - 9:00 - 18:00 - Wicklow Hall 2A
WHAT DID YOU THINK?
Evaluate This Session
events.drupal.org/dublin2016/schedule
THANK YOU!