Top Banner
THE ROAD TO CONTINUOUS DEPLOYMENT - A CASE STUDY MICHIEL ROOK - @MICHIELTCS
58

The road to continuous deployment (PHPCon Poland 2016)

Jan 07, 2017

Download

Software

Michiel Rook
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: The road to continuous deployment (PHPCon Poland 2016)

THE ROAD TO CONTINUOUS DEPLOYMENT - A CASE STUDY

MICHIEL ROOK - @MICHIELTCS

Page 2: The road to continuous deployment (PHPCon Poland 2016)

▸ Java, PHP & Scala developer

▸ Consultant, trainer, speaker

▸ make.io

▸ Dutch Web Alliance

▸ Maintainer of Phing

▸ @michieltcs

Page 3: The road to continuous deployment (PHPCon Poland 2016)

THIS TALK

▸ Background

▸ The approach

▸ Process / standards

▸ Build pipelines

▸ Results & lessons learned

Page 4: The road to continuous deployment (PHPCon Poland 2016)
Page 5: The road to continuous deployment (PHPCon Poland 2016)

THE SYSTEM - SAN DIEGO

▸ ... or the Big Ball Of Mud

▸ Large legacy monolith

▸ Generates significant income

▸ Slow & complex

▸ Technical debt

Page 6: The road to continuous deployment (PHPCon Poland 2016)

SAN DIEGO FRONTEND

MYSQL DB

SAN DIEGO BACKEND

LOAD BALANCERS / VARNISH

ITBANEN INTERMEDIAIR NATIONALEVACATUREBANK

SAN DIEGO FRONTEND

SAN DIEGO FRONTEND

SAN DIEGO FRONTEND

SAN DIEGO BACKEND

SAN DIEGO BACKEND

SAN DIEGO BACKEND

MEMCACHE FTP EXT. SERVICES

SOLR

Page 7: The road to continuous deployment (PHPCon Poland 2016)

THE SYSTEM - SAN DIEGO

▸ Infrequent, manual releases

▸ Fragile tests

▸ Low velocity

▸ Frequent outages / bugs / issues

▸ Frustrated team

▸ Low confidence modifying existing code

Page 8: The road to continuous deployment (PHPCon Poland 2016)

GOALS

▸ Reduce issues

▸ Reduce cycle time

▸ Increase productivity

▸ Increase motivation

Page 9: The road to continuous deployment (PHPCon Poland 2016)

REFACTOR? REBUILD?

Page 10: The road to continuous deployment (PHPCon Poland 2016)

APPROACH

▸ Strangler pattern

▸ Services per domain object (job, jobseeker, ...)

▸ Proxy to switch between old/new

▸ Migrate individual pages

Page 11: The road to continuous deployment (PHPCon Poland 2016)

ORIGINAL MONOLITH

PROXY

SERVICEORIGINAL MONOLITH

ORIGINAL MONOLITH

SERVICE SERVICE

SERVICE

PROXY

DB

DBDB

DB

DB DB

Page 12: The road to continuous deployment (PHPCon Poland 2016)

APPROACH

▸ Services behind load balancers

▸ Access legacy db’s

▸ Continuous deployment

▸ Docker containers

▸ Frontends are services

Page 13: The road to continuous deployment (PHPCon Poland 2016)

SAN DIEGO

ELASTIC SEARCHLEGACY

DB

JOB SERVICE

RMQ

ITBANEN INTERMEDIAIR NATIONALEVACATUREBANK

MONGO DB

ITBANEN

JOBSEEKER SERVICE

NVBINTERMEDIAIR

Page 14: The road to continuous deployment (PHPCon Poland 2016)

PROCESS

Page 15: The road to continuous deployment (PHPCon Poland 2016)

STARTING OFF

▸ Scrum, 1 week sprints

▸ TDD / BDD

▸ Definition of Done

▸ Team mindset / experience

▸ Focus on value

▸ Replace old features with new (legacy becomes obsolete)

Page 16: The road to continuous deployment (PHPCon Poland 2016)

CONTINUOUS EVERYTHING

Page 17: The road to continuous deployment (PHPCon Poland 2016)

DEV BUILD / TEST

CONTINUOUS INTEGRATION

Page 18: The road to continuous deployment (PHPCon Poland 2016)

DEV BUILD / TEST ACCEPTANCE PRODUCTION

CONTINUOUS DELIVERY

Page 19: The road to continuous deployment (PHPCon Poland 2016)

DEV BUILD / TEST ACCEPTANCE PRODUCTION

CONTINUOUS DEPLOYMENT

Page 20: The road to continuous deployment (PHPCon Poland 2016)

WHY CONTINUOUS DEPLOYMENT

