Composer Workflows for Drupal 8 Composer Workflows for

  • Slides: 77
Download presentation
Composer Workflows for Drupal 8

Composer Workflows for Drupal 8

Composer Workflows for Drupal 8 Kevin Moll Appnovation Technologies Sr. Developer kmoll @kevinjmoll

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

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

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

Dependency Management in Drupal

History ○ Manually install dependencies ○ Drush commands ○ Drush Make

History ○ Manually install dependencies ○ Drush commands ○ Drush Make

Composer

Composer

Installation https: //getcomposer. org/doc/00 -intro. md

Installation https: //getcomposer. org/doc/00 -intro. md

What is Composer?

What is Composer?

“Composer is a tool for dependency management in PHP. It allows you to declare

“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

Packages

What is a Package?

What is a Package?

Packages ○ namespace ○ name ○ composer. json file

Packages ○ namespace ○ name ○ composer. json file

{ "name": "symfony/yaml", "type": "library", "description": "Symfony Yaml Component", "keywords": [], "homepage": "https: //symfony.

{ "name": "symfony/yaml", "type": "library", "description": "Symfony Yaml Component", "keywords": [], "homepage": "https: //symfony. com", "license": "MIT", "authors": [ { "name": "Fabien Potencier", "email": "fabien@symfony. com" }, { "name": "Symfony Community", "homepage": "https: //symfony. com/contributors" } ], "require": { "php": ">=5. 3. 9" }, "autoload": { "psr-4": { "Symfony\Component\Yaml\": "" }, "exclude-from-classmap": [ "/Tests/" ] }, "minimum-stability": "dev", "extra": { "branch-alias": { "dev-master": "2. 8 -dev" } }

Defining Dependencies

Defining Dependencies

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

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

Packagist

Packagist

Packagist ○ PHP Package Repository ○ This is the default composer repository ○ Best

Packagist ○ PHP Package Repository ○ This is the default composer repository ○ Best place to put packages you wish to share

Repositories

Repositories

Repositories composer config [options] [setting-key] [setting-value 1]. . . [setting-value. N]

Repositories composer config [options] [setting-key] [setting-value 1]. . . [setting-value. N]

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

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

Drupal Packagist https: //packagist. drupal-composer. org

Drupal Packagist https: //packagist. drupal-composer. org

Drupal. org packages endpoint https: //packages. drupal. org/8

Drupal. org packages endpoint https: //packages. drupal. org/8

Toran Proxy https: //toranproxy. com/

Toran Proxy https: //toranproxy. com/

Toran Proxy ○ Packagist proxy ○ Install on your own servers ○ Add packages

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

Packagist Github Toran Drupal Packagist

Semantic Versioning

Semantic Versioning

major. minor. patch

major. minor. patch

Semver ○ Allows versions to give developers more information ○ Major version: Backwards capability

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

Defining versions in Composer

Version Constraints Exact ○ Example: 1. 0. 2

Version Constraints Exact ○ Example: 1. 0. 2

Version Constraints Range ○ >=1. 0 ○ >= 1. 0 < 2. 0 ○

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

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

Version Constraints Wildcard ○ * Any and all versions

Do not do this! Do not do do this! Do not this!

Do not do this! Do not do do this! Do not this!

Version Constraints Next Significant Release Operators ○ Tilde: Only last specified number can change

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

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

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.

"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 vs. Update Install ○ Install should be considered install/sync. ○ Will look at

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 ○ Should be considered, get latest based on what I specify

Install vs. 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

Create - Project ○ This is the equivalent of git clone then composer install

Create - Project ○ This is the equivalent of git clone then composer install

Create - Project composer create-project laravel/laravel your-project-name 4. 2. *

Create - Project composer create-project laravel/laravel your-project-name 4. 2. *

Lets Recap ○ We know how to use composer to manage dependencies ○ We

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

Composer and Drupal 8

Let’s install Drupal!!

Let’s install Drupal!!

Drupal Composer Project https: //github. com/drupal-composer/drupal-project

Drupal Composer Project https: //github. com/drupal-composer/drupal-project

Composer installers

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"],

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

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 ○

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

Drupal Scaffold ○ Plugin that will download scaffold files when using drupal/core ○ https:

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": "Drupal. Composer\Drupal. Scaffold\Plugin: : scaffold", "post-install-cmd": [ "Drupal. Project\composer\Script. Handler:

drupal-composer/drupal-project "scripts": { "drupal-scaffold": "Drupal. Composer\Drupal. Scaffold\Plugin: : scaffold", "post-install-cmd": [ "Drupal. Project\composer\Script. Handler: : build. Scaffold", "Drupal. Project\composer\Script. Handler: : create. Required. Files" ], "post-update-cmd": [ "Drupal. Project\composer\Script. Handler: : build. Scaffold", "Drupal. Project\composer\Script. Handler: : create. Required. Files" ] },

A Quick Example

A Quick Example

The Big Picture

The Big Picture

Creating a site from scratch

Creating a site from scratch

Initialise ○ Create the “placeholder" repository with some hooks and composer. json ○ Install

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 Minimum-stability interactive We want any 1. 0 allowed version below

Do not ask any Minimum-stability interactive We want any 1. 0 allowed version below 2. 0 question composer create-project --no-interaction --stability dev org/repo: ~1 Let’s create a new project! /path/to/project --repository-url="https: //user: pass@toranprivateurl. com/repo/private/"

Go Acquia ○ We clone our Acquia repository ○ Generate the settings. php file

Go Acquia ○ We clone our Acquia repository ○ Generate the settings. php file ○ Generate some extra files

Sync!

Sync!

drush site-install

drush site-install

That’s nice, I want my D 8 config

That’s nice, I want my D 8 config

Propagate!

Propagate!

Recap

Recap

Deploying Changes

Deploying Changes

Behind the scenes ○ We cloned both Github and Acquia ○ Installed Prestissimo ○

Behind the scenes ○ We cloned both Github and Acquia ○ Installed Prestissimo ○ Ran Composer Install ○ Sync’d ○ Imported D 8 Config ○ Drush cache-rebuild

Q&A

Q&A

JOIN US FOR CONTRIBUTION SPRINTS First Time Sprinter Workshop - 9: 00 -12: 00

JOIN US FOR CONTRIBUTION SPRINTS First Time Sprinter Workshop - 9: 00 -12: 00 - Room Wicklow 2 A Mentored Core Sprint - 9: 00 -18: 00 - Wicklow Hall 2 B General Sprints - 9: 00 - 18: 00 - Wicklow Hall 2 A

WHAT DID YOU THINK? Evaluate This Session events. drupal. org/dublin 2016/schedule THANK YOU!

WHAT DID YOU THINK? Evaluate This Session events. drupal. org/dublin 2016/schedule THANK YOU!