SlideShare una empresa de Scribd logo
1 de 32
Descargar para leer sin conexión
Drush in the Composer Era
1Photo © 2012 by Charlie Nguyen, CC BY 2.0
2
Overview
Using Composer Dependency Hell Site-Local Drush
Configuration Filter The FutureDrush Extensions
It is now possible to use Composer to
add code directly to Drupal:
drush dl drupal-8
cd drupal-8
composer require drupal/og:8.*
composer update will not update
drupal/core; use drush pm-update
drupal for this.
3
Standard Composer used in D8
web
├── autoload.php
├── composer.json
├── core
│ └─ composer.json
├── index.php
└── vendor
└─ autoload.php
4
wikimedia/composer-merge-plugin
{
"name": "drupal/drupal",
"require": {
"composer/installers": "^1.0.21",
"wikimedia/composer-merge-plugin": "^1.3.0"
},
"extra": {
"_readme": [
"By default Drupal loads the autoloader from ./vendor/autoload.php.",
"To change the autoloader you can edit ./autoload.php."
],
"merge-plugin": {
"include": [
"core/composer.json"
],
"recurse": false,
"replace": false,
"merge-extra": false
}
},
}
Uses “split core” to manage Drupal
core files:
composer create-project drupal-
composer/drupal-project:8.x-dev
my-site-name --stability dev --
no-interaction
5
Drupal 8: “drupal-project”
project
├── composer.json
├── vendor
│ └── autoload.php
└── web
├── autoload.php
├── core
│ └── composer.json
└── index.php
6
drupal-project Layout
{
"name": "drupal-composer/drupal-project",
"repositories": [
{
"type": "composer",
"url": "https://packagist.drupal-composer.org"
}
],
"require": {
"composer/installers": "^1.0.20",
"drupal/core": "8.0.*",
"drush/drush": "dev-master",
"drupal/console": "dev-master"
},
"extra": {
"installer-paths": {
"web/core": ["type:drupal-core"],
"web/modules/contrib/{$name}": ["type:drupal-module"],
"drush/contrib/{$name}": ["type:drupal-drush"]
}
}
}
7
Drupal 7: Example CI Scripts
example-drupal7-circle-composer
example-drupal7-travis-composer
CI
+
+
Use craychee/rootcanal to post-
process your Composer install:
"config": {
"bin-dir": "bin"
},
"scripts": {
"post-install-cmd": [
"bin/rootcanal"
],
"post-update-cmd": [
"bin/rootcanal"
]
}
}
http://craychee.io/blog/2015/08/01/no-excuses-part3-composer/ 8
Drupal 7: rootcanal
Dependency Hell
9
The Multiple Autoloaders Problem
10
Two autoloaders may directly or indirectly include the same dependent library.
Drupal 8
require autoload.php
Badly-Behaved Drush Extension
require autoload.php
"name": "symfony/event-dispatcher",
"version": "v2.7.5",
"name": "symfony/event-dispatcher",
"version": "3.*",
Version Mismatch Breaks
11
Event
isPropagationStopped
stopPropagation
symfony/event-dispatcher v2.7.5 symfony/event-dispatcher v3.x
public function dispatch($event_name, Event $event) {
$event->setDispatcher($this);
Event
isPropagationStopped
stopPropagation
setDispatcher
getDispatcher
getName
setName
DrupalComponentEventDispatcherContainerAwareEventDispatcher.dispatch
Site-Local Drush
12
Solution to Dependency Hell
Well-Behaved Drush Extensions
Site-Local Drush
13
Drush dispatch now happens in four phases:
14
Drush Dispatch
Drush Finder Drush Wrapper Drush Launcher
Drush
Application
15
Drush Finder
Responsible for finding the correct Drush to run
● Checks to see if it can find a Drupal site
● If the Drupal site contains a Drush script, use it
● If no Site-Local Drush is found, use global Drush
Does not look at alias files.
PHP Script
Optional. Located at the Drupal Root if it exists.
User may customize this script to:
● Add site-specific options (e.g. commandfile
locations)
● Select the location of the Drush launcher (if in a
non-standard location)
If there is no Drush Wrapper, then the Drush Finder
will find and execute the Drush Launcher.
16
Drush Wrapper
Shell Script
17
Drush Launcher
Sets up the PHP operating environment.
● Select php.ini file to use
● Select php executable to use
● Passes info about environment to Drush
Always launches the Drush that is located next to it.
Shell Script
18
Drush Application
Contains all the code that is Drush.
● Load configuration and command file
● Parse site alias files
● Might dispatch again, e.g. if site alias is remote
PHP
Application
Manage Drush and Drupal
Place Drush and Drupal in the same composer.json file:
cd /path/to/drupal-8-root
composer require drush/drush:8.*
It is also possible to use site-local Drush with a non-Composer-managed
Drupal site just to attach a specific version of Drush to that site:
cd /path/to/old/drupal-root
composer require drush/drush:6.*
19
CRITICAL
Drush Extensions
20Photo © 2011 by Shawn Clover, CC BY-NA 2.0
PROBLEM:
A Drush extension desires to use Composer
Libraries, but also wants to work with both
Composer-managed sites, and sites that do
not use Composer.
SOLUTION:
Include a composer.json file as usual, and
require libraries there. In your drush extension’
s hook_drush_init, call drush_autoload
(__FILE__).
21
Composer Libraries in Extensions
my.drush.inc:
function my_drush_init() {
drush_autoload(__FILE__);
}
IT’S SIMPLE.
If Drush has located a Drupal site that has an autoloader, then it assumes that
all extensions that need an autoloader are part of the Drupal site’s composer.
json file. Drush only loads Drupal’s autoload.php.
If the Drupal site does not have an autoloader, then Drush will find the
extension’s autoloader, and load it.
AN EXTENSION CAN’T GET THIS RIGHT. ALWAYS USE
drush_autoload.
22
drush_autoload Function
Global Extensions
23
Drush Extensions that use Composer libraries must be included locally as part
of your Drupal project:
cd /path/to/project
composer require drupal/drush_iq
Policy files can continue to live in a global location, e.g. $HOME/.drush.
24
Include Global Extensions in Project
{
"name": "drupal/drupal",
"require": {
"composer/installers": "^1.0.21",
"wikimedia/composer-merge-plugin": "^1.3.0",
"drush/drush": "dev-master"
},
"extra": {
"merge-plugin": {
"include": [
"/Users/ME/.drush-extensions/composer.json"
],
"recurse": false,
"replace": false,
"merge-extra": false
}
},
}
Drupal Project
composer.json:
Global Extensions List
composer.json:
$HOME
└── .drush-extensions
├── composer.json
├── composer.lock
├── drush
│ └── registry_rebuild
│ ├── registry_rebuild.drush.inc
│ └── registry_rebuild.php
└── vendor
└── autoload.php
Drush Configuration Filter
25
Configuration Workflow
26
Code and Content move in only one direction, but Configuration can move in
either direction.
To keep development modules out of exported configuration, define:
__ROOT__/drush/drushrc.php:
$command_specific['config-export']['skip-modules'] = array('devel');
$command_specific['config-import']['skip-modules'] = array(‘devel');
This only works with the Drush config-import and config-export
commands. Use caution with the Configuration Synchronization admin page.
27
Configuration Filter
The Future
28
Drush and Drupal Console
29
The more code you have, the more code you
have to maintain.
However, the maintenance process adds value.
New code should benefit from existing code.
Duplicate functions that do the same thing should
be avoided to reduce maintenance requirements.
&
Drush Bootstrap Refactor
30
Drush now has separate bootstrap
classes for each framework
Boot
validRoot($path);
DrupalBoot6
validRoot($path);
DrupalBoot7
validRoot($path);
DrupalBoot8
validRoot($path);
SOMEDAY?
By factoring Site Aliases and Backend Invoke into separate libraries, the “Drush
Finder” can handle remote dispatches.
31
Refactor into Composer Libraries
Drush Finder Drush Wrapper Drush Launcher Drush Application
cd /path/to/drupal-project
composer require pantheon-systems/behat-drush-endpoint
32
Drush Driver Enhancement
YES!

Más contenido relacionado

La actualidad más candente

Building a Drupal site with Git
Building a Drupal site with GitBuilding a Drupal site with Git
Building a Drupal site with Git
dirtytactics
 
Docker workshop
Docker workshopDocker workshop
Docker workshop
Evans Ye
 

La actualidad más candente (20)

문서화에 날개를 달아주는 Flybook CLI
문서화에 날개를 달아주는 Flybook CLI문서화에 날개를 달아주는 Flybook CLI
문서화에 날개를 달아주는 Flybook CLI
 
DevOps: Cooking Drupal Deployment
DevOps: Cooking Drupal DeploymentDevOps: Cooking Drupal Deployment
DevOps: Cooking Drupal Deployment
 
Building a Drupal site with Git
Building a Drupal site with GitBuilding a Drupal site with Git
Building a Drupal site with Git
 
How to Use the Command Line to Increase Speed of Development
How to Use the Command Line to Increase Speed of DevelopmentHow to Use the Command Line to Increase Speed of Development
How to Use the Command Line to Increase Speed of Development
 
Gdg cloud taipei ddt meetup #53 buildpack
Gdg cloud taipei ddt meetup #53 buildpackGdg cloud taipei ddt meetup #53 buildpack
Gdg cloud taipei ddt meetup #53 buildpack
 
Puppet and Vagrant in development
Puppet and Vagrant in developmentPuppet and Vagrant in development
Puppet and Vagrant in development
 
Drupal in Libraries
Drupal in LibrariesDrupal in Libraries
Drupal in Libraries
 
Exploring composer in drupal 8 with drupal project - salva molina
Exploring composer in drupal 8 with drupal project - salva molinaExploring composer in drupal 8 with drupal project - salva molina
Exploring composer in drupal 8 with drupal project - salva molina
 
Docker for Developers - php[tek] 2017
Docker for Developers - php[tek] 2017Docker for Developers - php[tek] 2017
Docker for Developers - php[tek] 2017
 
Cmake kitware
Cmake kitwareCmake kitware
Cmake kitware
 
Docker workshop
Docker workshopDocker workshop
Docker workshop
 
Drupal Console Deep Dive: How to Develop Faster and Smarter on Drupal 8
Drupal Console Deep Dive: How to Develop Faster and Smarter on Drupal 8Drupal Console Deep Dive: How to Develop Faster and Smarter on Drupal 8
Drupal Console Deep Dive: How to Develop Faster and Smarter on Drupal 8
 
A Hands-on Introduction to Docker
A Hands-on Introduction to DockerA Hands-on Introduction to Docker
A Hands-on Introduction to Docker
 
Scalable Cloud-Native Masterless Puppet, with PuppetDB and Bolt, Craig Watson...
Scalable Cloud-Native Masterless Puppet, with PuppetDB and Bolt, Craig Watson...Scalable Cloud-Native Masterless Puppet, with PuppetDB and Bolt, Craig Watson...
Scalable Cloud-Native Masterless Puppet, with PuppetDB and Bolt, Craig Watson...
 
Best Practices for Development Deployment & Distributions: Capital Camp + Gov...
Best Practices for Development Deployment & Distributions: Capital Camp + Gov...Best Practices for Development Deployment & Distributions: Capital Camp + Gov...
Best Practices for Development Deployment & Distributions: Capital Camp + Gov...
 
How a Content Delivery Network Can Help Speed Up Your Website
How a Content Delivery Network Can Help Speed Up Your WebsiteHow a Content Delivery Network Can Help Speed Up Your Website
How a Content Delivery Network Can Help Speed Up Your Website
 
Into The Box 2018 | Content box + docker
Into The Box 2018 | Content box + dockerInto The Box 2018 | Content box + docker
Into The Box 2018 | Content box + docker
 
Hands on Docker - Launch your own LEMP or LAMP stack
Hands on Docker -  Launch your own LEMP or LAMP stackHands on Docker -  Launch your own LEMP or LAMP stack
Hands on Docker - Launch your own LEMP or LAMP stack
 
CMake Talk 2008
CMake Talk 2008CMake Talk 2008
CMake Talk 2008
 
Native Hadoop with prebuilt spark
Native Hadoop with prebuilt sparkNative Hadoop with prebuilt spark
Native Hadoop with prebuilt spark
 

Destacado

Testing Your Code as Part of an Industrial Grade Workflow
Testing Your Code as Part of an Industrial Grade WorkflowTesting Your Code as Part of an Industrial Grade Workflow
Testing Your Code as Part of an Industrial Grade Workflow
Pantheon
 

Destacado (17)

Migrating NYSenate.gov
Migrating NYSenate.govMigrating NYSenate.gov
Migrating NYSenate.gov
 
How Drupal 8 Reaches Its Full Potential on Pantheon
How Drupal 8 Reaches Its Full Potential on PantheonHow Drupal 8 Reaches Its Full Potential on Pantheon
How Drupal 8 Reaches Its Full Potential on Pantheon
 
WP or Drupal (or both): A Framework for Client CMS Decisions
WP or Drupal (or both): A Framework for Client CMS Decisions WP or Drupal (or both): A Framework for Client CMS Decisions
WP or Drupal (or both): A Framework for Client CMS Decisions
 
Testing Your Code as Part of an Industrial Grade Workflow
Testing Your Code as Part of an Industrial Grade WorkflowTesting Your Code as Part of an Industrial Grade Workflow
Testing Your Code as Part of an Industrial Grade Workflow
 
Start with Drupal CMS
Start with Drupal CMSStart with Drupal CMS
Start with Drupal CMS
 
Test Coverage for Your WP REST API Project
Test Coverage for Your WP REST API ProjectTest Coverage for Your WP REST API Project
Test Coverage for Your WP REST API Project
 
WordPress at Scale Webinar
WordPress at Scale WebinarWordPress at Scale Webinar
WordPress at Scale Webinar
 
Level Up: 5 Expert Tips for Optimizing WordPress Performance
Level Up: 5 Expert Tips for Optimizing WordPress PerformanceLevel Up: 5 Expert Tips for Optimizing WordPress Performance
Level Up: 5 Expert Tips for Optimizing WordPress Performance
 
Drupal 8 and Pantheon
Drupal 8 and PantheonDrupal 8 and Pantheon
Drupal 8 and Pantheon
 
Continuous Integration Is for Teams: Moving past buzzword driven development
Continuous Integration Is for Teams: Moving past buzzword driven development Continuous Integration Is for Teams: Moving past buzzword driven development
Continuous Integration Is for Teams: Moving past buzzword driven development
 
Decoupled Architecture and WordPress
Decoupled Architecture and WordPressDecoupled Architecture and WordPress
Decoupled Architecture and WordPress
 
Drupal Performance
Drupal Performance Drupal Performance
Drupal Performance
 
WordPress REST API: Expert Advice & Practical Use Cases
WordPress REST API: Expert Advice & Practical Use CasesWordPress REST API: Expert Advice & Practical Use Cases
WordPress REST API: Expert Advice & Practical Use Cases
 
Why Your Site is Slow: Performance Answers for Your Clients
Why Your Site is Slow: Performance Answers for Your ClientsWhy Your Site is Slow: Performance Answers for Your Clients
Why Your Site is Slow: Performance Answers for Your Clients
 
Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...
Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...
Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...
 
Automating & Integrating Pantheon with JIRA, Slack, Jenkins and More
Automating & Integrating Pantheon with JIRA, Slack, Jenkins and MoreAutomating & Integrating Pantheon with JIRA, Slack, Jenkins and More
Automating & Integrating Pantheon with JIRA, Slack, Jenkins and More
 
Development Workflow Tools for Open-Source PHP Libraries
Development Workflow Tools for Open-Source PHP LibrariesDevelopment Workflow Tools for Open-Source PHP Libraries
Development Workflow Tools for Open-Source PHP Libraries
 

Similar a Drush in the Composer Era

5 Important Tools for Drupal Development
5 Important Tools for Drupal Development5 Important Tools for Drupal Development
5 Important Tools for Drupal Development
jcarrig
 
LuisRodriguezLocalDevEnvironmentsDrupalOpenDays
LuisRodriguezLocalDevEnvironmentsDrupalOpenDaysLuisRodriguezLocalDevEnvironmentsDrupalOpenDays
LuisRodriguezLocalDevEnvironmentsDrupalOpenDays
Luis Rodríguez Castromil
 
Drush installation guide
Drush installation guideDrush installation guide
Drush installation guide
Thierno Fall
 

Similar a Drush in the Composer Era (20)

Composer tools and frameworks for Drupal
Composer tools and frameworks for DrupalComposer tools and frameworks for Drupal
Composer tools and frameworks for Drupal
 
A Drush Primer - DrupalCamp Chattanooga 2013
A Drush Primer - DrupalCamp Chattanooga 2013A Drush Primer - DrupalCamp Chattanooga 2013
A Drush Primer - DrupalCamp Chattanooga 2013
 
Face your fears: Drush and Aegir
Face your fears: Drush and AegirFace your fears: Drush and Aegir
Face your fears: Drush and Aegir
 
5 Important Tools for Drupal Development
5 Important Tools for Drupal Development5 Important Tools for Drupal Development
5 Important Tools for Drupal Development
 
Drush workshop
Drush workshopDrush workshop
Drush workshop
 
Improving your Drupal 8 development workflow DrupalCampLA
Improving your Drupal 8 development workflow DrupalCampLAImproving your Drupal 8 development workflow DrupalCampLA
Improving your Drupal 8 development workflow DrupalCampLA
 
Drupal + composer = new love !?
Drupal + composer = new love !?Drupal + composer = new love !?
Drupal + composer = new love !?
 
Pavlenko Sergey. Drush: using and creating custom commands. DrupalCamp Kyiv 2011
Pavlenko Sergey. Drush: using and creating custom commands. DrupalCamp Kyiv 2011Pavlenko Sergey. Drush: using and creating custom commands. DrupalCamp Kyiv 2011
Pavlenko Sergey. Drush: using and creating custom commands. DrupalCamp Kyiv 2011
 
Introduction to Composer for Drupal
Introduction to Composer for DrupalIntroduction to Composer for Drupal
Introduction to Composer for Drupal
 
LuisRodriguezLocalDevEnvironmentsDrupalOpenDays
LuisRodriguezLocalDevEnvironmentsDrupalOpenDaysLuisRodriguezLocalDevEnvironmentsDrupalOpenDays
LuisRodriguezLocalDevEnvironmentsDrupalOpenDays
 
Efficient development workflows with composer
Efficient development workflows with composerEfficient development workflows with composer
Efficient development workflows with composer
 
Drush
DrushDrush
Drush
 
Drupal 8 improvements for developer productivity php symfony and more
Drupal 8 improvements for developer productivity  php symfony and moreDrupal 8 improvements for developer productivity  php symfony and more
Drupal 8 improvements for developer productivity php symfony and more
 
drush_multi @ DrupalDevDays 2010
drush_multi @ DrupalDevDays 2010drush_multi @ DrupalDevDays 2010
drush_multi @ DrupalDevDays 2010
 
Introduction to Drupal - Installation, Anatomy, Terminologies
Introduction to Drupal - Installation, Anatomy, TerminologiesIntroduction to Drupal - Installation, Anatomy, Terminologies
Introduction to Drupal - Installation, Anatomy, Terminologies
 
Drupal 8 - Improving your development workflow
Drupal 8 - Improving your development workflowDrupal 8 - Improving your development workflow
Drupal 8 - Improving your development workflow
 
Drush installation guide
Drush installation guideDrush installation guide
Drush installation guide
 
Efficient development workflows with composer
Efficient development workflows with composerEfficient development workflows with composer
Efficient development workflows with composer
 
Managing your Drupal project with Composer
Managing your Drupal project with ComposerManaging your Drupal project with Composer
Managing your Drupal project with Composer
 
Beginning Drush
Beginning DrushBeginning Drush
Beginning Drush
 

Más de Pantheon

Más de Pantheon (13)

Drupal Migrations in 2018
Drupal Migrations in 2018Drupal Migrations in 2018
Drupal Migrations in 2018
 
Architecting Million Dollar Projects
Architecting Million Dollar ProjectsArchitecting Million Dollar Projects
Architecting Million Dollar Projects
 
Streamlined Drupal 8: Site Building Strategies for Tight Deadlines
Streamlined Drupal 8: Site Building Strategies for Tight DeadlinesStreamlined Drupal 8: Site Building Strategies for Tight Deadlines
Streamlined Drupal 8: Site Building Strategies for Tight Deadlines
 
Getting Started with Drupal
Getting Started with DrupalGetting Started with Drupal
Getting Started with Drupal
 
Defense in Depth: Lessons Learned Securing 200,000 Sites
Defense in Depth: Lessons Learned Securing 200,000 SitesDefense in Depth: Lessons Learned Securing 200,000 Sites
Defense in Depth: Lessons Learned Securing 200,000 Sites
 
Automate Your Automation | DrupalCon Vienna
Automate Your Automation | DrupalCon ViennaAutomate Your Automation | DrupalCon Vienna
Automate Your Automation | DrupalCon Vienna
 
Sub-Second Pageloads: Beat the Speed of Light with Pantheon & Fastly
Sub-Second Pageloads: Beat the Speed of Light with Pantheon & FastlySub-Second Pageloads: Beat the Speed of Light with Pantheon & Fastly
Sub-Second Pageloads: Beat the Speed of Light with Pantheon & Fastly
 
Building a Network of 195 Drupal 8 Sites
Building a Network of 195 Drupal 8 Sites Building a Network of 195 Drupal 8 Sites
Building a Network of 195 Drupal 8 Sites
 
Hacking Your Agency Workflow: Treating Your Process Like A Product
Hacking Your Agency Workflow: Treating Your Process Like A ProductHacking Your Agency Workflow: Treating Your Process Like A Product
Hacking Your Agency Workflow: Treating Your Process Like A Product
 
Best Practice Site Architecture in Drupal 8
Best Practice Site Architecture in Drupal 8Best Practice Site Architecture in Drupal 8
Best Practice Site Architecture in Drupal 8
 
Preparing for the Internet Zombie Apocalypse
Preparing for the Internet Zombie ApocalypsePreparing for the Internet Zombie Apocalypse
Preparing for the Internet Zombie Apocalypse
 
Content as a Service: What to Know About Decoupled CMS
Content as a Service: What to Know About Decoupled CMSContent as a Service: What to Know About Decoupled CMS
Content as a Service: What to Know About Decoupled CMS
 
Drupal 8 CMI on a Managed Workflow
Drupal 8 CMI on a Managed WorkflowDrupal 8 CMI on a Managed Workflow
Drupal 8 CMI on a Managed Workflow
 

Último

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

Drush in the Composer Era

  • 1. Drush in the Composer Era 1Photo © 2012 by Charlie Nguyen, CC BY 2.0
  • 2. 2 Overview Using Composer Dependency Hell Site-Local Drush Configuration Filter The FutureDrush Extensions
  • 3. It is now possible to use Composer to add code directly to Drupal: drush dl drupal-8 cd drupal-8 composer require drupal/og:8.* composer update will not update drupal/core; use drush pm-update drupal for this. 3 Standard Composer used in D8
  • 4. web ├── autoload.php ├── composer.json ├── core │ └─ composer.json ├── index.php └── vendor └─ autoload.php 4 wikimedia/composer-merge-plugin { "name": "drupal/drupal", "require": { "composer/installers": "^1.0.21", "wikimedia/composer-merge-plugin": "^1.3.0" }, "extra": { "_readme": [ "By default Drupal loads the autoloader from ./vendor/autoload.php.", "To change the autoloader you can edit ./autoload.php." ], "merge-plugin": { "include": [ "core/composer.json" ], "recurse": false, "replace": false, "merge-extra": false } }, }
  • 5. Uses “split core” to manage Drupal core files: composer create-project drupal- composer/drupal-project:8.x-dev my-site-name --stability dev -- no-interaction 5 Drupal 8: “drupal-project”
  • 6. project ├── composer.json ├── vendor │ └── autoload.php └── web ├── autoload.php ├── core │ └── composer.json └── index.php 6 drupal-project Layout { "name": "drupal-composer/drupal-project", "repositories": [ { "type": "composer", "url": "https://packagist.drupal-composer.org" } ], "require": { "composer/installers": "^1.0.20", "drupal/core": "8.0.*", "drush/drush": "dev-master", "drupal/console": "dev-master" }, "extra": { "installer-paths": { "web/core": ["type:drupal-core"], "web/modules/contrib/{$name}": ["type:drupal-module"], "drush/contrib/{$name}": ["type:drupal-drush"] } } }
  • 7. 7 Drupal 7: Example CI Scripts example-drupal7-circle-composer example-drupal7-travis-composer CI + +
  • 8. Use craychee/rootcanal to post- process your Composer install: "config": { "bin-dir": "bin" }, "scripts": { "post-install-cmd": [ "bin/rootcanal" ], "post-update-cmd": [ "bin/rootcanal" ] } } http://craychee.io/blog/2015/08/01/no-excuses-part3-composer/ 8 Drupal 7: rootcanal
  • 10. The Multiple Autoloaders Problem 10 Two autoloaders may directly or indirectly include the same dependent library. Drupal 8 require autoload.php Badly-Behaved Drush Extension require autoload.php "name": "symfony/event-dispatcher", "version": "v2.7.5", "name": "symfony/event-dispatcher", "version": "3.*",
  • 11. Version Mismatch Breaks 11 Event isPropagationStopped stopPropagation symfony/event-dispatcher v2.7.5 symfony/event-dispatcher v3.x public function dispatch($event_name, Event $event) { $event->setDispatcher($this); Event isPropagationStopped stopPropagation setDispatcher getDispatcher getName setName DrupalComponentEventDispatcherContainerAwareEventDispatcher.dispatch
  • 12. Site-Local Drush 12 Solution to Dependency Hell Well-Behaved Drush Extensions
  • 14. Drush dispatch now happens in four phases: 14 Drush Dispatch Drush Finder Drush Wrapper Drush Launcher Drush Application
  • 15. 15 Drush Finder Responsible for finding the correct Drush to run ● Checks to see if it can find a Drupal site ● If the Drupal site contains a Drush script, use it ● If no Site-Local Drush is found, use global Drush Does not look at alias files. PHP Script
  • 16. Optional. Located at the Drupal Root if it exists. User may customize this script to: ● Add site-specific options (e.g. commandfile locations) ● Select the location of the Drush launcher (if in a non-standard location) If there is no Drush Wrapper, then the Drush Finder will find and execute the Drush Launcher. 16 Drush Wrapper Shell Script
  • 17. 17 Drush Launcher Sets up the PHP operating environment. ● Select php.ini file to use ● Select php executable to use ● Passes info about environment to Drush Always launches the Drush that is located next to it. Shell Script
  • 18. 18 Drush Application Contains all the code that is Drush. ● Load configuration and command file ● Parse site alias files ● Might dispatch again, e.g. if site alias is remote PHP Application
  • 19. Manage Drush and Drupal Place Drush and Drupal in the same composer.json file: cd /path/to/drupal-8-root composer require drush/drush:8.* It is also possible to use site-local Drush with a non-Composer-managed Drupal site just to attach a specific version of Drush to that site: cd /path/to/old/drupal-root composer require drush/drush:6.* 19 CRITICAL
  • 20. Drush Extensions 20Photo © 2011 by Shawn Clover, CC BY-NA 2.0
  • 21. PROBLEM: A Drush extension desires to use Composer Libraries, but also wants to work with both Composer-managed sites, and sites that do not use Composer. SOLUTION: Include a composer.json file as usual, and require libraries there. In your drush extension’ s hook_drush_init, call drush_autoload (__FILE__). 21 Composer Libraries in Extensions my.drush.inc: function my_drush_init() { drush_autoload(__FILE__); }
  • 22. IT’S SIMPLE. If Drush has located a Drupal site that has an autoloader, then it assumes that all extensions that need an autoloader are part of the Drupal site’s composer. json file. Drush only loads Drupal’s autoload.php. If the Drupal site does not have an autoloader, then Drush will find the extension’s autoloader, and load it. AN EXTENSION CAN’T GET THIS RIGHT. ALWAYS USE drush_autoload. 22 drush_autoload Function
  • 23. Global Extensions 23 Drush Extensions that use Composer libraries must be included locally as part of your Drupal project: cd /path/to/project composer require drupal/drush_iq Policy files can continue to live in a global location, e.g. $HOME/.drush.
  • 24. 24 Include Global Extensions in Project { "name": "drupal/drupal", "require": { "composer/installers": "^1.0.21", "wikimedia/composer-merge-plugin": "^1.3.0", "drush/drush": "dev-master" }, "extra": { "merge-plugin": { "include": [ "/Users/ME/.drush-extensions/composer.json" ], "recurse": false, "replace": false, "merge-extra": false } }, } Drupal Project composer.json: Global Extensions List composer.json: $HOME └── .drush-extensions ├── composer.json ├── composer.lock ├── drush │ └── registry_rebuild │ ├── registry_rebuild.drush.inc │ └── registry_rebuild.php └── vendor └── autoload.php
  • 26. Configuration Workflow 26 Code and Content move in only one direction, but Configuration can move in either direction.
  • 27. To keep development modules out of exported configuration, define: __ROOT__/drush/drushrc.php: $command_specific['config-export']['skip-modules'] = array('devel'); $command_specific['config-import']['skip-modules'] = array(‘devel'); This only works with the Drush config-import and config-export commands. Use caution with the Configuration Synchronization admin page. 27 Configuration Filter
  • 29. Drush and Drupal Console 29 The more code you have, the more code you have to maintain. However, the maintenance process adds value. New code should benefit from existing code. Duplicate functions that do the same thing should be avoided to reduce maintenance requirements. &
  • 30. Drush Bootstrap Refactor 30 Drush now has separate bootstrap classes for each framework Boot validRoot($path); DrupalBoot6 validRoot($path); DrupalBoot7 validRoot($path); DrupalBoot8 validRoot($path); SOMEDAY?
  • 31. By factoring Site Aliases and Backend Invoke into separate libraries, the “Drush Finder” can handle remote dispatches. 31 Refactor into Composer Libraries Drush Finder Drush Wrapper Drush Launcher Drush Application
  • 32. cd /path/to/drupal-project composer require pantheon-systems/behat-drush-endpoint 32 Drush Driver Enhancement YES!