Download - Continous delivery with sbt

Transcript
Page 1: Continous delivery with sbt

CONTINOUS DELIVERYWITH SBT

JENKINS, DOCKER, GATLING AND MORECreated by Wojciech Pituła

Page 2: Continous delivery with sbt

DEPLOYMENT PIPELINE

Page 3: Continous delivery with sbt

BENEFITSRepeatable deploysHistory of deploysNo knowledge needed to deployFast rollback to previous version

Page 4: Continous delivery with sbt
Page 5: Continous delivery with sbt
Page 6: Continous delivery with sbt
Page 7: Continous delivery with sbt

RELEASE STAGE

Page 8: Continous delivery with sbt

COMMIT> ...

> sbt test

> ...

> git push

Page 9: Continous delivery with sbt

JENKINS POLL

Page 10: Continous delivery with sbt
Page 11: Continous delivery with sbt

SBT RELEASEproject/plugins.sbt

addSbtPlugin("com.github.gseitz" % "sbt­release" % "1.0.0")

shell> sbt release

Page 12: Continous delivery with sbt

jenkins

Page 13: Continous delivery with sbt

RELEASE PROCESSBUILD.SBT

import sbtrelease.ReleasePlugin.autoImport.ReleaseTransformations._releaseProcess := Seq[ReleaseStep]( checkSnapshotDependencies, inquireVersions, runTest, setReleaseVersion, commitReleaseVersion, tagRelease, ReleaseStep(releaseStepTask(publish in Docker)), publishArtifacts, setNextVersion, commitNextVersion, pushChanges)

Page 14: Continous delivery with sbt

inquireVersionsReleaseStep(releaseStepTask(publish in Docker))publishArtifactspushChanges

Page 15: Continous delivery with sbt

RELEASE: INQUIRE VERSIONSVERSION.SBT

version in ThisBuild := "0.1.40­SNAPSHOT"

inquireVersionspublishArtifactsReleaseStep(releaseStepTask(publish in Docker))pushChanges

Page 16: Continous delivery with sbt

RELEASE: PUBLISH ARTIFACTSoptional

> sbt publish

inquireVersionspublishArtifactsReleaseStep(releaseStepTask(publish in Docker))pushChanges

Page 17: Continous delivery with sbt

BUILD.SBTpublishMavenStyle := truepublishArtifact in Test := falsepomIncludeRepository := _ => false publishTo := val nexus = "http://nexus.int.wp­sa.pl/" if (isSnapshot.value) Some("snapshots" at nexus + "content/repositories/snapshots" else Some("releases" at nexus + "content/repositories/releases")

Page 18: Continous delivery with sbt

RELEASE: DOCKERplugins.sbt

addSbtPlugin("com.typesafe.sbt" % "sbt­native­packager" % "1.0.3")

shell> sbt docker:publish

inquireVersionspublishArtifactsReleaseStep(releaseStepTask(publish in Docker))pushChanges

Page 19: Continous delivery with sbt

BUILD.SBTenablePlugins(JavaAppPackaging)dockerBaseImage := "java:8"dockerRepository := Some("hub.docker.grupawp.pl/itrd")

Page 20: Continous delivery with sbt

RELEASE: PUSHPush bumped version and tag to origin

inquireVersionspublishArtifactsReleaseStep(releaseStepTask(publish in Docker))pushChanges

Page 21: Continous delivery with sbt
Page 22: Continous delivery with sbt

SUCCESS

Page 23: Continous delivery with sbt

TRIGGER NEXT STEP

Page 24: Continous delivery with sbt

ADD RELEASED_VER PARAMETER

Page 25: Continous delivery with sbt

TRIGGER BUILD WITH PARAMS

Page 26: Continous delivery with sbt

DEPLOY TO DEV

Page 27: Continous delivery with sbt

DEPLOY BUILD

Page 28: Continous delivery with sbt

DEPLOY SCRIPT#!/usr/bin/env bashset ­xueAPP_VERSION=$1HOST=$2APP_NAME=ab­tests­serviceDOCKER_IMAGE=hub.docker.grupawp.pl/itrd/ab­tests­service:$APP_VERSIONshift 2RUN_OPTS=$@ssh ­t ­o StrictHostKeyChecking=no jenkins­ci@$HOST << EOF docker pull $DOCKER_IMAGE docker stop $APP_NAME docker rm $APP_NAME docker run ­­name $APP_NAME ­d ­p 8080:8080 $DOCKER_IMAGE $RUN_OPTSEOF# verify if docker is runningsleep 30ssh ­t ­o StrictHostKeyChecking=no jenkins­ci@$HOST 'RUNNING=docker inspect ­­format=" .State.Running " ab­tests­service; [[ $RUNNING == "true" ]]'

Page 29: Continous delivery with sbt

MACHINE SETUPANSIBLE PLAYBOOK

­­­­ hosts: all sudo: yes

tasks: ­ name: install docker­engine yum: name=docker­engine state=present

­ name: create jenkins user user: name=jenkins­ci groups=docker state=present shell=/bin/bash home=/opt/jenkins­ci createhome=yes

­ name: Set up authorized_keys for the deploy user authorized_key: user=jenkins­ci key=" item " with_file: ­ id_rsa.pub_noweci ­ id_rsa.pub

Page 30: Continous delivery with sbt

SUCCESS

Page 31: Continous delivery with sbt

TESTSTriggered automatically after deploy

Page 32: Continous delivery with sbt

GATLINGAn open-source load testing framework based on Scala,

Akka and Netty

High performanceReady-to-present HTML reportsScenario recorder and developer-friendly DSL

Page 33: Continous delivery with sbt

GATLING SCENARIOPut in src/it/scala

class AddAndDeleteSingleTestSimulation extends Simulation val httpConf = http.baseURL("some.url") val testScenario = scenario("AddAndGetSingleTest") .exec( http("PostNewTest") .post("some/endpoint") .header("Content­Type", "application/json") .body(StringBody("body")) .check(status.is(201)) ) .exec( http("GetCreatedTest") .get("some/endpoint") .check(status.is(200), jsonPath("$.testDef.name").is(testName)) ) .exec( http("DeleteCreatedTest")

Page 34: Continous delivery with sbt

PLUGINS.SBTaddSbtPlugin("io.gatling" % "gatling­sbt" % "2.1.5")

BUILD.SBTenablePlugins(GatlingPlugin)configs(IntegrationTest, GatlingIt)Defaults.itSettings

Page 35: Continous delivery with sbt
Page 36: Continous delivery with sbt

2015­09­09 12:38:33 +02:00, duration : 0 secondsGLOBAL DETAILS

> Global Information

Expand all groups | Collapse all groups

ASSERTIONS

Assertion

For all requests: count of failed requests is 0

STATISTICS

Executions Response Time (ms)

KO OK

0

1

Number of requestsNu

mber o

f Requests

t < 800 ms 800 ms < t < 1200ms

t > 1200 ms failed0

1

2

3

4

5

Indicators

addanddeletesingletestsimulation

Active Users

Requests / sec

Responses / sec

SUCCESS

Page 37: Continous delivery with sbt

DEPLOY TO PRODUCTIONExactly the same process like with DEV environment

Page 38: Continous delivery with sbt

TRIGGER MANUALLY

Page 39: Continous delivery with sbt

SUCCESS

Page 40: Continous delivery with sbt

DRAWBACKS AND PROBLEMSbinaries and config separationsmoke testsproduction db passworddata migration/schema updatesdeployment downtime

Page 41: Continous delivery with sbt

TRICKSbuild-name-setter