-
Notifications
You must be signed in to change notification settings - Fork 7
/
deploy.sh
executable file
·105 lines (84 loc) · 2.34 KB
/
deploy.sh
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/bash
set -e
echo "START $0 $(date)"
STAGE=dev
# Usage info
show_help() {
cat << EOF
Usage: ${0##*/} [-p]
By default, deploy to dev environment on AWS account 812644853088
-p PRODUCTION 192458993663
-d DEMO 915001051872
EOF
}
while getopts "pd" opt
do
case $opt in
p)
echo "PRODUCTION" >&2
STAGE=prod
;;
d)
echo "DEMO" >&2
STAGE=demo
;;
*)
show_help >&2
exit 1
;;
esac
done
AWS_PROFILE=uneet-$STAGE
shift "$((OPTIND-1))" # Discard the options and sentinel --
export COMMIT=$(git rev-parse --short HEAD)
# Run deploy hooks
for hook in deploy-hooks/*
do
[[ -x $hook ]] || continue
if "$hook"
then
echo OK: "$hook"
else
echo FAIL: "$hook"
exit 1
fi
done
if ! aws configure --profile $AWS_PROFILE list
then
echo Profile $AWS_PROFILE does not exist >&2
if ! test "$AWS_ACCESS_KEY_ID"
then
echo Missing $AWS_ACCESS_KEY_ID >&2
exit 1
fi
echo Attempting to setup one from the environment >&2
aws configure set profile.uneet-${STAGE}.aws_access_key_id $AWS_ACCESS_KEY_ID
aws configure set profile.uneet-${STAGE}.aws_secret_access_key $AWS_SECRET_ACCESS_KEY
aws configure set profile.uneet-${STAGE}.region ap-southeast-1
if ! aws configure --profile $AWS_PROFILE list
then
echo Profile $AWS_PROFILE does not exist >&2
exit 1
fi
fi
if ! hash ecs-cli
then
echo Please install https://github.com/aws/amazon-ecs-cli and ensure it is in your \$PATH
echo curl -o /usr/local/bin/ecs-cli https://s3.amazonaws.com/amazon-ecs-cli/ecs-cli-linux-amd64-latest && chmod +x /usr/local/bin/ecs-cli
exit 1
else
ecs-cli -version
fi
ecs-cli configure --cluster master --region ap-southeast-1 --compose-service-name-prefix ecscompose-service-
test -f aws-env.$STAGE && source aws-env.$STAGE
service=$(grep -A1 services AWS-docker-compose.yml | tail -n1 | tr -cd '[[:alnum:]]')
echo Deploying $service with commit $COMMIT >&2
# Ensure docker compose file's STAGE env is empty for production
test "$STAGE" == prod && export STAGE=""
envsubst < AWS-docker-compose.yml > docker-compose-${service}.yml
ecs-cli compose --aws-profile $AWS_PROFILE -p ${service} -f docker-compose-${service}.yml service up \
--deployment-max-percent 100 \
--deployment-min-healthy-percent 50 \
--timeout 7
ecs-cli compose --aws-profile $AWS_PROFILE -p ${service} -f docker-compose-${service}.yml service ps
echo "END $0 $(date)"