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
who of you have used Drush?
How about Drush .make files then?
Dependencies in enabling models - because Drupal resolves them
incomplete = no dependency -consept
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.
$ ls -1
— now, where is my drupal?
It’s in vendor -folder! because… we installed it as a component for the project
https://packagist.org Packagist is the main Composer repository. It aggregates public PHP packages installable with Composer.
“^8.” <= no version specified, so use (and lock to) the latest minor release.
coolio can be omitted, too. Defaults to drupal-project.
Code hosted elsewhere == pretty much everything added by Composer.
Code hosted elsewhere (Drupal core, modules, libraries)
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.
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.
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.
Example code is modified version ofhttps://donatstudios.com/Require-a-Remote-Zip-File-with-Composer
Example code is modified version ofhttps://donatstudios.com/Require-a-Remote-Zip-File-with-Composer