You are on page 1of 77

Composer Workflows for

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

composer require [namespace]/[package]:[version]


Packagist
Packagist

○ PHP Package Repository


○ This is the default composer repository
○ Best place to put packages you wish to share
Repositories
Repositories

composer config [options] [setting-key] [setting-value1] ... [setting-valueN]


Repositories

composer config repositories.hello-universe vcs https://github.com/kmoll/hello_universe


Drupal Packagist

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

○ Tilde: Only last specified number can change


~1.2.3
Equivalent to >=1.2.3 <1.3.0
~1.3
Equivalent to >=1.3.0 <2.0
Version Constraints
Next Significant Release Operators

○ Caret: Similar to Tilde but will always allow non-breaking versions


^1.2.3
Equivalent to >=1.2.3 <2.0.0
^1.2
Equivalent to >=1.2.0 <2.0.0
Version Constraints
Stability

○ 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

○ Install should be considered install/sync.


○ Will look at composer.lock file first
○ If version specified there, it will download that exact versions
○ Will ignore composer.json if entry exists in composer.lock
○ In the absence of composer.lock or an entry in composer.lock
will act as update
Install vs. Update
Update

○ Should be considered, get latest based on what I specify in composer.json.


○ Will look at composer.json file first
○ If version specified there, it will download latest version that matches what you define
○ Will update composer.lock with the downloaded version
○ If no composer.lock, it will be create.
Create - Project
Create - Project

○ This is the equivalent of git clone then composer install


Create - Project

composer create-project laravel/laravel your-project-name 4.2.*


Lets Recap

○ We know how to use composer to manage dependencies


○ We know how to create/list these dependencies
○ We know how to install them
○ We know where they are located
○ We know how to add our custom code
○ We know how to define our dependency versions
○ We know what commands to run and when
Composer and Drupal 8
Let’s install Drupal!!
Drupal Composer Project
https://github.com/drupal-composer/drupal-project
Composer installers
drupal-composer/drupal-project

"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

○ Plugin for Composer


○ Allows a package type to be mapped to an install path
○ https://github.com/composer/installers
Custom installers

○ Plugin for composer to define your own types and paths


○ https://github.com/davidbarratt/custom-installer
○ Can create type: kmoll-module
○ Then can map that to an install path
Drupal Scaffold
Drupal Scaffold

○ Plugin that will download scaffold files when using drupal/core


○ https://github.com/drupal-composer/drupal-scaffold
○ Will build out the rest of the Drupal and Webroot structure
drupal-composer/drupal-project

"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!

You might also like