Transcript
Page 1: Trunk based development

Trunk Based DevelopmentTrunk Based DevelopmentDutch PHP ConferenceDutch PHP Conference

2014-06-282014-06-28

Page 2: Trunk based development

Gordon OheimGordon OheimSenior Craftsman, PHP Documentor, Senior Craftsman, PHP Documentor, Stack Overflow Contributor & Moderator, Stack Overflow Contributor & Moderator, AgilistAgilist

→ → http://twitter.com/go_ohhttp://twitter.com/go_oh → → http://about.me/goohhttp://about.me/gooh → → [email protected]@php.net

Page 3: Trunk based development
Page 4: Trunk based development
Page 5: Trunk based development
Page 6: Trunk based development

Before we start …Before we start …

Page 7: Trunk based development

x

Page 8: Trunk based development

Six months ago …Six months ago …

Page 9: Trunk based development

AdvantagesAdvantages

● Easy to understand when used properlyEasy to understand when used properly● Branches document Sprints/FeaturesBranches document Sprints/Features● Isolated development cannot break master Isolated development cannot break master

branchbranch

Page 10: Trunk based development

ProblemsProblems

● assumes Sprints end as plannedassumes Sprints end as planned● rogue branches might be impossible to mergerogue branches might be impossible to merge● requires more communication about what was requires more communication about what was

merged yetmerged yet● merge conflicts are postponedmerge conflicts are postponed● merge conflicts are more expensivemerge conflicts are more expensive

Page 11: Trunk based development

Welcome to Merge HellWelcome to Merge Hell

Page 12: Trunk based development

Trunk Based Developmentto the rescue

Image: https://commons.wikimedia.org/wiki/File:Placeholder_male_superhero_c.png (CC SA 3.0)

Page 13: Trunk based development

Trunk Based DevelopmentTrunk Based Development

● everyone commits to master at least once per dayeveryone commits to master at least once per day● remote branches are only made for releasesremote branches are only made for releases● developers may use local branchesdevelopers may use local branches● hotfixes are also committed to masterhotfixes are also committed to master● hotfixes are cherry picked into supported releaseshotfixes are cherry picked into supported releases● only Release Managers may branch release only Release Managers may branch release

branchesbranches

Page 14: Trunk based development

WorkflowWorkflow

Page 15: Trunk based development

AdvantagesAdvantages

● leanlean● can release at any timecan release at any time● merge problems surface earlymerge problems surface early● merge problems are smallermerge problems are smaller● release branches are cheaprelease branches are cheap

Page 16: Trunk based development

ProblemsProblems

● Branches no longer document featuresBranches no longer document features● Needs a way to hide/disable unfinished workNeeds a way to hide/disable unfinished work● Requires additional care with db changesRequires additional care with db changes● Requires OOD knowledgeRequires OOD knowledge

Page 17: Trunk based development

Branch by AbstractionBranch by Abstraction

"Branch by Abstraction" is a technique for making a large-"Branch by Abstraction" is a technique for making a large-scale change to a software system in gradual way that scale change to a software system in gradual way that

allows you to release the system regularly while the allows you to release the system regularly while the change is still in-progress.change is still in-progress.

- Martin Fowler- Martin Fowler

Page 18: Trunk based development

In a nutshellIn a nutshell

● modularity through design not through VCSmodularity through design not through VCS● add an abstraction over any code you are going to change in a add an abstraction over any code you are going to change in a

featurefeature● new features are added through Adapters and Interfacesnew features are added through Adapters and Interfaces● production code keeps old implementations while feature is production code keeps old implementations while feature is

incompleteincomplete● development code uses the new implementationsdevelopment code uses the new implementations● when the feature is ready, the new implementations are when the feature is ready, the new implementations are

rolled outrolled out

Page 19: Trunk based development

Feature TogglesFeature Toggles

● features are hidden until readyfeatures are hidden until ready● hides features at the entry pointshides features at the entry points● easy to configure via config fileeasy to configure via config file● easy to implement with a small POPOeasy to implement with a small POPO● can be tailored to specific user groupscan be tailored to specific user groups● bonus:bonus: allows for easy A/B testing allows for easy A/B testing

Page 20: Trunk based development

Feature Toggles at MVSFeature Toggles at MVS

Page 21: Trunk based development

Database ChangesDatabase Changes

● all changes to the database need to be all changes to the database need to be backwards compatiblebackwards compatible

● one statement per migrationone statement per migration● migrations should be transactionalmigrations should be transactional● needs to be integrated into the build process needs to be integrated into the build process

(DBDeploy, Liquibase, …)(DBDeploy, Liquibase, …)

Page 22: Trunk based development

Any Questions so far?Any Questions so far?