▸ Small steps

▸ Less overhead

▸ Early feedback

▸ Reduce cycle time

▸ Reduce risk

Page 21: The road to continuous deployment (PHPCon Poland 2016)

ONLY COMMIT TO MASTER

Page 22: The road to continuous deployment (PHPCon Poland 2016)

NO BRANCHES

Page 23: The road to continuous deployment (PHPCon Poland 2016)

NO BRANCHES

REALLY.

Page 24: The road to continuous deployment (PHPCon Poland 2016)

PAIR PROGRAMMING

Page 25: The road to continuous deployment (PHPCon Poland 2016)

BOY SCOUT RULE

Page 26: The road to continuous deployment (PHPCon Poland 2016)

QUALITY GATES

Page 27: The road to continuous deployment (PHPCon Poland 2016)

100% CODE COVERAGE *

Page 28: The road to continuous deployment (PHPCon Poland 2016)

FEATURE TOGGLES, A/B TESTS

Page 29: The road to continuous deployment (PHPCon Poland 2016)

DEVOPS

Page 30: The road to continuous deployment (PHPCon Poland 2016)

DASHBOARDS

Page 31: The road to continuous deployment (PHPCon Poland 2016)

BUILDPIPELINE

Page 32: The road to continuous deployment (PHPCon Poland 2016)

AUTOMATE REPEATABLE THINGS

Page 33: The road to continuous deployment (PHPCon Poland 2016)

EVERY COMMIT GOES TO PRODUCTION

Page 34: The road to continuous deployment (PHPCon Poland 2016)

DEFENSE IN DEPTH

UNIT TESTS

INTEGRATIONTESTS

ACCEPTANCETESTS

UI TESTS

Page 35: The road to continuous deployment (PHPCon Poland 2016)

DEFENSE IN DEPTH

UNIT TESTS

INTEGRATIONTESTS

ACCEPTANCE

UI TESTS

public function testJobCannotBeFound() { $jobRepository = $this->prophesize(JobRepository::class); $jobRepository->getById(EXPECTED_JOB_ID) ->shouldBeCalled() ->willReturn(false); $jobService = new JobService($jobRepository->reveal()); $this->assertFalse($jobService->getById(EXPECTED_JOB_ID)); }

Page 36: The road to continuous deployment (PHPCon Poland 2016)

DEFENSE IN DEPTH

UNIT TESTS

INTEGRATIONTESTS

ACCEPTANCETESTS

UI TESTS

public function testFindJob() { $expectedJob = $this->loadFixture('active_job.yml'); $actualJob = $this->repository->getById($expectedJob->getId()); self::assertInstanceOf(Job::class, $actualJob); self::assertEquals($expectedJob->getId(), $actualJob->getId()); }

Page 37: The road to continuous deployment (PHPCon Poland 2016)

DEFENSE IN DEPTH

UNIT TESTS

INTEGRATIONTESTS

ACCEPTANCETESTS

UI TESTSScenario: Link to related job Given a job exists And there are related jobs available When that job is viewed Then a list of related jobs is shown And each related job links to the detail page of the related job

Page 38: The road to continuous deployment (PHPCon Poland 2016)

DEFENSE IN DEPTH

UNIT TESTS

INTEGRATIONTESTS

ACCEPTANCETESTS

UI TESTS

Page 39: The road to continuous deployment (PHPCon Poland 2016)

DEFENSE IN DEPTH

MANUAL TESTING?

UNIT TESTS

INTEGRATIONTESTS

ACCEPTANCETESTS

UI

Page 40: The road to continuous deployment (PHPCon Poland 2016)

CONTINUOUS TESTING

UNIT TESTS

INTEGRATION TESTS

ACCEPTANCE TESTS

UI TESTS

SMOKETESTS

Cost Speed

Exploratorytesting Monitoring

Page 41: The road to continuous deployment (PHPCon Poland 2016)

PIPELINE AS CODE

node { stage 'Run tests' sh "phpunit" sh "behat" stage 'Build docker image' sh "phing build" sh "docker build -t jobservice:${env.BUILD_NUMBER} ." sh "docker push jobservice:${env.BUILD_NUMBER}" stage 'Deploy acceptance' sh "ansible-playbook -e BUILD=${env.BUILD_NUMBER} -i acc deploy.yml" stage 'Deploy production' sh "ansible-playbook -e BUILD=${env.BUILD_NUMBER} -i prod deploy.yml" }

Page 42: The road to continuous deployment (PHPCon Poland 2016)

DOCKERFILE

FROM php:7.0-apache

ADD vhost.conf /etc/apache2/sites-available/000-default.conf

ADD . /var/www/html

