SlideShare a Scribd company logo
Efficient development
workflows
with Composer
About me
● Wolfgang Ziegler
● drupal.org/u/fago
● @the_real_fago at
twitter
Wolfgang Ziegler // fago
●
More than 10 years of Drupal experience
●
Leading force behind the Drupal 8 Entity
Field API improvements
Maintainer of Typed Data API
●
Creator of Rules, Field Collection, Profile2
CEO/CTO of
http://getcomposer.org
What is it?
● Dependency manager for PHP
● Use and publish packages
● Package-metadata:
composer.json
● Repository: packagist.org
composer.json
{
"name": "drupal/core",
"description": "Drupal is an open 
source content management....",
"require": {
  "twig/twig": "1.15.*",
  "symfony/class­loader": "2.5.*",
Using a package
composer require guzzle/guzzle 
Providing a package
● Add composer.json
● Tag releases Semantic→
versioning
● Add Git repository to
packagist.org
Packagist
Using it in project
● Add composer .json
● Specify
● Add dependencies
"type": "project"
Using it in a project
git clone ­­branch 8.1.x 
https://git.drupal.org/project/
drupal.git
cd drupal
composer install
What happens?
● Reads composer.lock and
installs recorded versions
● Downloads code and puts it into
./vendor
(or somewhere else)
● Generates a class autoloader
Composer update & locks
● composer update
– Update all the dependencies and
write new lock file
● composer install 
– Apply what's recorded in the lock file
Composer & VCS
● Commit composer.json
● For projects: Commit
composer.lock
● For libraries: Commit
composer.lock for tests
● Avoid commit vendor files
Versions & Composer
● Require versions like 2.1.*
● composer supports many different
version constraints
● Specify allowed versions, not
specific versions
Composer & Drupal Projects
Bye, bye, drush make!
● composer replaces drush make
● Support for Drupal modules via:
– https://packagist.drupal­composer.org
– https://packages.drupal.org/7
– https://packages.drupal.org/8
Project template
http://github.com/
drupal-composer/drupal-project
Start a new d8 project
composer create­project 
drupal­composer/drupal­project
What does it do?
● Adds Drupal into the „web“ dir
● Adds folder structure, drush, Drupal
console, …
● Custom projects can add more stuff
and/or customize things
– Add Drupal modules & themes!
Drupal modules & ./vendor?
● Composer package types:
– library
– project
– drupal­module
– drupal­theme
– drupal­profile
– drupal­drush
Working with a
composer-based Drupal
project
composer install all the way!
● Do not forget to run composer
install!
● After pulling changes, run it!
● Best: Add to deployment alias:
composer install && 
drush updatedb && ...
Adding a module
composer require drupal/MODULE
composer require drupal/MODULE=1.*
composer require drupal/MODULE=1.*@beta 
composer require drupal/MODULE=1.*@dev
Downloads the module + updates files!
Keep things ordered
 "config": {
   "sort­packages": true,
 },
Update your modules
● composer update
● Commit the changes in
composer.lock !
Update a single module
composer update drupal/module
composer update drupal/module  
­­with­depdendencies
Checking installed versions
● List all packages:
composer show
● List directly added pagckages
only:
composer show ­D
Where did it go?
composer show ­P
Patches
● cweagans/composer-patches
"extra": {
  "patches": {
    "drupal/foobar": {
      "description": "URL to patch"
    }
  }
}
Add custom repositories
With composer.json:
"require": {
  "fago/example": "1.*"
}
"repositories": [ 
  {
    "type": "vcs",
    "url": "http://github.com/fago/example"
  }
]
SemVer branching
● Branches:
– 1.0.x
– 1.1.x
– 2.0.x
● Tags / Releases:
– 1.0.0
– 1.0.1
– 1.1.0
– 2.0.0
Composer versions
1.*       =>  1.1.0
^1.0.1    =>  1.1.0 (>=1.0.1, <2)
~1.0      =>  1.1.0 (>=1.0.0, <2)
~1.0.0    =>  1.0.1 (>=1.0.0, <1.1)
1.*@dev   =>  1.1.0 (prefer­stable)
1.*@dev   =>  1.1.0 (prefer­stable)
*         =>  2.0.0
Custom repositories
Without composer.json:
"repositories": [{
  "type": "package",
  "package": {
    "name": "fago/example",
    "version": "0.1.0",
    "source": {
      "url": "github.com/fago/example",
      "type": "git",
      "reference": "0.1.0"
    }
  }
}]
Patches
● cweagans/composer-patches
"extra": {
  "patches": {
    "drupal/foobar": {
      "description": "URL to patch"
    }
  }
}
Fork & add your fork
● Alternative to patch files
● Works great with the Github pull
request workflow
● composer create­project 
drupal/module path 2.2.0
● Add in the fork instead upstream
Adding in your fork
"require": {
  "samson/yt": "dev­BRANCH as 2.0.0"
},
"repositories": [
  {
    "type": "vcs",
    "url": "https://github.com/fago/yt"
  }
],
Keep builds fast
● composer fetches either „dist“ or
„source“ packages
● Prefer „dist“ packages for fast
builds & cache use!
● Pre-configured in drupal-project
Edit your vendors
rm ­r web/modules/contrib/pathauto
composer install ­­prefer­source
cd web/modules/contrib/pathauto
git checkout ­b your­pathauto­branch
Merge conflicts?
composer update ­­lock
● „Nice“ hash in composer.lock
● Just merge and resolve it by doing
either
composer scripts
  "scripts": {
    "test": "phpunit web/modules/custom",
    "deploy": "drush updatedb ­y && ...",
  },
  
  composer deploy
  composer test
composer scripts
● Uses vendor binaries!
● React on events like
– post-package-install
– post-create-project-cmd
– ..
● Reference other scripts via @script
● Handy for documented developer short-cuts
Deploying composer
managed projects!
Avoid committing vendors!
● Smaller diffs & pull requests
=> easy to review!
● Keeps repositories smaller (only
custom code)
● Work with vendor repositories
without submodules
Builds & Deployment
1.Hosting takes care of it
2.Deployment tools like capistrano
or deployer (http://deployer.org)
3.Git-based deployments of build-
branches or build-repositories
Git-based deployments
● Common in the Drupal world as it
is required by many Drupal
hosters
● I like it :-)
Build branches
Never merge build branches back!
master  => build/master
version/2016­CW47 => build/version/2016­CW47
release/2016­CW47 => build/release/2016­CW47
Build branches
● We keep them in the same
repository
● Enables possible future
enhancements
Creating builds
● PHP-console script for creating
builds
● Takes care of updating pre-existing
build branches (think: build/master)
● Takes care of tags
● Takes care of vendor repositories
phapp cli
● Tool for managing PHP
applications
● Not yet many commands besides
„phapp build“
● https://github.com/ 
drunomics/phapp­cli
phapp build
● Custom build scripts via phapp.yml
per project
=> Allows adding things like npm
● Just build in place?
→ phapp build
● Build a branch?
→ phapp build BRANCH
Deployment updates
● Apply changes after code update
● Do not rely on special server
environments!
→ More reliable deployments!
Deployment script tools
● composer scripts
● Robo
● Drush, Drupal console
Add dependencies to the project!
Creating re-usable packages
Why?
● Develop re-usable PHP libraries,
e.g. REST clients
● Feature modules for kick-starting
development
composer require 
drunomics/dsk_media
Add your own packages
● Custom repositories at project
● Run your own packagist
● Use Toran Proxy
● Use satis & static files
– Scans your repositories
– Re-run after every change
"repositories": [
  {
    "type": "composer",
    "url": "https://satis.example.com"
  }
],
Edit your code
● Use source for your packages
"config": {
    "preferred­install": {
       "drunomics/*": "source",
       "*": "dist"
    }
}
Issue:
Some modules need libraries
Handling libraries & assets
● Possible solutions:
– Add them via custom repostories
– composer scripts for running bower or
npm on project install
– fxp/composer-asset-plugin
– ...
asset-packagist.org
Project configuration
"repositories": [{
    "type": "composer",
    "url": "https://asset­packagist.org"
}],
"require": {
 "oomphinc/composer­installers­extender": "*",
},
"extra": {
  "installer­types": ["library"],
  "installer­paths": {
    "web/libraries/{$name}/": ["vendor:bower­
asset", "vendor:npm­asset"]
  }
}
Package
drunomics/dsk_media composer.json:
  "require": {
    "bower­asset/dropzone": "~4.2"
  }
Usage
composer install
Questions?

More Related Content

What's hot

Docker 101 - From production to development
Docker 101 - From production to developmentDocker 101 - From production to development
Docker 101 - From production to development
Raül Pérez
 

What's hot (20)

Composer
ComposerComposer
Composer
 
OpenCms Days 2014 - OpenCms Module Development and Deployment with IntelliJ, ...
OpenCms Days 2014 - OpenCms Module Development and Deployment with IntelliJ, ...OpenCms Days 2014 - OpenCms Module Development and Deployment with IntelliJ, ...
OpenCms Days 2014 - OpenCms Module Development and Deployment with IntelliJ, ...
 
Composer & Drupal
Composer & DrupalComposer & Drupal
Composer & Drupal
 
Chromium: NaCl and Pepper API
Chromium: NaCl and Pepper APIChromium: NaCl and Pepper API
Chromium: NaCl and Pepper API
 
Magento 2 Capistrano Deploy
Magento 2 Capistrano DeployMagento 2 Capistrano Deploy
Magento 2 Capistrano Deploy
 
OpenCms Days 2015 How do you develop for OpenCms?
OpenCms Days 2015 How do you develop for OpenCms?OpenCms Days 2015 How do you develop for OpenCms?
OpenCms Days 2015 How do you develop for OpenCms?
 
Ninja Build: Simple Guide for Beginners
Ninja Build: Simple Guide for BeginnersNinja Build: Simple Guide for Beginners
Ninja Build: Simple Guide for Beginners
 
OpenCms Days 2013 - Start rolling with OpenCms 9
OpenCms Days 2013 - Start rolling with OpenCms 9OpenCms Days 2013 - Start rolling with OpenCms 9
OpenCms Days 2013 - Start rolling with OpenCms 9
 
Using Composer with Drupal and Drush
Using Composer with Drupal and DrushUsing Composer with Drupal and Drush
Using Composer with Drupal and Drush
 
[drupalday2017] - DevOps: strumenti di automazione per Drupal8
[drupalday2017] - DevOps: strumenti di automazione per Drupal8[drupalday2017] - DevOps: strumenti di automazione per Drupal8
[drupalday2017] - DevOps: strumenti di automazione per Drupal8
 
Gulp and bower Implementation
Gulp and bower Implementation Gulp and bower Implementation
Gulp and bower Implementation
 
Headless Drupal
Headless DrupalHeadless Drupal
Headless Drupal
 
Docker 101 - From production to development
Docker 101 - From production to developmentDocker 101 - From production to development
Docker 101 - From production to development
 
OpenCmsDays 2013 - Using OpenCms 9 folders as a network drive
OpenCmsDays 2013 - Using OpenCms 9 folders as a network driveOpenCmsDays 2013 - Using OpenCms 9 folders as a network drive
OpenCmsDays 2013 - Using OpenCms 9 folders as a network drive
 
OpenCms Days 2015: Keynote - OpenCms 10 X marks the spot
OpenCms Days 2015: Keynote - OpenCms 10 X marks the spotOpenCms Days 2015: Keynote - OpenCms 10 X marks the spot
OpenCms Days 2015: Keynote - OpenCms 10 X marks the spot
 
Devel for Drupal 8
Devel for Drupal 8Devel for Drupal 8
Devel for Drupal 8
 
Lean Drupal Repositories with Composer and Drush
Lean Drupal Repositories with Composer and DrushLean Drupal Repositories with Composer and Drush
Lean Drupal Repositories with Composer and Drush
 
The Workflow Methodology to Train Your Team on Drupal 8
The Workflow Methodology to Train Your Team on Drupal 8The Workflow Methodology to Train Your Team on Drupal 8
The Workflow Methodology to Train Your Team on Drupal 8
 
Drupal Developer Days Keynote
Drupal Developer Days KeynoteDrupal Developer Days Keynote
Drupal Developer Days Keynote
 
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
 

Viewers also liked

Newsletter iii2016
Newsletter iii2016Newsletter iii2016
Newsletter iii2016
Salutaria
 
Sanjay Singh Nayal-CV
Sanjay Singh Nayal-CVSanjay Singh Nayal-CV
Sanjay Singh Nayal-CV
Nayal Sanjay
 
Biografía del dr. alfonso millán maldonado (27/ago/2013)
Biografía del dr. alfonso millán maldonado (27/ago/2013)Biografía del dr. alfonso millán maldonado (27/ago/2013)
Biografía del dr. alfonso millán maldonado (27/ago/2013)
MedicinaUas
 

Viewers also liked (20)

Homepage i TOS - #Moja Srbija
Homepage i TOS - #Moja SrbijaHomepage i TOS - #Moja Srbija
Homepage i TOS - #Moja Srbija
 
Mastering composer
Mastering composerMastering composer
Mastering composer
 
Newsletter iii2016
Newsletter iii2016Newsletter iii2016
Newsletter iii2016
 
Ieee projects 2012 2013 - Mobile Computing
Ieee projects 2012 2013 - Mobile ComputingIeee projects 2012 2013 - Mobile Computing
Ieee projects 2012 2013 - Mobile Computing
 
2 cell smart power selector 1760fa 1
2 cell smart power selector 1760fa 12 cell smart power selector 1760fa 1
2 cell smart power selector 1760fa 1
 
Introduction to Free Software
Introduction to Free SoftwareIntroduction to Free Software
Introduction to Free Software
 
Lourdes Flores Y CéSar CatañO
Lourdes Flores Y CéSar CatañOLourdes Flores Y CéSar CatañO
Lourdes Flores Y CéSar CatañO
 
BüroWARE Oil - ERP-Software für den Energiehandel
BüroWARE Oil - ERP-Software für den EnergiehandelBüroWARE Oil - ERP-Software für den Energiehandel
BüroWARE Oil - ERP-Software für den Energiehandel
 
Nueva Carta de El Pote Restaurante
Nueva Carta de El Pote RestauranteNueva Carta de El Pote Restaurante
Nueva Carta de El Pote Restaurante
 
Zombis
ZombisZombis
Zombis
 
Content Marketing: Wie kann Ihr Business davon profitieren?
Content Marketing: Wie kann Ihr Business davon profitieren?Content Marketing: Wie kann Ihr Business davon profitieren?
Content Marketing: Wie kann Ihr Business davon profitieren?
 
"Как продавать Вену": вебинар Vitiana
"Как продавать Вену": вебинар Vitiana"Как продавать Вену": вебинар Vitiana
"Как продавать Вену": вебинар Vitiana
 
Sanjay Singh Nayal-CV
Sanjay Singh Nayal-CVSanjay Singh Nayal-CV
Sanjay Singh Nayal-CV
 
April 2015 group advisement
April 2015 group advisementApril 2015 group advisement
April 2015 group advisement
 
El pendo
El pendoEl pendo
El pendo
 
Itinerario político cultural de la españa actual-carlos pla barriol
Itinerario político cultural de la españa actual-carlos pla barriolItinerario político cultural de la españa actual-carlos pla barriol
Itinerario político cultural de la españa actual-carlos pla barriol
 
Hack x crack_scapy2
Hack x crack_scapy2Hack x crack_scapy2
Hack x crack_scapy2
 
Android tv market - March 2017 - analysis and commentary
Android tv market -  March 2017 - analysis and commentaryAndroid tv market -  March 2017 - analysis and commentary
Android tv market - March 2017 - analysis and commentary
 
Biografía del dr. alfonso millán maldonado (27/ago/2013)
Biografía del dr. alfonso millán maldonado (27/ago/2013)Biografía del dr. alfonso millán maldonado (27/ago/2013)
Biografía del dr. alfonso millán maldonado (27/ago/2013)
 
La Antorcha - Mayo 2012
La Antorcha - Mayo 2012La Antorcha - Mayo 2012
La Antorcha - Mayo 2012
 

Similar to Efficient development workflows with composer

Similar to Efficient development workflows with composer (20)

Introduction to Composer for Drupal
Introduction to Composer for DrupalIntroduction to Composer for Drupal
Introduction to Composer for Drupal
 
Composer JSON kills make files
Composer JSON kills make filesComposer JSON kills make files
Composer JSON kills make files
 
Composer Tools & Frameworks for Drupal
Composer Tools & Frameworks for DrupalComposer Tools & Frameworks for Drupal
Composer Tools & Frameworks for Drupal
 
Mono Repo
Mono RepoMono Repo
Mono Repo
 
Drupal 8 - Improving your development workflow
Drupal 8 - Improving your development workflowDrupal 8 - Improving your development workflow
Drupal 8 - Improving your development workflow
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practices
 
Composer tools and frameworks for Drupal
Composer tools and frameworks for DrupalComposer tools and frameworks for Drupal
Composer tools and frameworks for Drupal
 
Composer tools and frameworks for drupal.ppt
Composer tools and frameworks for drupal.pptComposer tools and frameworks for drupal.ppt
Composer tools and frameworks for drupal.ppt
 
Help! I inherited a Drupal Site! - DrupalCamp Atlanta 2016
Help! I inherited a Drupal Site! - DrupalCamp Atlanta 2016Help! I inherited a Drupal Site! - DrupalCamp Atlanta 2016
Help! I inherited a Drupal Site! - DrupalCamp Atlanta 2016
 
Configuration as Dependency: Managing Drupal 8 Configuration with git and Com...
Configuration as Dependency: Managing Drupal 8 Configuration with git and Com...Configuration as Dependency: Managing Drupal 8 Configuration with git and Com...
Configuration as Dependency: Managing Drupal 8 Configuration with git and Com...
 
Open source projects with python
Open source projects with pythonOpen source projects with python
Open source projects with python
 
My "Perfect" Toolchain Setup for Grails Projects
My "Perfect" Toolchain Setup for Grails ProjectsMy "Perfect" Toolchain Setup for Grails Projects
My "Perfect" Toolchain Setup for Grails Projects
 
Publican
PublicanPublican
Publican
 
Composer
ComposerComposer
Composer
 
ENIB 2015-2016 - CAI Web - S01E01- La forge JavaScript
ENIB 2015-2016 - CAI Web - S01E01- La forge JavaScriptENIB 2015-2016 - CAI Web - S01E01- La forge JavaScript
ENIB 2015-2016 - CAI Web - S01E01- La forge JavaScript
 
ENIB 2015 2016 - CAI Web S02E03- Forge JS 1/4 - La forge JavaScript
ENIB 2015 2016 - CAI Web S02E03- Forge JS 1/4 - La forge JavaScriptENIB 2015 2016 - CAI Web S02E03- Forge JS 1/4 - La forge JavaScript
ENIB 2015 2016 - CAI Web S02E03- Forge JS 1/4 - La forge JavaScript
 
Managing your Drupal project with Composer
Managing your Drupal project with ComposerManaging your Drupal project with Composer
Managing your Drupal project with Composer
 
Becoming A Drupal Master Builder
Becoming A Drupal Master BuilderBecoming A Drupal Master Builder
Becoming A Drupal Master Builder
 
Bgoug 2019.11 building free, open-source, plsql products in cloud
Bgoug 2019.11   building free, open-source, plsql products in cloudBgoug 2019.11   building free, open-source, plsql products in cloud
Bgoug 2019.11 building free, open-source, plsql products in cloud
 
How to plan and define your CI-CD pipeline
How to plan and define your CI-CD pipelineHow to plan and define your CI-CD pipeline
How to plan and define your CI-CD pipeline
 

Recently uploaded

Article writing on excessive use of internet.pptx
Article writing on excessive use of internet.pptxArticle writing on excessive use of internet.pptx
Article writing on excessive use of internet.pptx
abhinandnam9997
 
audience research (emma) 1.pptxkkkkkkkkkkkkkkkkk
audience research (emma) 1.pptxkkkkkkkkkkkkkkkkkaudience research (emma) 1.pptxkkkkkkkkkkkkkkkkk
audience research (emma) 1.pptxkkkkkkkkkkkkkkkkk
lolsDocherty
 
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
aagad
 

Recently uploaded (13)

Article writing on excessive use of internet.pptx
Article writing on excessive use of internet.pptxArticle writing on excessive use of internet.pptx
Article writing on excessive use of internet.pptx
 
ER(Entity Relationship) Diagram for online shopping - TAE
ER(Entity Relationship) Diagram for online shopping - TAEER(Entity Relationship) Diagram for online shopping - TAE
ER(Entity Relationship) Diagram for online shopping - TAE
 
Pvtaan Social media marketing proposal.pdf
Pvtaan Social media marketing proposal.pdfPvtaan Social media marketing proposal.pdf
Pvtaan Social media marketing proposal.pdf
 
The Best AI Powered Software - Intellivid AI Studio
The Best AI Powered Software - Intellivid AI StudioThe Best AI Powered Software - Intellivid AI Studio
The Best AI Powered Software - Intellivid AI Studio
 
audience research (emma) 1.pptxkkkkkkkkkkkkkkkkk
audience research (emma) 1.pptxkkkkkkkkkkkkkkkkkaudience research (emma) 1.pptxkkkkkkkkkkkkkkkkk
audience research (emma) 1.pptxkkkkkkkkkkkkkkkkk
 
How Do I Begin the Linksys Velop Setup Process?
How Do I Begin the Linksys Velop Setup Process?How Do I Begin the Linksys Velop Setup Process?
How Do I Begin the Linksys Velop Setup Process?
 
Case study on merger of Vodafone and Idea (VI).pptx
Case study on merger of Vodafone and Idea (VI).pptxCase study on merger of Vodafone and Idea (VI).pptx
Case study on merger of Vodafone and Idea (VI).pptx
 
The AI Powered Organization-Intro to AI-LAN.pdf
The AI Powered Organization-Intro to AI-LAN.pdfThe AI Powered Organization-Intro to AI-LAN.pdf
The AI Powered Organization-Intro to AI-LAN.pdf
 
The+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptxThe+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptx
 
The Use of AI in Indonesia Election 2024: A Case Study
The Use of AI in Indonesia Election 2024: A Case StudyThe Use of AI in Indonesia Election 2024: A Case Study
The Use of AI in Indonesia Election 2024: A Case Study
 
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
 
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and GuidelinesMulti-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
 
Bug Bounty Blueprint : A Beginner's Guide
Bug Bounty Blueprint : A Beginner's GuideBug Bounty Blueprint : A Beginner's Guide
Bug Bounty Blueprint : A Beginner's Guide
 

Efficient development workflows with composer