Continuously serving the developer community with Continuous Integration and Delivery

52
Continuously serving the developer community with Continuous Integration and Delivery Akshay Karle Fernando Júnior

Transcript of Continuously serving the developer community with Continuous Integration and Delivery

Page 1: Continuously serving the developer community with  Continuous Integration and Delivery

Continuously serving the developer community with

Continuous Integration and Delivery

Akshay Karle

Fernando Júnior

Page 2: Continuously serving the developer community with  Continuous Integration and Delivery

“How long would it take your organization to deploy a change that involves just one single line of code?”

Mary and Tom Poppendieck

Page 3: Continuously serving the developer community with  Continuous Integration and Delivery

“(…) build software in such a way that the software can be released to

production at any time.” Martin Fowler

Page 4: Continuously serving the developer community with  Continuous Integration and Delivery

CONTINUOUS INTEGRATION

Page 5: Continuously serving the developer community with  Continuous Integration and Delivery

CONTINUOUS DELIVERY

Page 6: Continuously serving the developer community with  Continuous Integration and Delivery

CONTINUOUS DELIVERY

▫︎ Continuous Integration

▫︎ Automated tasks

▫︎ Repeatable/reliable process

Page 7: Continuously serving the developer community with  Continuous Integration and Delivery

CONTINUOUS DELIVERY

frequent, reliable releases of high quality valuable

software

Page 8: Continuously serving the developer community with  Continuous Integration and Delivery

THERE’S MORE…

Page 9: Continuously serving the developer community with  Continuous Integration and Delivery

CONTINUOUS DELIVERY

Page 10: Continuously serving the developer community with  Continuous Integration and Delivery

CONTINUOUS DELIVERY

Page 11: Continuously serving the developer community with  Continuous Integration and Delivery

DEPLOYING YOUR APPLICATION

▫︎ Database migrations

▫︎ Infrastructure update

▫︎ Restarting services

Page 12: Continuously serving the developer community with  Continuous Integration and Delivery

ZERO DOWNTIME DEPLOYMENTS

Deployment process of your application has got to be transparent for end users

Page 13: Continuously serving the developer community with  Continuous Integration and Delivery

WHO WE ARE?

Developer, ThoughtWorks

@nandopaf

fernando-alves

nand0paf

Developer, ThoughtWorks

@akshay_karle

akshaykarle

akshay_ka

Page 14: Continuously serving the developer community with  Continuous Integration and Delivery

WHAT WE DO?

▫︎ Continuous Integration and Delivery for repositories on GitHub

▫︎ Cloud Hosted

Page 15: Continuously serving the developer community with  Continuous Integration and Delivery

SNAP INSIDE-OUT

Page 16: Continuously serving the developer community with  Continuous Integration and Delivery

LIFECYCLE OF A BUILD

head repository commit

Page 17: Continuously serving the developer community with  Continuous Integration and Delivery

LIFECYCLE OF A BUILD

head repository commit

Page 18: Continuously serving the developer community with  Continuous Integration and Delivery

Babysitters

LIFECYCLE OF A BUILD

head repository commit

DATABASE

Page 19: Continuously serving the developer community with  Continuous Integration and Delivery

LIFE CYCLE

▫︎ Prepare the container

▫︎ Starts database

▫︎ Sets PATH for languages

▫︎ Download artifacts

▫︎ Git clone

▫︎ Runs each pipeline stage

▫︎ Upload artifacts

DATABASE

Page 20: Continuously serving the developer community with  Continuous Integration and Delivery

Babysitters

LIFECYCLE OF A BUILD

head repository commit

DATABASE

Page 21: Continuously serving the developer community with  Continuous Integration and Delivery

ARCHITECTURE OVERVIEW

L B

Database

web server

Page 22: Continuously serving the developer community with  Continuous Integration and Delivery

ARCHITECTURE OVERVIEW

▫︎ Rails app fronted by nginx

▫︎ Receives the hooks from GitHub

Database

web server

Page 23: Continuously serving the developer community with  Continuous Integration and Delivery

ARCHITECTURE OVERVIEW

L B

Build Server

web server

Database

Page 24: Continuously serving the developer community with  Continuous Integration and Delivery

ARCHITECTURE OVERVIEW

▫︎ Background jobs

▫︎ Babysitters

▫︎ Build Queue

▫︎ Artifacts

▫︎ OpenVZ Containers

▫︎ Virtual machines where the pipeline runs

Build Server

Page 25: Continuously serving the developer community with  Continuous Integration and Delivery

ARCHITECTURE OVERVIEW

L B

Build Server

web server

Database

Page 26: Continuously serving the developer community with  Continuous Integration and Delivery

OUR DEPLOYMENT

▫︎ Do have automated scripts

▫︎ Deployment pipeline

▫︎ 1-click deploy

▫︎ Sort of…

Babysitters

DATABASE

L B

Build Server

Database

web server

Page 27: Continuously serving the developer community with  Continuous Integration and Delivery

OUR DEPLOYMENT