Page 23: Trunk based development

Example 1 - Migrate CodeExample 1 - Migrate CodeObjective: replace a legacy component with a Objective: replace a legacy component with a

newer componentnewer component

Page 24: Trunk based development

Current CodeCurrent Code

Page 25: Trunk based development

Step One: Decouple the Step One: Decouple the implementationimplementation

Page 26: Trunk based development

ProTipProTip

● In PHPStorm you can right-click class code and In PHPStorm you can right-click class code and select Refactor Extract Interface→ →select Refactor Extract Interface→ →

● If your IDE doesn't support Extract Interface, If your IDE doesn't support Extract Interface, try https://github.com/gooh/InterfaceDistillertry https://github.com/gooh/InterfaceDistiller

Page 27: Trunk based development

Step Two: Change all consumers Step Two: Change all consumers to use the Interfaceto use the Interface

Page 28: Trunk based development

Step Three: Add feature toggleStep Three: Add feature toggle

Page 29: Trunk based development

Step Four: Add new componentStep Four: Add new component

Page 30: Trunk based development

Step Five: CleanupStep Five: Cleanup

● remove the toggle from bootstrapremove the toggle from bootstrap● optional: remove the interface againoptional: remove the interface again

● Done \o/Done \o/

Page 31: Trunk based development

Example 2: Change APIExample 2: Change APIObjective: adapt a new API graduallyObjective: adapt a new API gradually

Page 32: Trunk based development

Change API - SetupChange API - Setup

Page 33: Trunk based development

Change API: isolate the old APIChange API: isolate the old API

Page 34: Trunk based development

Change API: fading outChange API: fading out

Page 35: Trunk based development

Change API: cleanupChange API: cleanup

● when ready, remove the old API codewhen ready, remove the old API code● run your tests to make sure it worksrun your tests to make sure it works● remove the Migration Adapter from bootstrapremove the Migration Adapter from bootstrap● inject the component with the new API onlyinject the component with the new API only

● done \o/done \o/

Page 36: Trunk based development

Bonus: Using a VerifyBonus: Using a VerifyObjective: harden against failuresObjective: harden against failures

Page 37: Trunk based development

In a nutshellIn a nutshell

● Verify adds additional safety to the migrationVerify adds additional safety to the migration● fail fast and tell you where at runtimefail fast and tell you where at runtime● is basically a Runtime Assertionis basically a Runtime Assertion

● is is NOTNOT a replacement for your test QA a replacement for your test QA

Page 38: Trunk based development

Verify: ImplementationVerify: Implementation

Page 39: Trunk based development

Questions?Questions?Last Chance!Last Chance!

Page 40: Trunk based development

ReferencesReferences

● http://paulhammant.com/2013/04/05/what-is-trunk-based-developmenthttp://paulhammant.com/2013/04/05/what-is-trunk-based-development● http://paulhammant.com/blog/branch_by_abstraction.htmlhttp://paulhammant.com/blog/branch_by_abstraction.html● http://paulhammant.com/2011/05/13/avoid-big-bang-for-branch-by-abstraction/http://paulhammant.com/2011/05/13/avoid-big-bang-for-branch-by-abstraction/● http://continuousdelivery.com/2011/05/make-large-scale-changes-incrementally-with-http://continuousdelivery.com/2011/05/make-large-scale-changes-incrementally-with-

branch-by-abstraction/branch-by-abstraction/● http://c2.com/cgi/wiki?BranchByAbstractionhttp://c2.com/cgi/wiki?BranchByAbstraction● http://martinfowler.com/bliki/FeatureToggle.htmlhttp://martinfowler.com/bliki/FeatureToggle.html● http://martinfowler.com/bliki/BranchByAbstraction.htmlhttp://martinfowler.com/bliki/BranchByAbstraction.html● http://www.stephen-smith.co.uk/application-pattern-verify-branch-by-abstraction/http://www.stephen-smith.co.uk/application-pattern-verify-branch-by-abstraction/● http://dev.jimdo.com/2013/05/03/software-migration-strategies/http://dev.jimdo.com/2013/05/03/software-migration-strategies/● http://java.dzone.com/articles/application-pattern-verifyhttp://java.dzone.com/articles/application-pattern-verify● http://www.whitewashing.de/2013/12/05/feature_flags_and_doctrine_entities.htmlhttp://www.whitewashing.de/2013/12/05/feature_flags_and_doctrine_entities.html● http://abhishek-tiwari.com/post/decoupling-deployment-and-release-feature-toggleshttp://abhishek-tiwari.com/post/decoupling-deployment-and-release-feature-toggles

Page 41: Trunk based development

Thanks!Thanks!https://joind.in/10876https://joind.in/10876


Top Related