-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.sh
executable file
·70 lines (55 loc) · 1.69 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
#!/bin/sh
# TODO add shellcheck for all scripts
set -e
version=$(<package.json jq -re .version)
if [ "$(uname -s)" = "Darwin" ] ; then
uuid=$(uuidgen | tr "[:upper:]" "[:lower:]" | tr -d -)
else
uuid=$(uuidgen -r | tr -d -)
fi
package=aoc-bot-$version-$uuid.zip
region=eu-central-1
bucket=cf.009116496185.$region
stack=aoc-bot
# Update SSM secrets using values from GitHub
if [ -z "$SKIP_SECRETS" ] ; then
put_secret() {
local param_name="$1"
local param_value="$2"
aws ssm put-parameter \
--overwrite \
--region $region \
--name "/$stack/$param_name" \
--type SecureString \
--value "$param_value"
}
put_secret "advent-of-code-secret" "$ADVENT_OF_CODE_SECRET"
put_secret "telegram-secret" "$TELEGRAM_SECRET"
put_secret "webhook-secret" "$WEBHOOK_SECRET"
fi
# Upload and deploy the package
if [ -z "$SKIP_DEPLOY" ] ; then
zip -rq $package $(<package.json jq -re .files[],.deployFiles[])
aws s3 cp \
--region $region \
$package s3://$bucket/$package
aws cloudformation deploy \
--region $region \
--capabilities CAPABILITY_IAM \
--template template.yml \
--stack-name $stack \
--parameter-overrides \
Bucket=$bucket \
Package=$package \
Version=$version
rm -f $package
# Register the Telegram webhook
endpoint=$(aws cloudformation describe-stacks \
--region $region \
--stack-name $stack \
--query "Stacks[0].Outputs[?OutputKey=='Endpoint'].OutputValue" \
--output text \
)
echo Endpoint: $endpoint
node src/register.js "${endpoint}telegram"
fi