Continous delivery with sbt

download Continous delivery with sbt

of 41

  • date post

    15-Apr-2017
  • Category

    Software

  • view

    626
  • download

    0

Embed Size (px)

Transcript of Continous delivery with sbt

  • CONTINOUS DELIVERYWITH SBT

    JENKINS, DOCKER, GATLING AND MORECreated by Wojciech Pitua

  • DEPLOYMENT PIPELINE

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

  • RELEASE STAGE

  • COMMIT>...

    >sbttest

    >...

    >gitpush

  • JENKINS POLL

  • SBT RELEASEproject/plugins.sbt

    addSbtPlugin("com.github.gseitz"%"sbtrelease"%"1.0.0")

    shell>sbtrelease

  • jenkins

  • RELEASE PROCESSBUILD.SBT

    importsbtrelease.ReleasePlugin.autoImport.ReleaseTransformations._releaseProcess:=Seq[ReleaseStep](checkSnapshotDependencies,inquireVersions,runTest,setReleaseVersion,commitReleaseVersion,tagRelease,ReleaseStep(releaseStepTask(publishinDocker)),publishArtifacts,setNextVersion,commitNextVersion,pushChanges)

  • inquireVersionsReleaseStep(releaseStepTask(publish in Docker))publishArtifactspushChanges

  • RELEASE: INQUIRE VERSIONSVERSION.SBT

    versioninThisBuild:="0.1.40SNAPSHOT"

    inquireVersionspublishArtifactsReleaseStep(releaseStepTask(publish in Docker))pushChanges

  • RELEASE: PUBLISH ARTIFACTSoptional

    >sbtpublish

    inquireVersionspublishArtifactsReleaseStep(releaseStepTask(publish in Docker))pushChanges

  • BUILD.SBTpublishMavenStyle:=truepublishArtifactinTest:=falsepomIncludeRepository:={_=>false}publishTo:={valnexus="http://nexus.int.wpsa.pl/"if(isSnapshot.value)Some("snapshots"atnexus+"content/repositories/snapshots"elseSome("releases"atnexus+"content/repositories/releases")}

  • RELEASE: DOCKERplugins.sbt

    addSbtPlugin("com.typesafe.sbt"%"sbtnativepackager"%"1.0.3")

    shell>sbtdocker:publish

    inquireVersionspublishArtifactsReleaseStep(releaseStepTask(publish in Docker))pushChanges

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

  • RELEASE: PUSHPush bumped version and tag to origin

    inquireVersionspublishArtifactsReleaseStep(releaseStepTask(publish in Docker))pushChanges

  • SUCCESS

  • TRIGGER NEXT STEP

  • ADD RELEASED_VER PARAMETER

  • TRIGGER BUILD WITH PARAMS

  • DEPLOY TO DEV

  • DEPLOY BUILD

  • DEPLOY SCRIPT#!/usr/bin/envbashsetxueAPP_VERSION=$1HOST=$2APP_NAME=abtestsserviceDOCKER_IMAGE=hub.docker.grupawp.pl/itrd/abtestsservice:$APP_VERSIONshift2RUN_OPTS=$@sshtoStrictHostKeyChecking=nojenkinsci@$HOST
  • MACHINE SETUPANSIBLE PLAYBOOK

    hosts:allsudo:yes

    tasks:name:installdockerengineyum:name=dockerenginestate=present

    name:createjenkinsuseruser:name=jenkinscigroups=dockerstate=presentshell=/bin/bashhome=/opt/jenkinscicreatehome=yes

    name:Setupauthorized_keysforthedeployuserauthorized_key:user=jenkinscikey="{{item}}"with_file:id_rsa.pub_noweciid_rsa.pub

  • SUCCESS

  • TESTSTriggered automatically after deploy

  • GATLINGAn open-source load testing framework based on Scala,

    Akka and Netty

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

  • GATLING SCENARIOPut in src/it/scala

    classAddAndDeleteSingleTestSimulationextendsSimulation{valhttpConf=http.baseURL("some.url")valtestScenario=scenario("AddAndGetSingleTest").exec(http("PostNewTest").post("some/endpoint").header("ContentType","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")

  • PLUGINS.SBTaddSbtPlugin("io.gatling"%"gatlingsbt"%"2.1.5")

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

  • 2015090912:38:33+02:00,duration:0secondsGLOBAL DETAILS

    >GlobalInformation

    Expandallgroups|Collapseallgroups

    ASSERTIONS

    Assertion

    Forallrequests:countoffailedrequestsis0

    STATISTICS

    Executions ResponseTime(ms)

    KO OK

    0

    1

    NumberofrequestsNu

    mbe

    rofR

    eque

    sts

    t

  • DEPLOY TO PRODUCTIONExactly the same process like with DEV environment

    file:///home/wpitula/Projects/cd-with-sbt/res/gatling-report/req_deletecreatedte-de08b.htmlfile:///home/wpitula/Projects/cd-with-sbt/res/gatling-report/req_getcreatedtest-1faf5.htmlfile:///home/wpitula/Projects/cd-with-sbt/res/gatling-report/req_getdeletedtest-c8824.htmlfile:///home/wpitula/Projects/cd-with-sbt/res/gatling-report/index.htmlfile:///home/wpitula/Projects/cd-with-sbt/res/gatling-report/req_postnewtest-0f6b8.html

  • TRIGGER MANUALLY

  • SUCCESS

    http://gatling.io/

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

  • TRICKSbuild-name-setter