Composer is a great tool for managing a project's dependencies - however, as with many tools there are various ways to use it. That's why this session will provide you an overview of possible workflows and shows practical solutions for building and deploying composer-managed projects. It covers experiences with handling Drupal projects and focus on approaches that can be shared across projects and team members.
Topics:
- Introduction: What is composer and how to use it with Drupal
- Build & deployment workflows for composer-managed projects
- Composer & Drupal: Challenges & solutions
- Creating re-usable packages
3. 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
11. Using it in project
● Add composer .json
● Specify
● Add dependencies
"type": "project"
12. Using it in a project
git clone branch 8.1.x
https://git.drupal.org/project/
drupal.git
cd drupal
composer install
13. What happens?
● Reads composer.lock and
installs recorded versions
● Downloads code and puts it into
./vendor
(or somewhere else)
● Generates a class autoloader
14. Composer update & locks
● composer update
– Update all the dependencies and
write new lock file
● composer install
– Apply what's recorded in the lock file
15. Composer & VCS
● Commit composer.json
● For projects: Commit
composer.lock
● For libraries: Commit
composer.lock for tests
● Avoid commit vendor files
16. Versions & Composer
● Require versions like 2.1.*
● composer supports many different
version constraints
● Specify allowed versions, not
specific versions
20. Start a new d8 project
composer createproject
drupalcomposer/drupalproject
21. 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!
24. 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 && ...
37. Fork & add your fork
● Alternative to patch files
● Works great with the Github pull
request workflow
● composer createproject
drupal/module path 2.2.0
● Add in the fork instead upstream
38. Adding in your fork
"require": {
"samson/yt": "devBRANCH as 2.0.0"
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/fago/yt"
}
],
39. Keep builds fast
● composer fetches either „dist“ or
„source“ packages
● Prefer „dist“ packages for fast
builds & cache use!
● Pre-configured in drupal-project
45. Avoid committing vendors!
● Smaller diffs & pull requests
=> easy to review!
● Keeps repositories smaller (only
custom code)
● Work with vendor repositories
without submodules
46. 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
49. Build branches
● We keep them in the same
repository
● Enables possible future
enhancements
50. 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
51. phapp cli
● Tool for managing PHP
applications
● Not yet many commands besides
„phapp build“
● https://github.com/
drunomics/phappcli
52. 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
53. Deployment updates
● Apply changes after code update
● Do not rely on special server
environments!
→ More reliable deployments!
54. Deployment script tools
● composer scripts
● Robo
● Drush, Drupal console
Add dependencies to the project!
56. Why?
● Develop re-usable PHP libraries,
e.g. REST clients
● Feature modules for kick-starting
development
composer require
drunomics/dsk_media
57. 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
61. Handling libraries & assets
● Possible solutions:
– Add them via custom repostories
– composer scripts for running bower or
npm on project install
– fxp/composer-asset-plugin
– ...