-
Notifications
You must be signed in to change notification settings - Fork 12
/
polycosm-publish.sh
executable file
·47 lines (37 loc) · 1.68 KB
/
polycosm-publish.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
#!/usr/bin/env bash
if [[ -z "$1" ]]; then
echo -e "
Usage: polycosm-publish.sh [environment]
Packages and publishes the lambda code to S3 for redistribution into new polycosm deployments.
"
exit 1
fi
if [[ -z "$HUBS_OPS_PATH" ]]; then
echo -e "To use this deploy script, you need to clone out the hubs-ops repo
git clone [email protected]:mozilla/hubs-ops.git
Then set HUBS_OPS_PATH to point to the cloned repo."
exit 1
fi
ENVIRONMENT=$1
[[ -z "$ENVIRONMENT" ]] && ENVIRONMENT=dev
VERSION=$(cat package.json | jq -r ".version")
NAME=$(cat package.json | jq -r ".name")
DIR=$(pwd)
pushd $HUBS_OPS_PATH/terraform
BUCKET=$(./grunt_local.sh output ret $ENVIRONMENT -json | jq 'with_entries(.value |= .value)' | jq -r ".polycosm_sam_bucket_id")
BUCKET_REGION=$(./grunt_local.sh output ret $ENVIRONMENT -json | jq 'with_entries(.value |= .value)' | jq -r ".polycosm_sam_bucket_region")
popd
mv node_modules node_modules_tmp
env npm_config_arch=x64 npm_config_platform=linux npm_config_target=10.16.1 npm ci
zip -9 -y -r ${NAME}.zip *.js node_modules
sam package --region $BUCKET_REGION --template-file template.yaml --output-template-file template-packaged.yaml --s3-bucket $BUCKET
for samregion in us-east-1 #us-east-2 us-west-1 us-west-2 ap-northeast-1 eu-west-1
do
sam publish --region $samregion --template template-packaged.yaml
APPLICATION_ARN=$(aws --region $samregion serverlessrepo list-applications | jq -r '.Applications | . [] | .ApplicationId' | grep $NAME)
aws --region $samregion serverlessrepo put-application-policy --application-id "$APPLICATION_ARN" --statements Principals=*,Actions=Deploy
done
rm template-packaged.yaml
rm -rf node_modules
mv node_modules_tmp node_modules
rm ${NAME}.zip