Share
Embed
Git and composer workflows for Drupal 7 and Drupal 8
https://www.drupalcampbaltics.com/node/78
https://www.youtube.com/watch?v=uaxViOaiwCs&ab_channel=DrupalCampBaltics
João Ventura
November 02, 2018
Transcript
28 slides
-
João Ventura (@jcnventura) Wunder Germany git and composer workflows
for Drupal 7 / 8 Tallinn, November 2, 2018 -
Drush make is better than nothing. Composer is the best.
Summary • Drupal build systems • Drush make • Composer • git -
Drush make (http://docs.drush.org/en/7.x/make/) Part of drush versions 5 to 8
Two fl avours: ini or yaml (!) Site built with exact versions of: • Core • Projects (modules, themes) • Libraries Support for just-in-time patching. Support for git, svn, bzr, copy, etc downloads. drush make-generate project.make -
ini format (project.make) core = 7.x api = 2 defaults[projects][subdir]
= "contrib" projects[drupal][version] = "7.60" projects[token][version] = "1.7" projects[views][version] = "3.20" projects[views][patch][2885660] = "https://www.drupal.org/ fi les/issues/2018-06-28/2885660-13.patch" projects[zen][version] = "6.4" -
yaml format core: 7.x api: 2 defaults: projects: subdir: 'contrib'
projects: drupal: version: '7.60' token: version: '1.7' views: version: '3.20' patch: - 'https://www.drupal.org/ fi les/issues/2018-06-28/2885660-13.patch' zen: version: '6.4' -
Composer (https://getcomposer.org) Dependency manager for PHP Works well with semantic
versioning Package repositories: • https://packagist.org/ - default •https://packages.drupal.org/8 - Drupal 8 •https://packages.drupal.org/7 - Drupal 7 -
Semantic versioning (https://semver.org) x.y.z • x - major version •
lots of new features • not backwards compatible • y - minor version • some new features • backwards compatible • z - patch version • bug fi xes only Drupal core: 8.6.2 -
Composer version syntax • Exact: 1.2.3 • Range i: >=1.0
<1.1 || >=1.2 • Range ii: 1.0 - 2.0 (i.e. >=1.0.0 <2.1) • Wildcard: 1.0.* (i.e. >=1.0 <1.1) • Tilde: • ~1.2 (i.e. >=1.2 <2.0.0) • ~1.2.3 (i.e. >=1.2.3 <1.3.0) • Caret: • ^1.2 (i.e. >=1.2 <2.0.0) • ^1.2.3 (i.e. >=1.2.3 <2.0.0) -
drupal-project (https://github.com/drupal-composer/drupal-project) Composer template for D7 or D8 sites Provides:
•Drupal packages.drupal.org •Directory installers (web/modules/contrib, etc.) •Patches •Drush, etc. •Some scaffold -
drupal-project for Drupal 7 Location of Drupal 7 packages Drupal
7 PHP extensions requirements Composer patches library + patch to preserve-paths Composer preserve paths library (to preserve sites/all/*) -> in case anything happens your fi les are in ~/.composer/cache/preserve-paths/ Correct installer paths con fi guration Correct preserve-paths con fi guration -
Create a project Drupal 8: composer create-project drupal-composer/drupal-project:8.x-dev some-dir --
stability dev --no-interaction Drupal 7: composer create-project drupal-composer/drupal-project:7.x-dev some-dir -- stability dev --no-interaction Word of caution: "con fi g": { "platform": {"php": "5.5.9"} }, -
Workflow • First time, or major update: composer update •
During deployment: composer install • Add new modules (do not manually edit composer.json) composer require drupal/project “^1.0” --update-with-dependencies • Finally commit BOTH composer.json and composer.lock -
composer format "repositories": [ { "type": "composer", "url": "https://packages.drupal.org/7" }
], "require": { "composer/installers": "^1.2", "cweagans/composer-patches": "^1.6", "drupal-composer/preserve-paths": "^0.1", "drupal/drupal": "^7.60", "drupal/token": "^1.7", "drupal/views": "^3.20", "drupal/zen": "^6.4", "drush/drush": "~8.0" }, -
Convert a makefile to composer drush make-convert make fi le
--format=composer > composer.json Does not convert libraries. See the README.md of drupal-project/7.x on how to con fi gure. Some post-convert enhancements (from d-p/7.x composer.json): • Add scaffolding (autoload and scripts section), and the following requires: composer/semver, drupal/composer_autoloader, symfony/ fi lesystem web fl o/drupal- fi nder. • Add the patch to cweagans/composer-patches -
.gitignore # Ignore directories generated by Composer /vendor/ /web/sites/all/drush/ /web/sites/all/modules/contrib/
/web/sites/all/themes/contrib/ /web/sites/all/libraries/ # Ignore Drupal 7 core fi les. /web/* !/web/*/ /web/includes/ # Ignore con fi guration fi les that may contain sensitive information. /web/sites/*/*.settings.php /web/sites/*/settings*.php # Ignore paths that contain user-generated content. /web/sites/*/ fi les /web/sites/*/private -
git workflow • master/prod: live site • develop/stage: staging site
• Pull requests / merge to master, on release • feature/ticket#-desc: ticket branches • checkout -b from stage • Pull requests / merge after peer review https://nvie.com/posts/a-successful-git-branching-model/ -
git + composer • DO • con fi gure .gitignore
• commit composer.json AND composer.lock • use semantic versions • use composer as a development tool • DON’T • run “composer update” naked, unless you plan to test everything that is updated • commit /vendor nor any 3rd party code (from drupal.org or libraries) • use composer as a deployment tool -
^composer update$ • Running composer update alone will update every
dependency. • Are you ready to test the entire functionality affected by all the modules? • However: don’t fall behind. Update everything and retest site completely, from time to time. -
Lean repos • your development team uses git • Pull
requests should just be the changes your team made • Pull requests should not include the past 6 months of changes to Drupal core, Symfony, etc. • Do not use git for deployment. • Trust the Internet availability. -
git workflow • Create feature branch: git checkout -b feature/TKT-42-answer-life
• Do the work • Rebase to latest version of parent branch git rebase branch • Export con fi g drush cex • Check changes git diff • Add fi les and commit git add fi le1 … fi len ; git commit -m “TKT-42: 6 times 9 in base 13” • Create pull request in github/gitlab/bitbucket • Merge the feature branch