-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
executable file
·75 lines (64 loc) · 1.75 KB
/
entrypoint.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
#!/bin/sh
set -e
if [ -z "$AWS_S3_BUCKET" ]; then
echo "AWS_S3_BUCKET is not set. Quitting."
exit 1
fi
if [ -z "$AWS_ACCESS_KEY_ID" ]; then
echo "AWS_ACCESS_KEY_ID is not set. Quitting."
exit 1
fi
if [ -z "$AWS_SECRET_ACCESS_KEY" ]; then
echo "AWS_SECRET_ACCESS_KEY is not set. Quitting."
exit 1
fi
if [ -z "$AWS_REGION" ]; then
echo "AWS_REGION is not set. Quitting."
exit 1
fi
if [ -z "$STAGE" ]; then
echo "STAGE is not set. Quitting."
exit 1
fi
# Create a dedicated profile for this action to avoid
# conflicts with other actions.
# https://github.com/jakejarvis/s3-sync-action/issues/1
aws configure --profile push-s3-cfn <<-EOF > /dev/null 2>&1
${AWS_ACCESS_KEY_ID}
${AWS_SECRET_ACCESS_KEY}
${AWS_REGION}
text
EOF
stagingfolder=$STAGE
if [ "$STAGE" = "staging" ]; then
stagingfolder=""
fi
for gitfile in $FILES
do
actiontype=$(echo $gitfile | cut -d' ' -f1)
file=$(echo $gitfile | cut -d' ' -f2)
case "$file" in
"serverless/$stagingfolder"*)
if [ "$actiontype" = "D" ]; then
echo "Deleted, we should delete stack"
else
# get file name
filename=$(basename $file)
# get hash content of file
hashfile=$(cat $file)
hash=$(echo $hashfile | tr -d '\r')
# Use our dedicated profile and suppress verbose messages.
# All other flags are optional via `args:` directive.
aws s3 cp s3://${AWS_S3_BUCKET}/${hash}.yml ./ --profile push-s3-cfn
aws cloudformation deploy --template-file ./${hash}.yml \
--stack-name $filename-${STAGE} \
--capabilities CAPABILITY_NAMED_IAM \
--parameter-overrides Stage=${STAGE} GitHash=${hash} \
--no-fail-on-empty-changeset \
--profile push-s3-cfn &
fi
;;
* ) echo no ;;
esac
done
wait