trunk based development
Post on 29-Oct-2014
1.096 Views
Preview:
DESCRIPTION
TRANSCRIPT
Trunk Based DevelopmentTrunk Based DevelopmentDutch PHP ConferenceDutch PHP Conference
2014-06-282014-06-28
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 → → gooh@php.netgooh@php.net
Before we start …Before we start …
x
Six months ago …Six months ago …
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
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
Welcome to Merge HellWelcome to Merge Hell
Trunk Based Developmentto the rescue
Image: https://commons.wikimedia.org/wiki/File:Placeholder_male_superhero_c.png (CC SA 3.0)
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
WorkflowWorkflow
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
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
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
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
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
Feature Toggles at MVSFeature Toggles at MVS
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, …)
Any Questions so far?Any Questions so far?
Example 1 - Migrate CodeExample 1 - Migrate CodeObjective: replace a legacy component with a Objective: replace a legacy component with a
newer componentnewer component
Current CodeCurrent Code
Step One: Decouple the Step One: Decouple the implementationimplementation
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
Step Two: Change all consumers Step Two: Change all consumers to use the Interfaceto use the Interface
Step Three: Add feature toggleStep Three: Add feature toggle
Step Four: Add new componentStep Four: Add new component
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/
Example 2: Change APIExample 2: Change APIObjective: adapt a new API graduallyObjective: adapt a new API gradually
Change API - SetupChange API - Setup
Change API: isolate the old APIChange API: isolate the old API
Change API: fading outChange API: fading out
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/
Bonus: Using a VerifyBonus: Using a VerifyObjective: harden against failuresObjective: harden against failures
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
Verify: ImplementationVerify: Implementation
Questions?Questions?Last Chance!Last Chance!
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
Thanks!Thanks!https://joind.in/10876https://joind.in/10876
top related