LDOP-240 blue green deployment (#16)

* Add traefik labels to petclinic dev

* LDOP-240 rolling blue/green deployment via Docker
This commit is contained in:
Eddie Bracho 2017-09-05 10:53:25 -07:00 committed by GitHub
parent f0b57e4613
commit 21d78146ad
2 changed files with 154 additions and 122 deletions

View file

@ -1,122 +0,0 @@
pipeline {
agent none
stages {
stage('Build') {
agent {
docker {
image 'maven:3.5.0'
args '-e INITIAL_ADMIN_USER -e INITIAL_ADMIN_PASSWORD --network=${LDOP_NETWORK_NAME}'
}
}
steps {
configFileProvider(
[configFile(fileId: 'nexus', variable: 'MAVEN_SETTINGS')]) {
sh 'mvn -s $MAVEN_SETTINGS clean deploy -DskipTests=true -B'
}
}
}
stage('Sonar') {
agent {
docker {
image 'sebp/sonar-runner'
args '-e SONAR_ACCOUNT_LOGIN -e SONAR_ACCOUNT_PASSWORD -e SONAR_DB_URL -e SONAR_DB_LOGIN -e SONAR_DB_PASSWORD --network=${LDOP_NETWORK_NAME}'
}
}
steps {
sh '/opt/sonar-runner-2.4/bin/sonar-runner -e -D sonar.login=${SONAR_ACCOUNT_LOGIN} -D sonar.password=${SONAR_ACCOUNT_PASSWORD} -D sonar.jdbc.url=${SONAR_DB_URL} -D sonar.jdbc.username=${SONAR_DB_LOGIN} -D sonar.jdbc.password=${SONAR_DB_PASSWORD}'
}
}
stage('Build container') {
agent any
steps {
sh 'docker build -t petclinic-tomcat .'
}
}
stage('Run local container') {
agent any
steps {
sh 'docker rm -f petclinic-tomcat-temp || true'
sh 'docker run -d --network=${LDOP_NETWORK_NAME} --name petclinic-tomcat-temp petclinic-tomcat'
}
}
stage('Smoke-Test & OWASP Security Scan') {
agent {
docker {
image 'maven:3.5.0'
args '--network=${LDOP_NETWORK_NAME}'
}
}
steps {
sh "cd regression-suite"
sh "mvn clean -B test -DPETCLINIC_URL=http://petclinic-tomcat:8080/petclinic/"
}
}
stage('Stop local container') {
agent any
steps {
sh 'docker rm -f petclinic-tomcat-temp || true'
}
}
stage('Deploy to dev') {
agent any
steps {
sh 'docker rm -f dev-petclinic || true'
sh 'docker run --label "traefik.backend=dev-petclinic" --label "traefik.frontend.rule=Host:dev.petclinic.docker.localhost" -d --network=${LDOP_NETWORK_NAME} --name dev-petclinic petclinic-tomcat'
}
}
stage('Smoke test dev') {
agent {
docker {
image 'maven:3.5.0'
args '--network=${LDOP_NETWORK_NAME}'
}
}
steps {
sh "cd regression-suite"
sh "mvn clean -B test -DPETCLINIC_URL=http://dev-petclinic:8080/petclinic/"
echo "Should be accessible at http://localhost:18888/petclinic"
}
}
stage('Deploy to qa') {
agent any
steps {
sh 'docker rm -f qa-petclinic || true'
sh 'docker run --label "traefik.backend=qa-petclinic" --label "traefik.frontend.rule=Host:qa.petclinic.docker.localhost" -d --network=${LDOP_NETWORK_NAME} --name qa-petclinic petclinic-tomcat'
}
}
stage('Smoke test qa') {
agent {
docker {
image 'maven:3.5.0'
args '--network=${LDOP_NETWORK_NAME}'
}
}
steps {
sh "cd regression-suite"
sh "mvn clean -B test -DPETCLINIC_URL=http://qa-petclinic:8080/petclinic/"
echo "Should be accessible at http://localhost:18889/petclinic"
input 'Deploy to Prod?'
}
}
stage('Deploy to prod') {
agent any
steps {
sh 'docker rm -f prod-petclinic || true'
sh 'docker run --label "traefik.backend=prod-petclinic" --label "traefik.frontend.rule=Host:prod.petclinic.docker.localhost" -d --network=${LDOP_NETWORK_NAME} --name prod-petclinic petclinic-tomcat'
}
}
stage('Smoke Test prod') {
agent {
docker {
image 'maven:3.5.0'
args '--network=${LDOP_NETWORK_NAME}'
}
}
steps {
sh "cd regression-suite"
sh "mvn clean -B test -DPETCLINIC_URL=http://prod-petclinic:8080/petclinic/"
echo "Should be accessible at http://localhost:18890/petclinic"
}
}
}
}

View file

@ -0,0 +1,154 @@
pipeline {
agent none
stages {
stage('Build') {
agent {
docker {
image 'maven:3.5.0'
args '-e INITIAL_ADMIN_USER -e INITIAL_ADMIN_PASSWORD --network=${LDOP_NETWORK_NAME}'
}
}
steps {
configFileProvider(
[configFile(fileId: 'nexus', variable: 'MAVEN_SETTINGS')]) {
sh 'mvn -s $MAVEN_SETTINGS clean deploy -DskipTests=true -B'
}
}
}
stage('Sonar') {
agent {
docker {
image 'sebp/sonar-runner'
args '-e SONAR_ACCOUNT_LOGIN -e SONAR_ACCOUNT_PASSWORD -e SONAR_DB_URL -e SONAR_DB_LOGIN -e SONAR_DB_PASSWORD --network=${LDOP_NETWORK_NAME}'
}
}
steps {
sh '/opt/sonar-runner-2.4/bin/sonar-runner -e -D sonar.login=${SONAR_ACCOUNT_LOGIN} -D sonar.password=${SONAR_ACCOUNT_PASSWORD} -D sonar.jdbc.url=${SONAR_DB_URL} -D sonar.jdbc.username=${SONAR_DB_LOGIN} -D sonar.jdbc.password=${SONAR_DB_PASSWORD}'
}
}
stage('Build container') {
agent any
steps {
sh 'docker build -t petclinic-tomcat .'
}
}
stage('Run local container') {
agent any
steps {
sh 'docker rm -f petclinic-tomcat-temp || true'
sh 'docker run -d --network=${LDOP_NETWORK_NAME} --name petclinic-tomcat-temp petclinic-tomcat'
}
}
stage('Smoke-Test & OWASP Security Scan') {
agent {
docker {
image 'maven:3.5.0'
args '--network=${LDOP_NETWORK_NAME}'
}
}
steps {
sh "cd regression-suite"
sh "mvn clean -B test -DPETCLINIC_URL=http://petclinic-tomcat:8080/petclinic/"
}
}
stage('Stop local container') {
agent any
steps {
sh 'docker rm -f petclinic-tomcat-temp || true'
}
}
stage('Deploy to dev') {
agent any
steps {
sh 'docker rm -f dev-petclinic || true'
sh 'docker run --label "traefik.enable=true" --label "traefik.backend=dev-petclinic" --label "traefik.frontend.rule=Host:dev.petclinic.localhost" -d --network=${LDOP_NETWORK_NAME} --name dev-petclinic petclinic-tomcat'
}
}
stage('Smoke test dev') {
agent {
docker {
image 'maven:3.5.0'
args '--network=${LDOP_NETWORK_NAME}'
}
}
steps {
sh "cd regression-suite"
sh "mvn clean -B test -DPETCLINIC_URL=http://dev-petclinic:8080/petclinic/"
echo "Should be accessible at http://localhost:18888/petclinic"
}
}
stage('Deploy to qa') {
agent any
steps {
sh 'docker rm -f qa-petclinic || true'
sh 'docker run --label "traefik.enable=true" --label "traefik.backend=qa-petclinic" --label "traefik.frontend.rule=Host:qa.petclinic.localhost" -d --network=${LDOP_NETWORK_NAME} --name qa-petclinic petclinic-tomcat'
}
}
stage('Smoke test qa') {
agent {
docker {
image 'maven:3.5.0'
args '--network=${LDOP_NETWORK_NAME}'
}
}
steps {
sh "cd regression-suite"
sh "mvn clean -B test -DPETCLINIC_URL=http://qa-petclinic:8080/petclinic/"
echo "Should be accessible at http://localhost:18889/petclinic"
input 'Deploy to Prod?'
}
}
stage('Deploy to ProdA-Green') {
agent any
steps {
sh 'docker rm -f proda-petclinic-green || true'
sh 'docker run --label "traefik.enable=true" --label "traefik.backend=prod-petclinic" --label "traefik.frontend.rule=Host:prod.petclinic.localhost" -d --network=${LDOP_NETWORK_NAME} --name proda-petclinic-green petclinic-tomcat'
}
}
stage('Smoke test ProdA-Green') {
agent {
docker {
image 'maven:3.5.0'
args '--network=${LDOP_NETWORK_NAME}'
}
}
steps {
sh "cd regression-suite"
sh "mvn clean -B test -DPETCLINIC_URL=http://proda-petclinic-green:8080/petclinic/"
}
}
stage('Deploy to ProdA') {
agent any
steps {
sh 'docker rm -f proda-petclinic || true'
sh 'docker container rename proda-petclinic-green proda-petclinic'
}
}
stage('Deploy to ProdB-Green') {
agent any
steps {
sh 'docker rm -f prodb-petclinic-green || true'
sh 'docker run --label "traefik.enable=true" --label "traefik.backend=prod-petclinic" --label "traefik.frontend.rule=Host:prod.petclinic.localhost" -d --network=${LDOP_NETWORK_NAME} --name prodb-petclinic-green petclinic-tomcat'
}
}
stage('Smoke test ProdB-Green') {
agent {
docker {
image 'maven:3.5.0'
args '--network=${LDOP_NETWORK_NAME}'
}
}
steps {
sh "cd regression-suite"
sh "mvn clean -B test -DPETCLINIC_URL=http://prodb-petclinic-green:8080/petclinic/"
}
}
stage('Deploy to ProdB') {
agent any
steps {
sh 'docker rm -f prodb-petclinic || true'
sh 'docker container rename prodb-petclinic-green prodb-petclinic'
}
}
}
}