Slide 1

Slide 1 text

drupalcampbaltics.com

Slide 2

Slide 2 text

João Ventura (@jcnventura) Wunder Germany 
 git and composer workflows for Drupal 7 / 8 Tallinn, November 2, 2018

Slide 3

Slide 3 text

THANKS!

Slide 4

Slide 4 text

THANKS!

Slide 5

Slide 5 text

Drush make is better than nothing. Composer is the best. Summary • Drupal build systems • Drush make • Composer • git

Slide 6

Slide 6 text

Drupal build systems Tallinn, November 2, 2018

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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"

Slide 9

Slide 9 text

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'

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

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)

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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"} },

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

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" },

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

.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

Slide 20

Slide 20 text

“Anything that can go wrong will go wrong” - Murfy’s law

Slide 21

Slide 21 text

git best-practices Tallinn, November 2, 2018

Slide 22

Slide 22 text

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/

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

^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.

Slide 25

Slide 25 text

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.

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

Senior Developer Of fi ce: +49.89.85636307 [email protected] João Ventura (jcnventura) $> who am i

Slide 28

Slide 28 text

Thank you.