mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-19 05:55:51 +00:00
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:
parent
c9b33de94d
commit
2a012de048
2 changed files with 293 additions and 120 deletions
|
@ -1,5 +1,9 @@
|
||||||
|
#!/bin/env groovy
|
||||||
pipeline {
|
pipeline {
|
||||||
agent none
|
agent none
|
||||||
|
environment {
|
||||||
|
IMAGE = "liatrio/petclinic-tomcat"
|
||||||
|
}
|
||||||
stages {
|
stages {
|
||||||
stage('Build') {
|
stage('Build') {
|
||||||
agent {
|
agent {
|
||||||
|
@ -25,6 +29,21 @@ pipeline {
|
||||||
steps {
|
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}'
|
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') {
|
stage('Build container') {
|
||||||
agent any
|
agent any
|
||||||
|
@ -34,8 +53,6 @@ pipeline {
|
||||||
if ( env.BRANCH_NAME == 'master' ) {
|
if ( env.BRANCH_NAME == 'master' ) {
|
||||||
pom = readMavenPom file: 'pom.xml'
|
pom = readMavenPom file: 'pom.xml'
|
||||||
containerVersion = pom.version
|
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} ."
|
sh "docker build -t liatrio/petclinic-tomcat:${containerVersion} ."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -85,8 +102,14 @@ pipeline {
|
||||||
stage('Deploy to dev') {
|
stage('Deploy to dev') {
|
||||||
agent any
|
agent any
|
||||||
steps {
|
steps {
|
||||||
sh 'docker rm -f dev-petclinic || true'
|
script {
|
||||||
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'
|
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') {
|
stage('Smoke test dev') {
|
||||||
|
@ -98,18 +121,23 @@ pipeline {
|
||||||
}
|
}
|
||||||
steps {
|
steps {
|
||||||
sh "cd regression-suite"
|
sh "cd regression-suite"
|
||||||
sh "mvn clean -B test -DPETCLINIC_URL=http://dev-petclinic:8080/petclinic/"
|
sh "mvn clean -B test -DPETCLINIC_URL=https://dev-petclinic.liatr.io/petclinic"
|
||||||
echo "Should be accessible at http://localhost:18888/petclinic"
|
echo "Should be accessible at https://dev-petclinic.liatr.io/petclinic"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stage('Deploy to qa') {
|
stage('Deploy to qa') {
|
||||||
|
when {
|
||||||
|
branch 'master'
|
||||||
|
}
|
||||||
agent any
|
agent any
|
||||||
steps {
|
steps {
|
||||||
sh 'docker rm -f qa-petclinic || true'
|
deployToEnvironment("ec2-user", "qa-petclinic.liatr.io", "petclinic-deploy-key", "${env.IMAGE}", "${containerVersion}", "spring-petclinic", "qa-petclinic.liatr.io")
|
||||||
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') {
|
stage('Smoke test qa') {
|
||||||
|
when {
|
||||||
|
branch 'master'
|
||||||
|
}
|
||||||
agent {
|
agent {
|
||||||
docker {
|
docker {
|
||||||
image 'maven:3.5.0'
|
image 'maven:3.5.0'
|
||||||
|
@ -118,19 +146,24 @@ pipeline {
|
||||||
}
|
}
|
||||||
steps {
|
steps {
|
||||||
sh "cd regression-suite"
|
sh "cd regression-suite"
|
||||||
sh "mvn clean -B test -DPETCLINIC_URL=http://qa-petclinic:8080/petclinic/"
|
sh "mvn clean -B test -DPETCLINIC_URL=https://qa-petclinic.liatr.io/petclinic"
|
||||||
echo "Should be accessible at http://localhost:18889/petclinic"
|
echo "Should be accessible at https://qa-petclinic.liatr.io/petclinic"
|
||||||
input 'Deploy to Prod?'
|
input 'Deploy to Prod?'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stage('Deploy to ProdA-Green') {
|
stage('Deploy to Prod') {
|
||||||
|
when {
|
||||||
|
branch 'master'
|
||||||
|
}
|
||||||
agent any
|
agent any
|
||||||
steps {
|
steps {
|
||||||
sh 'docker rm -f proda-petclinic-green || true'
|
deployToEnvironment("ec2-user", "petclinic.liatr.io", "petclinic-deploy-key", "${env.IMAGE}", "${containerVersion}", "prod-petclinic", "petclinic.liatr.io")
|
||||||
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') {
|
stage('Smoke test Prod') {
|
||||||
|
when {
|
||||||
|
branch 'master'
|
||||||
|
}
|
||||||
agent {
|
agent {
|
||||||
docker {
|
docker {
|
||||||
image 'maven:3.5.0'
|
image 'maven:3.5.0'
|
||||||
|
@ -139,40 +172,7 @@ pipeline {
|
||||||
}
|
}
|
||||||
steps {
|
steps {
|
||||||
sh "cd regression-suite"
|
sh "cd regression-suite"
|
||||||
sh "mvn clean -B test -DPETCLINIC_URL=http://proda-petclinic-green:8080/petclinic/"
|
sh "mvn clean -B test -DPETCLINIC_URL=https://petclinic.liatr.io/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'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
173
jenkinsfiles/full-demo-aws/full-demo-aws
Normal file
173
jenkinsfiles/full-demo-aws/full-demo-aws
Normal 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'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue