mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-19 05:55:51 +00:00
Decomposed blue/green into stages
This commit is contained in:
parent
7ff8791b8d
commit
13607d2edc
2 changed files with 94 additions and 28 deletions
46
Jenkinsfile
vendored
46
Jenkinsfile
vendored
|
@ -154,7 +154,7 @@ pipeline {
|
|||
}
|
||||
}
|
||||
|
||||
stage('Blue/Green deploy to prod') {
|
||||
stage('Blue/Green Prod Deploy') {
|
||||
when {
|
||||
branch 'master'
|
||||
}
|
||||
|
@ -169,7 +169,49 @@ pipeline {
|
|||
file(credentialsId: 'petclinic-deploy-key', variable: 'DEPLOY_KEY_PATH')
|
||||
]) {
|
||||
script {
|
||||
sh "TAG=${TAG} blue-green/blue-green-deploy"
|
||||
sh "TAG=${TAG} blue-green/blue-green deploy"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Blue/Green Prod Regression Test') {
|
||||
when {
|
||||
branch 'master'
|
||||
}
|
||||
agent {
|
||||
dockerfile {
|
||||
filename "blue-green/Dockerfile"
|
||||
}
|
||||
}
|
||||
steps {
|
||||
withCredentials([
|
||||
usernamePassword(credentialsId: 'aws', usernameVariable: 'AWS_ACCESS_KEY_ID', passwordVariable: 'AWS_SECRET_ACCESS_KEY'),
|
||||
file(credentialsId: 'petclinic-deploy-key', variable: 'DEPLOY_KEY_PATH')
|
||||
]) {
|
||||
script {
|
||||
sh "TAG=${TAG} blue-green/blue-green test"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Blue/Green Prod Toggle Load Balancer') {
|
||||
when {
|
||||
branch 'master'
|
||||
}
|
||||
agent {
|
||||
dockerfile {
|
||||
filename "blue-green/Dockerfile"
|
||||
}
|
||||
}
|
||||
steps {
|
||||
withCredentials([
|
||||
usernamePassword(credentialsId: 'aws', usernameVariable: 'AWS_ACCESS_KEY_ID', passwordVariable: 'AWS_SECRET_ACCESS_KEY'),
|
||||
file(credentialsId: 'petclinic-deploy-key', variable: 'DEPLOY_KEY_PATH')
|
||||
]) {
|
||||
script {
|
||||
sh "TAG=${TAG} blue-green/blue-green toggle"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,17 +28,6 @@
|
|||
|
||||
export AWS_DEFAULT_REGION='us-west-2'
|
||||
|
||||
deploy() {
|
||||
FQDN="$1"
|
||||
ssh -i ${DEPLOY_KEY_PATH} -o StrictHostKeyChecking=no ec2-user@${FQDN} "docker rm -f petclinic || true"
|
||||
ssh -i ${DEPLOY_KEY_PATH} -o StrictHostKeyChecking=no ec2-user@${FQDN} "docker run -d -p 80:8080 --name petclinic ${IMAGE}:${TAG}"
|
||||
}
|
||||
|
||||
smoke_test() {
|
||||
FQDN="$1"
|
||||
cd ./regression-suite && mvn clean -B test -DPETCLINIC_URL="${FQDN}" && cd -
|
||||
}
|
||||
|
||||
LOAD_BALANCER_ARN=$(aws elbv2 describe-load-balancers --names prod-petclinic | jq -r '.LoadBalancers|.[0]|.LoadBalancerArn')
|
||||
ATTACHED_LISTENER_ARN=$(aws elbv2 describe-listeners --load-balancer-arn "${LOAD_BALANCER_ARN}" | jq -r '.Listeners|.[0]|.ListenerArn')
|
||||
ATTACHED_LISTENER_TARGET_GROUP_ARN=$(aws elbv2 describe-listeners --load-balancer-arn "${LOAD_BALANCER_ARN}" | jq -r '.Listeners|.[0]|.DefaultActions|.[0]|.TargetGroupArn')
|
||||
|
@ -47,14 +36,29 @@ PRODB_TARGET_GROUP_ARN=$(aws elbv2 describe-target-groups --names prodb-petclini
|
|||
|
||||
if [[ "${ATTACHED_LISTENER_TARGET_GROUP_ARN}" == "${PRODA_TARGET_GROUP_ARN}" ]]; then
|
||||
NEW_TARGET_GROUP_ARN=${PRODB_TARGET_GROUP_ARN}
|
||||
deploy "prodb.petclinic.liatr.io"
|
||||
smoke_test "http://prodb.petclinic.liatr.io/petclinic"
|
||||
FQDN="prodb.petclinic.liatr.io"
|
||||
else
|
||||
NEW_TARGET_GROUP_ARN=${PRODA_TARGET_GROUP_ARN}
|
||||
deploy "proda.petclinic.liatr.io"
|
||||
smoke_test "http://proda.petclinic.liatr.io/petclinic"
|
||||
FQDN="proda.petclinic.liatr.io"
|
||||
fi
|
||||
|
||||
remote_exec() {
|
||||
ssh -i ${DEPLOY_KEY_PATH} -o StrictHostKeyChecking=no ec2-user@${FQDN} "$1"
|
||||
}
|
||||
|
||||
deploy() {
|
||||
echo "Deploying ${IMAGE}:${TAG} to ${FQDN}"
|
||||
remote_exec "docker rm -f petclinic || true"
|
||||
remote_exec "docker run -d -p 80:8080 --name petclinic ${IMAGE}:${TAG}"
|
||||
}
|
||||
|
||||
regr_test() {
|
||||
echo "Running regression test suite on ${FQDN}/petclinic"
|
||||
cd ./regression-suite && mvn clean -B test -DPETCLINIC_URL="http://${FQDN}/petclinic" && cd -
|
||||
}
|
||||
|
||||
toggle_lb() {
|
||||
echo "Toggling load balancer"
|
||||
if [[ "${ATTACHED_LISTENER_ARN}" != "null" ]]; then
|
||||
echo "Deleting previous listener: ${ATTACHED_LISTENER_ARN}"
|
||||
aws elbv2 delete-listener --listener-arn "${ATTACHED_LISTENER_ARN}"
|
||||
|
@ -66,3 +70,23 @@ aws elbv2 create-listener \
|
|||
--protocol "HTTP" \
|
||||
--port "80" \
|
||||
--default-actions "Type=forward,TargetGroupArn=${NEW_TARGET_GROUP_ARN}"
|
||||
}
|
||||
|
||||
ACTION=$1
|
||||
case "$ACTION" in
|
||||
deploy)
|
||||
deploy
|
||||
;;
|
||||
test)
|
||||
regr_test
|
||||
;;
|
||||
toggle)
|
||||
toggle_lb
|
||||
;;
|
||||
"")
|
||||
deploy; regr_test; toggle_lb;
|
||||
;;
|
||||
*)
|
||||
echo "Unknown action $1. Exiting."
|
||||
exit 1
|
||||
esac
|
Loading…
Reference in a new issue