-
Notifications
You must be signed in to change notification settings - Fork 6
/
release.sh
144 lines (122 loc) · 3.82 KB
/
release.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/bash
VALID_ENVIRONMENTS=("dev" "uat" "prod");
VALID_VERIFICATION_RESPONSES=("Y" "N" "y" "n");
APP_NAME="Serverless Ninja Buckets";
printSeparator() {
echo -e ""
echo -e ""
}
printColored() {
TEXT="${1}";
printf "\e[38;2;248;138;0m${TEXT} \e[0m\n";
}
printError() {
TEXT="${1}";
printf "\e[38;2;255;0;0m${TEXT}\e[0m\n";
}
printListItem() {
TEXT="${1}";
CHECK_MARK="\e[38;2;0;255;0m\xE2\x9C\x94\e[0m";
echo -e "${CHECK_MARK} ${TEXT}";
}
printHeader() {
clear;
printColored " _____ __ _ ___ _ ";
printColored " / ___/___ ______ _____ _____/ /__ __________ / | / (_)___ (_)___ _";
printColored " \__ \/ _ \/ ___/ | / / _ \/ ___/ / _ \/ ___/ ___/ / |/ / / __ \ / / __ \`/";
printColored " ___/ / __/ / | |/ / __/ / / / __(__ |__ ) / /| / / / / / / / /_/ / ";
printColored "/____/\___/_/ |___/\___/_/ /_/\___/____/____/ /_/ |_/_/_/ /_/_/ /\__,_/ ";
printColored " /___/ ";
}
collectEnvironment() {
printHeader
printSeparator;
printColored "$APP_NAME";
printSeparator;
echo -n "1). Enter Environment Code (${VALID_ENVIRONMENTS[*]}): "
read ENVIRONMENT_NAME
}
while true; do
collectEnvironment
if [[ " ${VALID_ENVIRONMENTS[*]} " == *" ${ENVIRONMENT_NAME} "* ]];
then
break
else
printError "Invalid environment code, try again after 1 second."
sleep 1
printSeparator
fi
done
printSeparator;
collectAwsCliProfile() {
printHeader
printSeparator;
printColored "$APP_NAME";
printSeparator;
echo -n "2). Enter AWS CLI Profile: "
read AWS_CLI_PROFILE
}
collectAwsCliProfile;
AWS_CF_STACK_NAME="${ENVIRONMENT_NAME}-ninja-buckets-a";
verifyInstallation() {
printHeader;
printSeparator;
printColored "I am about to release an instance of $APP_NAME with the following settings";
printSeparator;
printListItem "ENVIRONMENT_NAME = ${ENVIRONMENT_NAME}";
printListItem "AWS_CF_STACK_NAME = ${AWS_CF_STACK_NAME}";
printListItem "AWS_CLI_PROFILE = ${AWS_CLI_PROFILE}";
printSeparator;
echo -n "3). Are you sure you want to proceed? ([Y]es, [N]o): "
read CONFIRM_CODE
}
while true; do
verifyInstallation
if [[ " ${VALID_VERIFICATION_RESPONSES[*]} " == *" ${CONFIRM_CODE} "* ]];
then
break
else
printError "Invalid value."
sleep 1
printSeparator
fi
done
if [[ $CONFIRM_CODE == "Y" ]] || [[ $CONFIRM_CODE == "y" ]]
then
printSeparator
printHeader
printSeparator
printColored "Initiating deployment...";
printSeparator
else
clear;
printHeader
printSeparator
printError "Stack release aborted. Press any key to exit";
read
clear;
fi
if aws cloudformation describe-stacks --profile "$AWS_CLI_PROFILE" --stack-name "$AWS_CF_STACK_NAME" &> /dev/null ; then
printListItem "Updating an existing stack (${AWS_CF_STACK_NAME})";
printSeparator
aws cloudformation update-stack \
--stack-name "${AWS_CF_STACK_NAME}" \
--template-body file://rapid-expiration-bucket.cfn.yaml \
--profile "${AWS_CLI_PROFILE}" \
--parameters ParameterKey=Environment,ParameterValue="$ENVIRONMENT_NAME" \
--capabilities CAPABILITY_AUTO_EXPAND CAPABILITY_IAM CAPABILITY_NAMED_IAM
else
printListItem "Creating a new stack (${AWS_CF_STACK_NAME})";
printSeparator
aws cloudformation create-stack \
--stack-name "${AWS_CF_STACK_NAME}" \
--template-body file://rapid-expiration-bucket.cfn.yaml \
--profile "${AWS_CLI_PROFILE}" \
--parameters ParameterKey=Environment,ParameterValue="$ENVIRONMENT_NAME" \
--capabilities CAPABILITY_AUTO_EXPAND CAPABILITY_IAM CAPABILITY_NAMED_IAM
fi
printSeparator;
echo -n "Deployment completed";
printSeparator;
read -n 1 -s -r -p "Press any key to continue....";
clear;