mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-21 07:15:49 +00:00
Fixed indentation
This commit is contained in:
parent
1f631a317d
commit
7ff8791b8d
1 changed files with 32 additions and 30 deletions
|
@ -1,40 +1,42 @@
|
|||
#!/bin/bash -xe
|
||||
|
||||
# This script executes a blue/green deployment on the petclinic production infrastructure.
|
||||
# This script executes a blue/green deployment on the petclinic
|
||||
# production infrastructure.
|
||||
#
|
||||
# Production infrastructure consists of:
|
||||
# - An application load balancer (prod-petclinic)
|
||||
# - An application load balancer (prod-petclinic)
|
||||
# - Two target groups (proda-petclinic, prodb-petclinic)
|
||||
# - A single t2.micro ec2 instance in each target group (proda.petclinic.liatr.io, prodb.petclinic.liatr.io)
|
||||
# - A single t2.micro ec2 instance in each target group
|
||||
#
|
||||
# One of the two target groups should be attached to the ALB at any given time via a Listener
|
||||
# One of the two target groups should be attached to the ALB at any given timel
|
||||
# via a Listener
|
||||
#
|
||||
# To perform a blue/green deployment, we:
|
||||
# - Figure out which target group is detached
|
||||
# - Deploy the application to each instance in the detached target group (only 1 instance in this case)
|
||||
# - Run smoke tests on the newly deployed applications
|
||||
# - Delete the current attached listener
|
||||
# - Figure out which target group is detached
|
||||
# - Deploy the application to each instance in the detached target group
|
||||
# - Run smoke tests on the newly deployed applications
|
||||
# - Delete the current attached listener
|
||||
# - Attach a new listener that forwards to the target group we deployed to.
|
||||
#
|
||||
# Expected environment variables:
|
||||
# - DEPLOY_KEY_PATH Private key used to shell deploy to petclinic prod instances
|
||||
# - AWS_ACCESS_ID_ID
|
||||
# - AWS_SECRET_ACCESS_KEY For modifying load balancer resources
|
||||
# - IMAGE Dockerhub repo to deploy from
|
||||
# - TAG Version of image to deploy
|
||||
# - DEPLOY_KEY_PATH Private key to access prod instances
|
||||
# - AWS_ACCESS_ID_ID
|
||||
# - AWS_SECRET_ACCESS_KEY For modifying load balancer resources
|
||||
# - IMAGE Dockerhub repo to deploy from
|
||||
# - TAG Version of image to deploy
|
||||
#
|
||||
|
||||
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}"
|
||||
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 -
|
||||
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')
|
||||
|
@ -44,23 +46,23 @@ PRODA_TARGET_GROUP_ARN=$(aws elbv2 describe-target-groups --names proda-petclini
|
|||
PRODB_TARGET_GROUP_ARN=$(aws elbv2 describe-target-groups --names prodb-petclinic | jq -r '.TargetGroups|.[0]|.TargetGroupArn')
|
||||
|
||||
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"
|
||||
NEW_TARGET_GROUP_ARN=${PRODB_TARGET_GROUP_ARN}
|
||||
deploy "prodb.petclinic.liatr.io"
|
||||
smoke_test "http://prodb.petclinic.liatr.io/petclinic"
|
||||
else
|
||||
NEW_TARGET_GROUP_ARN=${PRODA_TARGET_GROUP_ARN}
|
||||
deploy "proda.petclinic.liatr.io"
|
||||
smoke_test "http://proda.petclinic.liatr.io/petclinic"
|
||||
NEW_TARGET_GROUP_ARN=${PRODA_TARGET_GROUP_ARN}
|
||||
deploy "proda.petclinic.liatr.io"
|
||||
smoke_test "http://proda.petclinic.liatr.io/petclinic"
|
||||
fi
|
||||
|
||||
if [[ "${ATTACHED_LISTENER_ARN}" != "null" ]]; then
|
||||
echo "Deleting previous listener: ${ATTACHED_LISTENER_ARN}"
|
||||
aws elbv2 delete-listener --listener-arn "${ATTACHED_LISTENER_ARN}"
|
||||
echo "Deleting previous listener: ${ATTACHED_LISTENER_ARN}"
|
||||
aws elbv2 delete-listener --listener-arn "${ATTACHED_LISTENER_ARN}"
|
||||
fi
|
||||
|
||||
echo "Attaching listener with target group: ${NEW_TARGET_GROUP_ARN}"
|
||||
aws elbv2 create-listener \
|
||||
--load-balancer-arn "${LOAD_BALANCER_ARN}" \
|
||||
--protocol "HTTP" \
|
||||
--port "80" \
|
||||
--default-actions "Type=forward,TargetGroupArn=${NEW_TARGET_GROUP_ARN}"
|
||||
--load-balancer-arn "${LOAD_BALANCER_ARN}" \
|
||||
--protocol "HTTP" \
|
||||
--port "80" \
|
||||
--default-actions "Type=forward,TargetGroupArn=${NEW_TARGET_GROUP_ARN}"
|
||||
|
|
Loading…
Reference in a new issue