forked from illuspas/Node-Media-Server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauto-deploy.sh
executable file
·75 lines (67 loc) · 2.52 KB
/
auto-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
71
72
73
74
75
#! /bin/bash
# Builds the .env file from scratch because we don't want that to be checked in
if [ "${CIRCLE_BRANCH}" == "master" ]; then
ENV='dev'
elif [ "${CIRCLE_BRANCH}" == "staging" ]; then
ENV='stag'
elif [ "${CIRCLE_BRANCH}" == "production" ]; then
ENV='prod'
fi
## Dynamically create variable names
env_region=${ENV}_REGION
## This script to be run before automatic deploys to get the environment setup
echo "Settings AWS config for radiant"
aws configure set radiant.region "${!env_region}"
## This is so hack, but it works
## https://discuss.circleci.com/t/support-for-aws-credentials-profiles/3698/2
echo -e "[radiant]\naws_access_key_id=${AWS_ACCESS_KEY_ID}\naws_secret_access_key=${AWS_SECRET_ACCESS_KEY}\n" > ~/.aws/credentials
# Configure kubectl
aws s3 cp s3://radiant-nms-files/.kube/config $HOME/.kube/config
# Reusable function to get ssm parameter
get_ssm () {
PARAMETER=$(aws ssm get-parameter --name $1 --with-decryption --profile radiant | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["Parameter"]["Value"]')
}
# Build a .env file from the param store
get_ssm nms-shared-secret
echo "SHARED_SECRET=\"$PARAMETER\"" > .env
get_ssm nms-${ENV}-aws-access-key
echo "AWS_ACCESS_KEY=\"$PARAMETER\"" >> .env
get_ssm nms-${ENV}-aws-access-secret
echo "AWS_SECRET_ACCESS_SECRET=\"$PARAMETER\"" >> .env
get_ssm nms-s3-region
echo "S3_REGION=\"$PARAMETER\"" >> .env
get_ssm nms-https-port
echo "HTTPS_PORT=$PARAMETER" >> .env
get_ssm nms-http-port
echo "HTTP_PORT=$PARAMETER" >> .env
get_ssm nms-rtmp-port
echo "RTMP_PORT=$PARAMETER" >> .env
echo "ENV=\"DEV\"" >> .env
get_ssm nms-secure-publish
echo "SECURE_PUBLISH=$PARAMETER" >> .env
get_ssm nms-secure-play
echo "SECURE_PLAY=$PARAMETER" >> .env
get_ssm nms-api-user
echo "API_USER=\"$PARAMETER\"" >> .env
get_ssm nms-api-password
echo "API_PASSWORD=\"$PARAMETER\"" >> .env
get_ssm nms-ffmpeg-path
echo "FFMPEG_PATH=\"$PARAMETER\"" >> .env
get_ssm nms-segment-length
echo "SEGMENT_LENGTH=$PARAMETER" >> .env
get_ssm nms-timeout-to-cleanup
echo "TIMEOUT_TO_CLEANUP=$PARAMETER" >> .env
get_ssm nms-thumbnail-segment
echo "THUMBNAIL_SEGMENT=$PARAMETER" >> .env
get_ssm nms-loggly-token
echo "LOGGLY_TOKEN=$PARAMETER" >> .env
get_ssm nms-${ENV}-loggly-log-level
echo "LOGGLY_LOG_LEVEL=$PARAMETER" >> .env
# Now we run the deploy script.
if [ "${CIRCLE_BRANCH}" == "master" ]; then
./deploy-dev.sh -p radiant
elif [ "${CIRCLE_BRANCH}" == "staging" ]; then
./deploy-stag.sh -p radiant
elif [ "${CIRCLE_BRANCH}" == "production" ]; then
./deploy-prod.sh -p radiant
fi