Page 43: The road to continuous deployment (PHPCon Poland 2016)

DEPLOYING

PULL IMAGE

START NEW CONTAINER

WAIT FOR PORT

SMOKE TESTS / HEALTH CHECKS

ADD NEW CONTAINER TO LB

REMOVE OLD CONTAINER FROM LB

STOP OLD CONTAINER

Page 44: The road to continuous deployment (PHPCon Poland 2016)

DEPLOYING

PULL IMAGE

START NEW CONTAINER

WAIT FOR PORT

SMOKE TESTS / HEALTH CHECKS

ADD NEW CONTAINER TO LB

REMOVE OLD CONTAINER FROM LB

STOP OLD CONTAINER

docker pull

Page 45: The road to continuous deployment (PHPCon Poland 2016)

DEPLOYING

PULL IMAGE

START NEW CONTAINER

WAIT FOR PORT

SMOKE TESTS / HEALTH CHECKS

ADD NEW CONTAINER TO LB

REMOVE OLD CONTAINER FROM LB

STOP OLD CONTAINER

docker run

Page 46: The road to continuous deployment (PHPCon Poland 2016)

DEPLOYING

PULL IMAGE

START NEW CONTAINER

WAIT FOR PORT

SMOKE TESTS / HEALTH CHECKS

ADD NEW CONTAINER TO LB

REMOVE OLD CONTAINER FROM LB

STOP OLD CONTAINER

wait_for: port=8080 delay=5 timeout=15

Page 47: The road to continuous deployment (PHPCon Poland 2016)

DEPLOYING

PULL IMAGE

START NEW CONTAINER

WAIT FOR PORT

SMOKE TESTS / HEALTH CHECKS

ADD NEW CONTAINER TO LB

REMOVE OLD CONTAINER FROM LB

STOP OLD CONTAINER

uri: url: http://localhost:8080/_health status_code: 200 timeout: 30

Page 48: The road to continuous deployment (PHPCon Poland 2016)

DEPLOYING

PULL IMAGE

START NEW CONTAINER

WAIT FOR PORT

SMOKE TESTS / HEALTH CHECKS

ADD NEW CONTAINER TO LB

REMOVE OLD CONTAINER FROM LB

STOP OLD CONTAINER

template: src=haproxy.cfg.j2 dest=/etc/haproxy/haproxy.cfg

service: name=haproxy state=reloaded

Page 49: The road to continuous deployment (PHPCon Poland 2016)

DEPLOYING

PULL IMAGE

START NEW CONTAINER

WAIT FOR PORT

SMOKE TESTS / HEALTH CHECKS

ADD NEW CONTAINER TO LB

REMOVE OLD CONTAINER FROM LB

STOP OLD CONTAINER

template: src=haproxy.cfg.j2 dest=/etc/haproxy/haproxy.cfg

service: name=haproxy state=reloaded

Page 50: The road to continuous deployment (PHPCon Poland 2016)

DEPLOYING

PULL IMAGE

START NEW CONTAINER

WAIT FOR PORT

SMOKE TESTS / HEALTH CHECKS

ADD NEW CONTAINER TO LB

REMOVE OLD CONTAINER FROM LB

STOP OLD CONTAINER

docker stop

docker rm

Page 51: The road to continuous deployment (PHPCon Poland 2016)

BUILD PIPELINE

Page 52: The road to continuous deployment (PHPCon Poland 2016)

FEEDBACK!

Page 53: The road to continuous deployment (PHPCon Poland 2016)

RESULTS

Page 54: The road to continuous deployment (PHPCon Poland 2016)

RESULTS

▸ Total build time per service < 10 minutes

▸ Significantly improved page load times

▸ Improved audience stats (time on page, pages per session, session duration, traffic, seo ranking, etc)

▸ Increased confidence and velocity

▸ Experimented with new tech/stacks (angular, jvm, event sourcing)

▸ More fun

Page 55: The road to continuous deployment (PHPCon Poland 2016)

LESSONS LEARNED

▸ Team acceptance

▸ Change is hard

▸ Overhead of weekly sprint; requires discipline

▸ Docker orchestration

▸ Issues with traffic between Amazon <-> on-premise datacenter

▸ Javascript testing

Page 56: The road to continuous deployment (PHPCon Poland 2016)

LESSONS LEARNED

▸ Experience with new tech

▸ Stability of build pipelines

▸ Management/leadership buy-in

▸ Business alignment

▸ Not enough focus on replacing legacy application

Page 57: The road to continuous deployment (PHPCon Poland 2016)

QUESTION TIME

Page 58: The road to continuous deployment (PHPCon Poland 2016)

THANK YOU!

@michieltcs / [email protected]