▫︎ Wait for all builds to finish

▫︎ Put app on maintenance mode

▫︎ No new requests picked up

▫︎ Deploy and wait for migrations

Babysitters

DATABASE

L B

Database

VZHOSTBuild Server

web server

Page 28: Continuously serving the developer community with  Continuous Integration and Delivery

ZERO DOWNTIME DEPLOYMENTS

Page 29: Continuously serving the developer community with  Continuous Integration and Delivery

BLUE-GREEN DEPLOYMENT

Web Server App Server Database

App ServerApp ServerWeb Server Database

Page 30: Continuously serving the developer community with  Continuous Integration and Delivery

BLUE-GREEN DEPLOYMENTS FOR SNAP

VZHOSTBuild Server

web server

VZHOSTBuild Server

web server

L B DATABASE

Page 31: Continuously serving the developer community with  Continuous Integration and Delivery

CHALLENGES IN SNAP

Long running builds

Running multiple versions of your app at the same time

Database migrations

Page 32: Continuously serving the developer community with  Continuous Integration and Delivery

LONG RUNNING BUILDS

▫︎ Builds should continue to run

▫︎ Artifacts should continue to be served

Page 33: Continuously serving the developer community with  Continuous Integration and Delivery

COLOR AWARE BABYSITTERS

Build Server

Green Stack

Build Server

Blue Stack

web server

Page 34: Continuously serving the developer community with  Continuous Integration and Delivery

BUILD LIFECYCLE

head repository commit

DATABASEDATABASE

L B

Page 35: Continuously serving the developer community with  Continuous Integration and Delivery

THE SWITCH

L B

Page 36: Continuously serving the developer community with  Continuous Integration and Delivery

THE SWITCH

L B

Page 37: Continuously serving the developer community with  Continuous Integration and Delivery

CHALLENGES IN SNAP

Long running builds

Running multiple versions of your app at the same time

Database migrations

Page 38: Continuously serving the developer community with  Continuous Integration and Delivery

FEATURE TOGGLES

Hide unfinished UI elements

Control backend behaviour

Test with feature toggles

Avoid multi-component feature toggles

http://martinfowler.com/bliki/FeatureToggle.html

Page 39: Continuously serving the developer community with  Continuous Integration and Delivery

FRONTEND

<% if feature_enabled?(:parallel_stage) %> <!-- show new html --><% else %> <!-- show old html --><% end %>

Page 40: Continuously serving the developer community with  Continuous Integration and Delivery

BACKEND

if feature_enabled?(:parallel_stage) # new logicelse # old logicend

Page 41: Continuously serving the developer community with  Continuous Integration and Delivery

TESTING WITH FEATURE TOGGLES

describe "multiple jobs" do describe "feature enabled" do before(:each) do with_feature_enabled(:parallel_stage) end it 'should not show the job tabs when there is only one job' do end end describe "feature disabled" do before(:each) do with_feature_disabled(:parallel_stage) end it 'should not show the job tabs but should show the logs' do end endend

Page 42: Continuously serving the developer community with  Continuous Integration and Delivery

CHALLENGES IN SNAP

Long running builds

Running multiple versions of your app at the same time

Database migrations

Page 43: Continuously serving the developer community with  Continuous Integration and Delivery

MIGRATION OF DATA

Consider existing schema as well as data

Incremental changes

Rollbacks

Page 44: Continuously serving the developer community with  Continuous Integration and Delivery

INTRODUCING JOBS

jobs

id

Page 45: Continuously serving the developer community with  Continuous Integration and Delivery

INTRODUCING JOBS

stages

id

started_at

completed_at

result

jobs

id

Page 46: Continuously serving the developer community with  Continuous Integration and Delivery

POPULATE ALL EXISTING STAGES

stages

id

started_at

completed_at

result

jobs

id

stage_id

Page 47: Continuously serving the developer community with  Continuous Integration and Delivery

COPY ATTRIBUTES TO JOB

stages

started_at

completed_at

result

jobs

started_at

completed_at

result

Page 48: Continuously serving the developer community with  Continuous Integration and Delivery

SWITCH THE APPLICATION TO START USING THE JOB MODEL

# After switchclass Stage def result results = jobs.collect { |job| job.result } return :failed if results.any?(:failed) :passed endend

# Before switchclass Stage attr_reader :resultend

# in transitionclass Stage def result if feature_enabled?(:parallel_stage) results = jobs.collect { |job| job.result } return :failed if results.any?(:failed) :passed else result end endend

Page 49: Continuously serving the developer community with  Continuous Integration and Delivery

REMOVE UNUSED ATTRIBUTES

stages

id

started_at

completed_at

result

jobs

started_at

completed_at

result

Page 50: Continuously serving the developer community with  Continuous Integration and Delivery

LESSONS LEARNT

Page 51: Continuously serving the developer community with  Continuous Integration and Delivery

LESSONS LEARNT

Zero downtime is not easy

Having reliability, automation, frequent releases helped

Watch out your data

Things will go wrong, but we keep learning and keep improving