mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-22 15:55: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
|
#!/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:
|
# Production infrastructure consists of:
|
||||||
# - An application load balancer (prod-petclinic)
|
# - An application load balancer (prod-petclinic)
|
||||||
# - Two target groups (proda-petclinic, prodb-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:
|
# To perform a blue/green deployment, we:
|
||||||
# - Figure out which target group is detached
|
# - Figure out which target group is detached
|
||||||
# - Deploy the application to each instance in the detached target group (only 1 instance in this case)
|
# - Deploy the application to each instance in the detached target group
|
||||||
# - Run smoke tests on the newly deployed applications
|
# - Run smoke tests on the newly deployed applications
|
||||||
# - Delete the current attached listener
|
# - Delete the current attached listener
|
||||||
# - Attach a new listener that forwards to the target group we deployed to.
|
# - Attach a new listener that forwards to the target group we deployed to.
|
||||||
#
|
#
|
||||||
# Expected environment variables:
|
# Expected environment variables:
|
||||||
# - DEPLOY_KEY_PATH Private key used to shell deploy to petclinic prod instances
|
# - DEPLOY_KEY_PATH Private key to access prod instances
|
||||||
# - AWS_ACCESS_ID_ID
|
# - AWS_ACCESS_ID_ID
|
||||||
# - AWS_SECRET_ACCESS_KEY For modifying load balancer resources
|
# - AWS_SECRET_ACCESS_KEY For modifying load balancer resources
|
||||||
# - IMAGE Dockerhub repo to deploy from
|
# - IMAGE Dockerhub repo to deploy from
|
||||||
# - TAG Version of image to deploy
|
# - TAG Version of image to deploy
|
||||||
#
|
#
|
||||||
|
|
||||||
export AWS_DEFAULT_REGION='us-west-2'
|
export AWS_DEFAULT_REGION='us-west-2'
|
||||||
|
|
||||||
deploy() {
|
deploy() {
|
||||||
FQDN="$1"
|
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 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}"
|
ssh -i ${DEPLOY_KEY_PATH} -o StrictHostKeyChecking=no ec2-user@${FQDN} "docker run -d -p 80:8080 --name petclinic ${IMAGE}:${TAG}"
|
||||||
}
|
}
|
||||||
|
|
||||||
smoke_test() {
|
smoke_test() {
|
||||||
FQDN="$1"
|
FQDN="$1"
|
||||||
cd ./regression-suite && mvn clean -B test -DPETCLINIC_URL="${FQDN}" && cd -
|
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')
|
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')
|
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
|
if [[ "${ATTACHED_LISTENER_TARGET_GROUP_ARN}" == "${PRODA_TARGET_GROUP_ARN}" ]]; then
|
||||||
NEW_TARGET_GROUP_ARN=${PRODB_TARGET_GROUP_ARN}
|
NEW_TARGET_GROUP_ARN=${PRODB_TARGET_GROUP_ARN}
|
||||||
deploy "prodb.petclinic.liatr.io"
|
deploy "prodb.petclinic.liatr.io"
|
||||||
smoke_test "http://prodb.petclinic.liatr.io/petclinic"
|
smoke_test "http://prodb.petclinic.liatr.io/petclinic"
|
||||||
else
|
else
|
||||||
NEW_TARGET_GROUP_ARN=${PRODA_TARGET_GROUP_ARN}
|
NEW_TARGET_GROUP_ARN=${PRODA_TARGET_GROUP_ARN}
|
||||||
deploy "proda.petclinic.liatr.io"
|
deploy "proda.petclinic.liatr.io"
|
||||||
smoke_test "http://proda.petclinic.liatr.io/petclinic"
|
smoke_test "http://proda.petclinic.liatr.io/petclinic"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "${ATTACHED_LISTENER_ARN}" != "null" ]]; then
|
if [[ "${ATTACHED_LISTENER_ARN}" != "null" ]]; then
|
||||||
echo "Deleting previous listener: ${ATTACHED_LISTENER_ARN}"
|
echo "Deleting previous listener: ${ATTACHED_LISTENER_ARN}"
|
||||||
aws elbv2 delete-listener --listener-arn "${ATTACHED_LISTENER_ARN}"
|
aws elbv2 delete-listener --listener-arn "${ATTACHED_LISTENER_ARN}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Attaching listener with target group: ${NEW_TARGET_GROUP_ARN}"
|
echo "Attaching listener with target group: ${NEW_TARGET_GROUP_ARN}"
|
||||||
aws elbv2 create-listener \
|
aws elbv2 create-listener \
|
||||||
--load-balancer-arn "${LOAD_BALANCER_ARN}" \
|
--load-balancer-arn "${LOAD_BALANCER_ARN}" \
|
||||||
--protocol "HTTP" \
|
--protocol "HTTP" \
|
||||||
--port "80" \
|
--port "80" \
|
||||||
--default-actions "Type=forward,TargetGroupArn=${NEW_TARGET_GROUP_ARN}"
|
--default-actions "Type=forward,TargetGroupArn=${NEW_TARGET_GROUP_ARN}"
|
||||||
|
|
Loading…
Reference in a new issue