-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.bash
executable file
·67 lines (51 loc) · 2.18 KB
/
deploy.bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source "$SCRIPT_DIR/constants.env"
if [ "$#" -lt 1 ]; then
cat <<HEREDOC
Usage: $(basename ${BASH_SOURCE[0]}) <environment>
Deploys the given $APPLICATION environment
HEREDOC
exit 1
fi
PATH="$PATH:$SCRIPT_DIR/bin"
stackName="$1-$APPLICATION"
accountId=$(aws sts get-caller-identity --output json | jq -r '.Account')
if [ -z "$accountId" ]; then # sandbox account
echo "authorized aws account id is not recognized, make sure you're logged in" > /dev/stderr
exit 1
fi
if ! stack-exists "subdomain-$APPLICATION-dns"; then
echo 'DNS stack not found. create one by following the instructions here: https://github.com/openstax/subdomains' > /dev/stderr
exit 1
fi
if ! stack-exists "subdomain-$APPLICATION-cert"; then
echo 'SSL cert stack not found. create one by following the instructions here: https://github.com/openstax/subdomains' > /dev/stderr
exit 1
fi
# =======
# main deployment includes alt region for failovers
# =======
aws cloudformation deploy \
--region us-east-2 \
--no-fail-on-empty-changeset \
--template-file "$SCRIPT_DIR/deployment-alt-region.cfn.yml" \
--stack-name "$stackName" \
--tags "Project=$PROJECT" "Application=$APPLICATION" "Environment=$1" "Owner=$OWNER"
# clouformation cannot reference exports across regions, so these are applied like this
replicaBucketWebsiteURL=$(AWS_DEFAULT_REGION=us-east-2 get-stack-param "$stackName" ReplicaBucketWebsiteURL)
aws cloudformation deploy \
--region us-east-1 \
--template-file "$SCRIPT_DIR/deployment.cfn.yml" \
--stack-name "$stackName" \
--capabilities CAPABILITY_NAMED_IAM \
--parameter-overrides "EnvName=$1" "Application=$APPLICATION" "ReplicaBucketWebsiteURL=$replicaBucketWebsiteURL" \
--tags "Project=$PROJECT" "Application=$APPLICATION" "Environment=$1" "Owner=$OWNER"
domainName=$(get-stack-param "$stackName" DistributionDomainName)
distributionId=$(get-stack-param "$stackName" DistributionId)
aws cloudfront create-invalidation --distribution-id "$distributionId" --paths "/*" --output text --query "Invalidation.Status"
# =======
# done
# =======
echo "deployed: $domainName";