SlideShare a Scribd company logo
Composer JSON kills
make files
DrupalCamp Baltics 2017
• Perttu Ehn
https://www.drupal.org/u/rpsu
@ropsue
• Competence manager at Exove Ltd www.exove.com
• 11 years of Drupal, contrib module maintainer
• Motto:
Q: Can this be done?
A: Yes. Most certainly. It’s just a matter of the size of your
budget and available timeframe.
Very briefly about me
Drush .make files are great. Really.
Composer.json keeps track of and
updates your codebase easier.
Topics
• Drush Recap
• Composer
• Workflow with the Composer
• Recipes
•Semantic versioning
Drush recap
• Drush is a command line shell and Unix scripting interface for
Drupal. 1)
• Can build the codebase based on the recipe (.make-file)
$ drush make project.make
• Can download and enable modules, themes from drupal.org
$ drush dl regcode_simple
$ drush en regcode_simple
• Set variables, reset passwords, rebuild or revert features…
$ drush uli admin
• Hooks for custom commands to do practically anything with Drupal
1) www.drush.org
Drush recap
• Drush .make file is a fixed yet incomplete recipe for
the codebase
• Drush .make file must be manually maintained
• Drush does not have a concept of “dependency” for
code downloads
• Composer is a tool for dependency management in
PHP
• Dependency manager, per project, within a project
• Node: npm
• Ruby: bundler
Composer
• Composer does everything with the codebase Drush
does, but better
• Composer Does not touch Drupal
.. however, Drupal console does
• Composer may be installed globally or per project 1)
• Composer == composer.phar -file, “Php ARchive”
Composer
1) https://getcomposer.org/doc/00-intro.md#installation-linux-unix-osx
• Set up a project repository
• Add component in project root
$ composer require drupal/drupal
Basics
$ composer require drupal/drupal
Using version ^8.4 for drupal/drupal
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 3 installs, 0 updates, 0 removals
- Installing wikimedia/composer-merge-plugin
(v1.4.1): Downloading (100%)
- Installing composer/installers (v1.4.0):
Downloading (100%)
- Installing drupal/drupal (8.4.0): Downloading
(100%)
Writing lock file
Generating autoload files
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating autoload files
composer.json
composer.lock
vendor/autoload.php
vendor/composer/
vendor/drupal/
vendor/wikimedia/
vendor/drupal/drupal/index.php
• Dependencies were resolved and downloaded?
=> Write composer.lock
• Something odd happened?
=> Revert the already made changes in
composer.json
Double or nothing
{
"require": {
"drupal/drupal": "^8.4"
}
}
Drupal: composer.json
• 258 lines of json-code
• Specifies the exact version of Drupal 8 (8.4.0)
• Dependencies listed and specified in detail, too
• With composer.lock -file the whole codebase can be
rebuilt to the last bit
• Loose constraints do not affect the reproducibility of
the codebase
composer.lock
• Use Composer template for Drupal
$ composer create-project drupal-
composer/drupal-project:8.x-dev coolio --
stability dev --no-interaction --prefer-dist
• It comes with steroids!
Workflow
• Use Composer template for Drupal
$ composer create-project drupal-
composer/drupal-project:8.x-dev coolio --
stability dev --no-interaction --prefer-dist
• create-project creates a new project from an
existing project (think git clone)
Workflow
• Use Composer template for Drupal
$ composer create-project drupal-
composer/drupal-project:8.x-dev coolio --
stability dev --no-interaction --prefer-dist
• Use Composer template for Drupal as the base
• 8.x project version (relates to the Drupal core
version)
• -dev use dev -version, ie. a git commit (latest one
in this case)
Workflow
• Use Composer template for Drupal
$ composer create-project drupal-
composer/drupal-project:8.x-dev coolio --
stability dev --no-interaction --prefer-dist
• coolio is the directory where the project will be
created
• composer.json and composer.lock files will be
there
Workflow
• Use Composer template for Drupal
$ composer create-project drupal-
composer/drupal-project:8.x-dev coolio --
stability dev --no-interaction --prefer-dist
• --stability dev Minimum stability of package
• --no-interaction Do not ask any interactive
question
Workflow
• Use Composer template for Drupal
$ composer create-project drupal-
composer/drupal-project:8.x-dev coolio --
stability dev --no-interaction --prefer-dist
• --prefer-dist Prefer distributions over source,
ie. use vendor zip/gzip/tar/whatever if found. Faster.
Workflow
• Web root is in
coolio/web
• All libraries are protected from direct access
coolio/vendor/*
• vendor code rarely needs to be accessible directly from
the world
• index.php
• core/update.php (well...)
Folder structure
• Download module
$ drush dl regcode_simple-8.1
• Add requirement manually to the .make -file
• Remove unnecessary code manually
Recipes
Get some modules (.make, .make.yml)
$ composer require drupal/ctools
$ composer require drupal/commerce:2.0-beta3
• List the modules you have with Drupal:
$ composer show drupal/*
• Remove affects composer.json and the codebase, too
$ composer remove drupal/ctools
Recipes
Get some modules (composer)
zsh requires quoted parameter when it contains an asterisk: $ composer show "drupal/*"
• Commit composer.json and composer.lock -files to
Git
• Don’t commit (.gitignore): vendor/*
What should I commit?
1. Clone project repository.
2. Run composer install
• Composer reads composer.lock -file
• Composer retrieves all the required dependencies
• Composer generates autoloader
3. That’s it!
(+ additional vagrant up or Docker magix)
Team mates up-to-date?
• Run composer update to get the latest versions
available (within constraints!)
• Updates code
• Write updates to composer.lock -file
• Change version (constraints)
$ composer require drupal/commerce:2.*
zsh requires quoted parameter when it contains an asterisk: $ composer show "drupal/*"
Update module versions?
• Three digits; 1.2.3
• 1st changes might be backwards incompatible (major
release)
• API removals, API changes
• 2nd changes with API additions, new features (minor
release)
• 3rd changes with bug fixes (patch releaser)
Semantic versioning
Range
• Comparison operators, specified range of allowed
versions
>=1.0
>=1.0 <2.0
>=1.0 <1.1 || >=1.2
1.0 - 2.0
Wildcard
• * is a wildcard: 1.0.* is the
equivalent of >=1.0 <1.1
https://getcomposer.org/doc/articles/versions.md
Constraints
Tilde
• ~ specifies a minimum version, but allows the last
digit specified to go up:
”~1.2” is equal to ”>= 1.2 < 2.*”
Caret
• ^ sticks closer to semantic versioning; sub-major
version updates should not break anything: ”^1.2.3”
is equivalent to ”>=1.2.3 <2.0.0”
https://getcomposer.org/doc/articles/versions.md
Constraints
Take also look at these
• Composer template for Drupal projects
https://github.com/drupal-composer/drupal-project
• Improving your Drupal 8 development workflow
by Jesus Manuel Olivas
http://weknowinc.com/talks/2016/drupalgov-workflow
• Drupal Console Docs
https://drupalconsole.com/docs
Time for questions!
• Drush Recap
• Composer
• Workflow with the Composer
• Recipes
•Semantic versioning
Thank you!

More Related Content

PDF
Git 101: Git and GitHub for Beginners
PDF
Building a Drupal site with Git
PDF
Ansible project-deploy
PDF
Using Capifony for Symfony apps deployment (updated)
PPTX
Introduction to dockerfile, SF Peninsula Software Development Meetup @Guidewire
PDF
Drush in the Composer Era
PDF
Tp install anything
PDF
CIbox - OpenSource solution for making your #devops better
Git 101: Git and GitHub for Beginners
Building a Drupal site with Git
Ansible project-deploy
Using Capifony for Symfony apps deployment (updated)
Introduction to dockerfile, SF Peninsula Software Development Meetup @Guidewire
Drush in the Composer Era
Tp install anything
CIbox - OpenSource solution for making your #devops better

What's hot (20)

PDF
Automating & Integrating Pantheon with JIRA, Slack, Jenkins and More
PDF
Developing and Deploying PHP with Docker
PDF
Drupal contrib module maintaining
PDF
IBM Drupal Users Group Discussion on Managing and Deploying Configuration
PDF
Composer Tools & Frameworks for Drupal
PDF
DrupalCon Los Angeles - Continuous Integration Toolbox
PDF
Dockercon EU 2014
PDF
Использование Docker в CI / Александр Акбашев (HERE Technologies)
PDF
Puppeteerのお話
PDF
Scalable Cloud-Native Masterless Puppet, with PuppetDB and Bolt, Craig Watson...
PDF
Getting Started with Docker
KEY
Perlbrew
PDF
Live deployment, ci, drupal
PDF
Let's go HTTPS-only! - More Than Buying a Certificate
PDF
Drupal 8 DevOps . Profile and SQL flows.
PDF
CI : the first_step: Auto Testing with CircleCI - (MOSG)
PPTX
MoldCamp - multidimentional testing workflow. CIBox.
PDF
Docker at Djangocon 2013 | Talk by Ken Cochrane
PDF
Integrate Openshift with Cloudforms
PPTX
Django via Docker
Automating & Integrating Pantheon with JIRA, Slack, Jenkins and More
Developing and Deploying PHP with Docker
Drupal contrib module maintaining
IBM Drupal Users Group Discussion on Managing and Deploying Configuration
Composer Tools & Frameworks for Drupal
DrupalCon Los Angeles - Continuous Integration Toolbox
Dockercon EU 2014
Использование Docker в CI / Александр Акбашев (HERE Technologies)
Puppeteerのお話
Scalable Cloud-Native Masterless Puppet, with PuppetDB and Bolt, Craig Watson...
Getting Started with Docker
Perlbrew
Live deployment, ci, drupal
Let's go HTTPS-only! - More Than Buying a Certificate
Drupal 8 DevOps . Profile and SQL flows.
CI : the first_step: Auto Testing with CircleCI - (MOSG)
MoldCamp - multidimentional testing workflow. CIBox.
Docker at Djangocon 2013 | Talk by Ken Cochrane
Integrate Openshift with Cloudforms
Django via Docker
Ad

Similar to Composer JSON kills make files (20)

PDF
Composer is the new Drush - Drupal Developer Training (internal)
PPTX
Exploring composer in drupal 8 with drupal project - salva molina
PDF
Composer & Drupal
PDF
Stop making, start composing - Using Composer for Drupal development
PDF
Drupal + composer = new love !?
PDF
Introduction to Composer for Drupal
PDF
Efficient development workflows with composer
PDF
Composer yourself: a reintroduction to composer
PPTX
Managing your Drupal project with Composer
PDF
Efficient development workflows with composer
PDF
Dependency management with Composer
PDF
Leveraging Composer in Existing Projects
PPTX
Composer
PDF
Using Composer with Drupal and Drush
PPTX
Composer
PDF
Composer and deployer for enterprise
PDF
Composer & Deployer for enterprise - Oleksii Kalinichenko
PDF
Lean Drupal Repositories with Composer and Drush
PDF
Beginning with Composer - Dependency manager in php
PPTX
Nh php may 2014 - composer
Composer is the new Drush - Drupal Developer Training (internal)
Exploring composer in drupal 8 with drupal project - salva molina
Composer & Drupal
Stop making, start composing - Using Composer for Drupal development
Drupal + composer = new love !?
Introduction to Composer for Drupal
Efficient development workflows with composer
Composer yourself: a reintroduction to composer
Managing your Drupal project with Composer
Efficient development workflows with composer
Dependency management with Composer
Leveraging Composer in Existing Projects
Composer
Using Composer with Drupal and Drush
Composer
Composer and deployer for enterprise
Composer & Deployer for enterprise - Oleksii Kalinichenko
Lean Drupal Repositories with Composer and Drush
Beginning with Composer - Dependency manager in php
Nh php may 2014 - composer
Ad

Recently uploaded (20)

PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
NewMind AI Monthly Chronicles - July 2025
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Electronic commerce courselecture one. Pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPT
Teaching material agriculture food technology
PDF
Empathic Computing: Creating Shared Understanding
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PPTX
Understanding_Digital_Forensics_Presentation.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPTX
MYSQL Presentation for SQL database connectivity
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Unlocking AI with Model Context Protocol (MCP)
Per capita expenditure prediction using model stacking based on satellite ima...
Review of recent advances in non-invasive hemoglobin estimation
NewMind AI Monthly Chronicles - July 2025
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Electronic commerce courselecture one. Pdf
Chapter 3 Spatial Domain Image Processing.pdf
Teaching material agriculture food technology
Empathic Computing: Creating Shared Understanding
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Understanding_Digital_Forensics_Presentation.pptx
The AUB Centre for AI in Media Proposal.docx
The Rise and Fall of 3GPP – Time for a Sabbatical?
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
MYSQL Presentation for SQL database connectivity
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Advanced methodologies resolving dimensionality complications for autism neur...
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Unlocking AI with Model Context Protocol (MCP)

Composer JSON kills make files

  • 1. Composer JSON kills make files DrupalCamp Baltics 2017
  • 2. • Perttu Ehn https://www.drupal.org/u/rpsu @ropsue • Competence manager at Exove Ltd www.exove.com • 11 years of Drupal, contrib module maintainer • Motto: Q: Can this be done? A: Yes. Most certainly. It’s just a matter of the size of your budget and available timeframe. Very briefly about me
  • 3. Drush .make files are great. Really. Composer.json keeps track of and updates your codebase easier.
  • 4. Topics • Drush Recap • Composer • Workflow with the Composer • Recipes •Semantic versioning
  • 5. Drush recap • Drush is a command line shell and Unix scripting interface for Drupal. 1) • Can build the codebase based on the recipe (.make-file) $ drush make project.make • Can download and enable modules, themes from drupal.org $ drush dl regcode_simple $ drush en regcode_simple • Set variables, reset passwords, rebuild or revert features… $ drush uli admin • Hooks for custom commands to do practically anything with Drupal 1) www.drush.org
  • 6. Drush recap • Drush .make file is a fixed yet incomplete recipe for the codebase • Drush .make file must be manually maintained • Drush does not have a concept of “dependency” for code downloads
  • 7. • Composer is a tool for dependency management in PHP • Dependency manager, per project, within a project • Node: npm • Ruby: bundler Composer
  • 8. • Composer does everything with the codebase Drush does, but better • Composer Does not touch Drupal .. however, Drupal console does • Composer may be installed globally or per project 1) • Composer == composer.phar -file, “Php ARchive” Composer 1) https://getcomposer.org/doc/00-intro.md#installation-linux-unix-osx
  • 9. • Set up a project repository • Add component in project root $ composer require drupal/drupal Basics
  • 10. $ composer require drupal/drupal Using version ^8.4 for drupal/drupal ./composer.json has been created Loading composer repositories with package information Updating dependencies (including require-dev) Package operations: 3 installs, 0 updates, 0 removals - Installing wikimedia/composer-merge-plugin (v1.4.1): Downloading (100%) - Installing composer/installers (v1.4.0): Downloading (100%) - Installing drupal/drupal (8.4.0): Downloading (100%) Writing lock file Generating autoload files Loading composer repositories with package information Updating dependencies (including require-dev) Nothing to install or update Generating autoload files
  • 12. • Dependencies were resolved and downloaded? => Write composer.lock • Something odd happened? => Revert the already made changes in composer.json Double or nothing
  • 14. • 258 lines of json-code • Specifies the exact version of Drupal 8 (8.4.0) • Dependencies listed and specified in detail, too • With composer.lock -file the whole codebase can be rebuilt to the last bit • Loose constraints do not affect the reproducibility of the codebase composer.lock
  • 15. • Use Composer template for Drupal $ composer create-project drupal- composer/drupal-project:8.x-dev coolio -- stability dev --no-interaction --prefer-dist • It comes with steroids! Workflow
  • 16. • Use Composer template for Drupal $ composer create-project drupal- composer/drupal-project:8.x-dev coolio -- stability dev --no-interaction --prefer-dist • create-project creates a new project from an existing project (think git clone) Workflow
  • 17. • Use Composer template for Drupal $ composer create-project drupal- composer/drupal-project:8.x-dev coolio -- stability dev --no-interaction --prefer-dist • Use Composer template for Drupal as the base • 8.x project version (relates to the Drupal core version) • -dev use dev -version, ie. a git commit (latest one in this case) Workflow
  • 18. • Use Composer template for Drupal $ composer create-project drupal- composer/drupal-project:8.x-dev coolio -- stability dev --no-interaction --prefer-dist • coolio is the directory where the project will be created • composer.json and composer.lock files will be there Workflow
  • 19. • Use Composer template for Drupal $ composer create-project drupal- composer/drupal-project:8.x-dev coolio -- stability dev --no-interaction --prefer-dist • --stability dev Minimum stability of package • --no-interaction Do not ask any interactive question Workflow
  • 20. • Use Composer template for Drupal $ composer create-project drupal- composer/drupal-project:8.x-dev coolio -- stability dev --no-interaction --prefer-dist • --prefer-dist Prefer distributions over source, ie. use vendor zip/gzip/tar/whatever if found. Faster. Workflow
  • 21. • Web root is in coolio/web • All libraries are protected from direct access coolio/vendor/* • vendor code rarely needs to be accessible directly from the world • index.php • core/update.php (well...) Folder structure
  • 22. • Download module $ drush dl regcode_simple-8.1 • Add requirement manually to the .make -file • Remove unnecessary code manually Recipes Get some modules (.make, .make.yml)
  • 23. $ composer require drupal/ctools $ composer require drupal/commerce:2.0-beta3 • List the modules you have with Drupal: $ composer show drupal/* • Remove affects composer.json and the codebase, too $ composer remove drupal/ctools Recipes Get some modules (composer) zsh requires quoted parameter when it contains an asterisk: $ composer show "drupal/*"
  • 24. • Commit composer.json and composer.lock -files to Git • Don’t commit (.gitignore): vendor/* What should I commit?
  • 25. 1. Clone project repository. 2. Run composer install • Composer reads composer.lock -file • Composer retrieves all the required dependencies • Composer generates autoloader 3. That’s it! (+ additional vagrant up or Docker magix) Team mates up-to-date?
  • 26. • Run composer update to get the latest versions available (within constraints!) • Updates code • Write updates to composer.lock -file • Change version (constraints) $ composer require drupal/commerce:2.* zsh requires quoted parameter when it contains an asterisk: $ composer show "drupal/*" Update module versions?
  • 27. • Three digits; 1.2.3 • 1st changes might be backwards incompatible (major release) • API removals, API changes • 2nd changes with API additions, new features (minor release) • 3rd changes with bug fixes (patch releaser) Semantic versioning
  • 28. Range • Comparison operators, specified range of allowed versions >=1.0 >=1.0 <2.0 >=1.0 <1.1 || >=1.2 1.0 - 2.0 Wildcard • * is a wildcard: 1.0.* is the equivalent of >=1.0 <1.1 https://getcomposer.org/doc/articles/versions.md Constraints
  • 29. Tilde • ~ specifies a minimum version, but allows the last digit specified to go up: ”~1.2” is equal to ”>= 1.2 < 2.*” Caret • ^ sticks closer to semantic versioning; sub-major version updates should not break anything: ”^1.2.3” is equivalent to ”>=1.2.3 <2.0.0” https://getcomposer.org/doc/articles/versions.md Constraints
  • 30. Take also look at these • Composer template for Drupal projects https://github.com/drupal-composer/drupal-project • Improving your Drupal 8 development workflow by Jesus Manuel Olivas http://weknowinc.com/talks/2016/drupalgov-workflow • Drupal Console Docs https://drupalconsole.com/docs
  • 31. Time for questions! • Drush Recap • Composer • Workflow with the Composer • Recipes •Semantic versioning

Editor's Notes

  • #3: Started as Product owner!
  • #6: who of you have used Drush? How about Drush .make files then?
  • #7: Dependencies in enabling models - because Drupal resolves them incomplete = no dependency -consept
  • #10: The require command adds new packages to the composer.json file from the current directory. If no file exists one will be created on the fly.
  • #12: $ ls -1 — now, where is my drupal? It’s in vendor -folder! because… we installed it as a component for the project
  • #13: https://packagist.org Packagist is the main Composer repository. It aggregates public PHP packages installable with Composer.
  • #15: “^8.” <= no version specified, so use (and lock to) the latest minor release.
  • #20: coolio can be omitted, too. Defaults to drupal-project.
  • #27: Code hosted elsewhere == pretty much everything added by Composer. Code hosted elsewhere (Drupal core, modules, libraries)
  • #33: Note: The ~ operator has an exception on its behavior for the major release number. This means for example that ~1 is the same as ~1.0 as it will not allow the major number to increase trying to keep backwards compatibility.
  • #34: Note: The ~ operator has an exception on its behavior for the major release number. This means for example that ~1 is the same as ~1.0 as it will not allow the major number to increase trying to keep backwards compatibility.
  • #37: Problem: -> Found and fixed a bug in a contrib module, and now you need to use your fixes (a patch file) from drupal.org? No prob. -> Perhaps you were lazy and never uploaded the patch? No prob either.
  • #42: Example code is modified version of https://donatstudios.com/Require-a-Remote-Zip-File-with-Composer
  • #43: Example code is modified version of https://donatstudios.com/Require-a-Remote-Zip-File-with-Composer
  • #46: default profile: standard
  • #49: example.com == target to sites/example.com folder