Download presentation
Presentation is loading. Please wait.
1
Composer Workflows for Drupal 8
2
Composer Workflows for Drupal 8
Kevin Moll Appnovation Technologies Sr. Developer kmoll @kevinjmoll Introduction:
3
Composer Workflows for Drupal 8
Pablo Fabregat Appnovation Technologies Automation Engineer pmatias @darth_pablitt Introduction:
4
What we’ll cover today What is Composer Composer commands
What are packages Where are packages What do we do with private packages Plugins and useful enhancements for Composer How we work this into our automated build process
5
Dependency Management in Drupal
6
History Manually install dependencies Drush commands Drush Make
8
Composer
9
Installation
10
What is Composer?
11
“Composer is a tool for dependency management in PHP
“Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you” - Composer Documentation
12
Packages
13
What is a Package?
15
Packages namespace name composer.json file
16
{ "name": "symfony/yaml", "type": "library", "description": "Symfony Yaml Component", "keywords": [], "homepage": " "license": "MIT", "authors": [ "name": "Fabien Potencier", " ": }, "name": "Symfony Community", "homepage": " } ], "require": { "php": ">=5.3.9" }, "autoload": { "psr-4": { "Symfony\\Component\\Yaml\\": "" }, "exclude-from-classmap": [ "/Tests/" ] "minimum-stability": "dev", "extra": { "branch-alias": { "dev-master": "2.8-dev" }
17
Defining Dependencies
18
Repositories composer require [namespace]/[package]:[version]
19
Packagist
20
Packagist PHP Package Repository
This is the default composer repository Best place to put packages you wish to share
21
Repositories
22
Repositories composer config [options] [setting-key] [setting-value1] ... [setting-valueN]
23
Repositories composer config repositories.hello-universe vcs
24
Drupal Packagist
25
Drupal.org packages endpoint
26
Toran Proxy
27
Toran Proxy Packagist proxy Install on your own servers
Add packages not available to public Acts as a redundant backup
28
Packagist Github Toran Drupal Packagist
29
Semantic Versioning
30
major.minor.patch
31
Semver Allows versions to give developers more information
Major version: Backwards capability breaking Minor version: Feature Updates (non-BC breaking) Patch version: Bug fixes
32
Defining versions in Composer
33
Version Constraints Exact Example: 1.0.2
34
Version Constraints >=1.0 >= 1.0 < 2.0
Range >=1.0 >= 1.0 < 2.0 (This is inclusive) Equivalent to >=1.0.0 <=2.0.0
35
Version Constraints 1.2.* Equivalent to >=1.2.0 <1.3 1.*
Wildcard 1.2.* Equivalent to >=1.2.0 <1.3 1.* Equivalent to >=1.0.0 <2.0
36
Version Constraints Wildcard * Any and all versions
37
Do not do this! Do not do this! Do not do this!
38
Next Significant Release Operators
Version Constraints Next Significant Release Operators Tilde: Only last specified number can change ~1.2.3 Equivalent to >=1.2.3 <1.3.0 ~1.3 Equivalent to >=1.3.0 <2.0
39
Next Significant Release Operators
Version Constraints Next Significant Release Operators Caret: Similar to Tilde but will always allow non-breaking versions ^1.2.3 Equivalent to >=1.2.3 <2.0.0 ^1.2 Equivalent to >=1.2.0 <2.0.0
40
Version Constraints Defaults to dev Can specify --stable
Stability Defaults to dev Can specify --stable Can specify --dev Default can be listed in composer.json or on command line with ‘minimum-stability’ Can be overridden by each package when specifying the version
41
"require": { "php": ">=5.5.9", "symfony/class-loader": "~2.8", "symfony/console": "~2.8", "symfony/dependency-injection": "~2.8", "symfony/event-dispatcher": "~2.8", "symfony/http-foundation": "~2.8", "symfony/http-kernel": "~2.8", "symfony/routing": "~2.8", "symfony/serializer": "~2.8", "symfony/translation": "~2.8", "symfony/validator": "~2.8", "symfony/process": "~2.8", "symfony/polyfill-iconv": "~1.0", "symfony/yaml": "~2.8", "twig/twig": "^1.23.1", "doctrine/common": "2.5.*", "doctrine/annotations": "1.2.*", "guzzlehttp/guzzle": "^6.2.1", […] }
42
Install vs. Update
43
Install vs. Update Install should be considered install/sync.
Will look at composer.lock file first If version specified there, it will download that exact versions Will ignore composer.json if entry exists in composer.lock In the absence of composer.lock or an entry in composer.lock will act as update
44
Install vs. Update Update Should be considered, get latest based on what I specify in composer.json. Will look at composer.json file first If version specified there, it will download latest version that matches what you define Will update composer.lock with the downloaded version If no composer.lock, it will be create.
46
Create - Project
47
Create - Project This is the equivalent of git clone then composer install
48
Create - Project composer create-project laravel/laravel your-project-name 4.2.*
49
Lets Recap We know how to use composer to manage dependencies
We know how to create/list these dependencies We know how to install them We know where they are located We know how to add our custom code We know how to define our dependency versions We know what commands to run and when
50
Composer and Drupal 8
51
Let’s install Drupal!!
52
Drupal Composer Project
53
Composer installers
54
drupal-composer/drupal-project
"extra": { "installer-paths": { "web/core": ["type:drupal-core"], "web/modules/contrib/{$name}": ["type:drupal-module"], "web/profiles/contrib/{$name}": ["type:drupal-profile"], "web/themes/contrib/{$name}": ["type:drupal-theme"], "drush/contrib/{$name}": ["type:drupal-drush"] }, "patches": {}, "branch-alias": {} }
55
Composer installers Plugin for Composer
Allows a package type to be mapped to an install path
56
Custom installers Plugin for composer to define your own types and paths Can create type: kmoll-module Then can map that to an install path
57
Drupal Scaffold
58
Drupal Scaffold Plugin that will download scaffold files when using drupal/core Will build out the rest of the Drupal and Webroot structure
59
drupal-composer/drupal-project
"scripts": { "drupal-scaffold": "DrupalComposer\\DrupalScaffold\\Plugin::scaffold", "post-install-cmd": [ "DrupalProject\\composer\\ScriptHandler::buildScaffold", "DrupalProject\\composer\\ScriptHandler::createRequiredFiles" ], "post-update-cmd": [ ] },
61
A Quick Example
62
The Big Picture * Mention Tuesday’s session Ride the Whale
63
Creating a site from scratch
64
Initialise Create the “placeholder" repository with some hooks and composer.json Install composer hirak/Prestissimo FTW Run composer Do some cleanup Push to Github Create the “placeholder" repository with some hooks and a very basic composer.json to say hi to Toran and integrate with Travis Install composer install the amazing hirak/Prestissimo FTW Do some cleanup like removing any extra generated files Push to Github
65
Let’s create a new project! Do not ask any interactive question
Minimum-stability allowed We want any 1.0 version below 2.0 composer create-project --no-interaction --stability dev org/repo:~1 /path/to/project
66
Go Acquia We clone our Acquia repository
Generate the settings.php file Generate some extra files We clone our Acquia repository Generate the settings.php file Generate some extra files like .gitignore and rules for .htaccess (btw we generate those files via python jinja2 templates)
67
Sync! We push all these new changes to Acquia
68
drush site-install Everything is on Acquia now, Install drupal 8!
69
That’s nice, I want my D8 config
All the yml files are going to be stored under the config dir Mention configuration management: Theory and practice session by Andrea Pescetti, Fabian Bircher and Antonio de Marco
70
Propagate! Via acquia api calls, we propagate the code and db to the other environments
71
Recap We created the repository We initialized it
We ran composer create-project We sync’d the changes to Acquia We ran our drush site-install command We exported our config We replicated the code
73
Deploying Changes
74
Behind the scenes We cloned both Github and Acquia
Installed Prestissimo Ran Composer Install Sync’d Imported D8 Config Drush cache-rebuild
75
Q&A
76
JOIN US FOR CONTRIBUTION SPRINTS
First Time Sprinter Workshop - 9:00-12:00 - Room Wicklow2A Mentored Core Sprint - 9:00-18:00 - Wicklow Hall 2B General Sprints - 9: :00 - Wicklow Hall 2A
77
events.drupal.org/dublin2016/schedule
WHAT DID YOU THINK? Evaluate This Session events.drupal.org/dublin2016/schedule THANK YOU!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.