-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeploy-templates.sh
49 lines (43 loc) · 1.21 KB
/
deploy-templates.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
#!/usr/bin/env bash
# Uses the AWS CLI to upload templates to S3. Provided a specific file
#
# Usage:
# deploy bucket-name [file]
# If file is omitted, then all will be deployed.
#
if ! type "aws" > /dev/null; then
echo "awscli not install. Exiting."
exit 1
fi
if [ -z "$1" ]; then
bucket="nemac-cloudformation"
fi
aws s3 mb s3://${bucket}
pushd $( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
branch=$(git symbolic-ref --short -q HEAD)
if [ -z "$branch" ]; then
echo "Not on a branch, exiting."
exit 1
fi
if [ -z "$2" ]; then
pushd ./templates
for i in *.yaml; do
echo validating $i
(aws cloudformation validate-template --template-body file://$i && aws s3 cp "$i" s3://${bucket}/${branch}/templates/) | grep 'error\|upload'
done;
popd
else
i=$2
echo validating $i
aws cloudformation validate-template --template-body file://$i
if [ $? -ne 0 ]; then
echo "Failed validation test, exiting."
exit 1
fi
aws s3 cp "$i" s3://${bucket}/${branch}/templates/
if [ $? -ne 0 ]; then
echo "Failed upload, exiting."
exit 1
fi
fi
popd