LDOP-302 full demo (#23)

* LDOP-302 setting up pipeline skeleton

* trying to fix spacing

* trying to fix spacing

* LDOP-302 Updated full-demo-aws to use the updated shared library function params.

* removing some environment variables

* bringing full-demo pipeline to top directory

* fixing tag

* reverting root Jenkinsfile and moving changes to full demo

* Fixed the image tag for deployments

* added script block around if statement

* Change env.branch to env.BRANCH_NAME

* Changed traeffik front end rules in jenkinsfiles

* replaced dev with qa in deploy to qa step

* replaced dev to qa

* fixed prod uri for production instances

* testing master branch logic

* removed prod b and changed prod stages

* LDOP-302 Update conditions for master branch

* Fixed backwards deploy logic for dev
This commit is contained in:
Eddie Bracho 2017-09-15 13:26:31 -07:00 committed by GitHub
parent c9b33de94d
commit 2a012de048
2 changed files with 293 additions and 120 deletions

View file

@ -1,31 +1,50 @@
#!/bin/env groovy
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'
}
}
agent none
environment {
IMAGE = "liatrio/petclinic-tomcat"
}
stages {
stage('Build') {
agent {
docker {
image 'maven:3.5.0'
args '-e INITIAL_ADMIN_USER -e INITIAL_ADMIN_PASSWORD --network=${LDOP_NETWORK_NAME}'
}
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}'
}
}
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('Get Artifact') {
agent {
docker {
image 'maven:3.5.0'
args '-e INITIAL_ADMIN_USER -e INITIAL_ADMIN_PASSWORD --network=${LDOP_NETWORK_NAME}'
}
}
steps {
sh 'mvn clean'
script {
pom = readMavenPom file: 'pom.xml'
getArtifact(pom.groupId, pom.artifactId, pom.version)
}
}
}
stage('Build container') {
agent any
steps {
@ -34,8 +53,6 @@ pipeline {
if ( env.BRANCH_NAME == 'master' ) {
pom = readMavenPom file: 'pom.xml'
containerVersion = pom.version
/*Need to check if version exists in the future*/
/*failIfVersionExists("liatrio","petclinic-tomcat",containerVersion)*/
sh "docker build -t liatrio/petclinic-tomcat:${containerVersion} ."
}
}
@ -49,22 +66,22 @@ pipeline {
}
}
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/"
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'
}
agent any
steps {
sh 'docker rm -f petclinic-tomcat-temp || true'
}
}
stage('Push to dockerhub') {
agent any
@ -83,97 +100,80 @@ pipeline {
}
}
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'
agent any
steps {
script {
if ( env.BRANCH_NAME == 'master' ) {
deployToEnvironment("ec2-user", "dev-petclinic.liatr.io", "petclinic-deploy-key", "${env.IMAGE}", "${containerVersion}", "spring-petclinic", "dev-petclinic.liatr.io")
}
else{
deployToEnvironment("ec2-user", "dev-petclinic.liatr.io", "petclinic-deploy-key", "${env.IMAGE}", "${env.BRANCH_NAME}", "spring-petclinic", "dev-petclinic.liatr.io")
}
}
}
}
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"
agent {
docker {
image 'maven:3.5.0'
args '--network=${LDOP_NETWORK_NAME}'
}
}
steps {
sh "cd regression-suite"
sh "mvn clean -B test -DPETCLINIC_URL=https://dev-petclinic.liatr.io/petclinic"
echo "Should be accessible at https://dev-petclinic.liatr.io/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'
}
when {
branch 'master'
}
agent any
steps {
deployToEnvironment("ec2-user", "qa-petclinic.liatr.io", "petclinic-deploy-key", "${env.IMAGE}", "${containerVersion}", "spring-petclinic", "qa-petclinic.liatr.io")
}
}
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?'
when {
branch 'master'
}
agent {
docker {
image 'maven:3.5.0'
args '--network=${LDOP_NETWORK_NAME}'
}
}
steps {
sh "cd regression-suite"
sh "mvn clean -B test -DPETCLINIC_URL=https://qa-petclinic.liatr.io/petclinic"
echo "Should be accessible at https://qa-petclinic.liatr.io/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('Deploy to Prod') {
when {
branch 'master'
}
agent any
steps {
deployToEnvironment("ec2-user", "petclinic.liatr.io", "petclinic-deploy-key", "${env.IMAGE}", "${containerVersion}", "prod-petclinic", "petclinic.liatr.io")
}
}
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'
stage('Smoke test Prod') {
when {
branch 'master'
}
agent {
docker {
image 'maven:3.5.0'
args '--network=${LDOP_NETWORK_NAME}'
}
}
steps {
sh "cd regression-suite"
sh "mvn clean -B test -DPETCLINIC_URL=https://petclinic.liatr.io/petclinic"
}
}
}
}
}

View file

@ -0,0 +1,173 @@
#!/bin/env groovy
pipeline {
agent none
environment {
IMAGE = "liatrio/petclinic-tomcat"
}
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('Get Artifact') {
agent {
docker {
image 'maven:3.5.0'
args '-e INITIAL_ADMIN_USER -e INITIAL_ADMIN_PASSWORD --network=${LDOP_NETWORK_NAME}'
}
}
steps {
sh 'mvn clean'
script {
pom = readMavenPom file: 'pom.xml'
if (params.version == 'UNSPECIFIED') {
getArtifact(pom.groupId, pom.artifactId, pom.version)
} else {
getArtifact(pom.groupId, pom.artifactId, params.VERSION)
}
}
}
}
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 {
deployToEnvironment("ec2-user", "dev-petclinic.liatr.io", "petclinic-deploy-key", "${env.IMAGE}", "${env.TAG}", "spring-petclinic", "dev-petclinic.liatr.io/petclinic")
}
}
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 {
deployToEnvironment("ec2-user", "qa-petclinic.liatr.io", "petclinic-deploy-key", "${env.IMAGE}", "${env.TAG}", "spring-petclinic", "qa-petclinic.liatr.io/petclinic")
}
}
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 {
deployToEnvironment("ec2-user", "prod-petclinic.liatr.io", "petclinic-deploy-key", "${env.IMAGE}", "${env.TAG}", "spring-petclinic", "prod-petclinic.liatr.io/petclinic", "petclinic-prod")
}
}
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 {
deployToEnvironment("ec2-user", "prod-petclinic.liatr.io", "petclinic-deploy-key", "${env.IMAGE}", "${env.TAG}", "spring-petclinic", "prod-petclinic.liatr.io/petclinic", "petclinic-prod")
}
}
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'
}
}
}
}