Skip to content

Commit ffb74ce

Browse files
committed
Added route53 settings
1 parent c9292f0 commit ffb74ce

2 files changed

Lines changed: 138 additions & 0 deletions

File tree

deploy.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ elif [ $# -lt 7 ]; then
6969
echo ' Param 8: The Environment DEV / QA / STAGE / PROD to deploy DB instance.'
7070
echo ' Param 9: The URL at which Research Gateway will be accessed'
7171
echo ' Param 10: The Target Group to which the Portal EC2 instance should be added'
72+
echo ' Param 11: The hosted-zone ID for URL in param 9.'
7273
exit 1
7374
else
7475
echo "New run"
@@ -487,6 +488,12 @@ aws cloudformation describe-stacks --stack-name "$imgbldrstackname" | jq -r '.St
487488

488489
#===============================================================================================================
489490
#Creating Main stack
491+
ac_name=$(aws sts get-caller-identity --query "Account" --output text)
492+
r53_domain_name="${rgurl//http[s]*:\/\//}"
493+
jqcmd='.HostedZones[] | select(.Name=='"\"${r53_domain_name}.\""')|.Id'
494+
hosted_zone=$(aws route53 list-hosted-zones-by-name --dns-name "$r53_domain_name" | jq -r "$jqcmd" | sed -e 's#\/hostedzone\/##')
495+
makeconfigs.sh "$userpoolclient_id" "$userpool_id" "$bucketname" "$appuser" "$appuserpassword" \
496+
"$runid" "$rgurl" "$region" "ROLE_NAME" "$ac_name" "$hosted_zone"
490497
echo "Deploying main stack (roles, ec2 instance etc.)"
491498
mainstack_start_time=$SECONDS
492499
mainstackname="RG-PortalStack-$runid"

makeconfigs.sh

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
#!/bin/bash
2+
version="0.1.0"
3+
echo "Making configs locally...(makeconfigs.sh v$version)"
4+
# Ensure right number of params
5+
if [ $# -lt 11 ]; then
6+
echo 'At least 11 parameters are required!'
7+
echo ' Param 1: AWS Cognito User Pool id'
8+
echo ' Param 2: AWS Cognito client id'
9+
echo ' Param 3: RG Bucket Name (The bucket where CFT templates are stored)'
10+
echo ' Param 4: App username'
11+
echo ' Param 5: App user password'
12+
echo ' Param 6: Run Id'
13+
echo ' Param 7: URL to reach RG'
14+
echo ' e.g https://rg.example.com'
15+
echo ' Note that the protocol will be picked from this param!'
16+
echo ' Param 8: AWS Region'
17+
echo ' Param 9: AWS InstanceRoleName'
18+
echo ' Param 10: AWS Account Number. Optional if running on an EC2 in the'
19+
echo ' same account to which Research Gateway is to be deployed'
20+
echo ' Param 11: Hosted Zone Id in Route53 to be used for enabling SSL'
21+
echo ' in projects'
22+
exit 1
23+
fi
24+
25+
myuserpoolid=$1
26+
myclientid=$2
27+
mys3bucket=$3
28+
myappuser=$4
29+
myapppwd=$5
30+
myrunid=$6
31+
myurl=$7
32+
region=$8
33+
role_name=$9
34+
RG_HOME=$(mktemp -d -t "config.$myrunid.XXX")
35+
echo "RG_HOME=$RG_HOME"
36+
RG_SRC=$(pwd)
37+
echo "RG_SRC=$RG_SRC"
38+
[ -z "$RG_ENV" ] && RG_ENV='PROD'
39+
echo "RG_ENV=$RG_ENV"
40+
echo "Region : $region"
41+
echo "Role name : $role_name"
42+
ac_name=${10}
43+
if [ -z "$ac_name" ]; then
44+
ac_name=$(
45+
wget -q -O - http://169.254.169.254/latest/dynamic/instance-identity/document | jq -r .accountId
46+
)
47+
[ -z "$ac_name" ] && echo "Error: Account Number is needed" && exit 1
48+
fi
49+
echo "Account number : $ac_name"
50+
r53_hosted_zone=${11}
51+
generated_token=$(
52+
date +%s | sha256sum | base64 | tr -dc _a-z-0-9 | head -c 24
53+
echo
54+
)
55+
echo "Generated token : $generated_token"
56+
if [ -z "$myurl" ]; then
57+
echo "ERROR: No RG URL passed. Exiting."
58+
exit 1
59+
fi
60+
baseurl="$myurl/"
61+
echo "Base URL set to $baseurl"
62+
snsprotocol=$(
63+
echo "$myurl" | sed -e 's/\(http.*:\/\/\).*/\1/' -e 's/://' -e 's/\///g'
64+
)
65+
[ -z "$snsprotocol" ] && echo "RG URL must begin with http or https" && exit 1
66+
echo "snsprotocol set to $snsprotocol"
67+
r53_domain_name="${myurl//http[s]*:\/\//}"
68+
echo "Domain name is ${r53_domain_name}"
69+
mkdir -p "$RG_HOME/config"
70+
mytemp="$RG_SRC/config"
71+
if [ ! -e "$mytemp" ]; then
72+
echo "Error: Did not find $mytemp folder. Run this from rgdeploy folder"
73+
exit 1
74+
fi
75+
cp "$mytemp"/* "$RG_HOME/config"
76+
s3url="https://${mys3bucket}.s3.${region}.amazonaws.com/"
77+
echo "Modifying config.json"
78+
if [ -z "$baseurl" ]; then
79+
echo "WARNING: Base URL is not passed. config.json file may not be configured correctly"
80+
fi
81+
jq -r ".baseURL=\"$baseurl\"" "$mytemp/config.json" |
82+
jq -r ".googleOAuthCredentials.callbackURL=\"$baseurl\"" |
83+
jq -r ".baseAccountInstanceRoleName=\"$role_name\"" |
84+
jq -r '.baseAccountPolicyName="RG-Portal-CrossAccount-Policy"' |
85+
jq -r ".baseAccountNumber=\"$ac_name\"" |
86+
jq -r ".researchGatewayAPIToken=\"$generated_token\"" |
87+
jq -r ".BucketName=\"$mys3bucket\"" |
88+
jq -r ".cftTemplateURL=\"$s3url\"" |
89+
jq -r ".AWSCognito.userPoolId=\"$myuserpoolid\"" |
90+
jq -r ".AWSCognito.clientId=\"$myclientid\"" |
91+
jq -r ".route53.domainName=\"${r53_domain_name}\"" |
92+
jq -r ".route53.hostedZoneId=\"${r53_hosted_zone}\"" |
93+
jq -r ".AWSCognito.region=\"$region\"" |
94+
jq -r ".enableB2CMode=false" >"${RG_HOME}/config/config.json"
95+
echo "Modifying snsConfig.json"
96+
if [ -z "$snsprotocol" ]; then
97+
echo "WARNING: SNS protocol could not be determined. Did you pass in the correct RG URL?"
98+
echo "snsConfig.json file may not be configured correctly"
99+
fi
100+
jq -r ".snsProtocol=\"$snsprotocol\"" "$mytemp/snsConfig.json" >"${RG_HOME}/config/snsConfig.json"
101+
echo "Modifying mongo-config.json"
102+
jq -r ".db_ssl_enable=true" "$mytemp/mongo-config.json" |
103+
jq -r '.db_ssl_config.CAFile="rds-combined-ca-bundle.pem"' |
104+
jq -r ".db_auth_enable=true" |
105+
jq -r ".db_documentdb_enable=true" |
106+
jq -r ".db_auth_config.username=\"$myappuser\"" |
107+
jq -r ".db_auth_config.password=\"$myapppwd\"" |
108+
jq -r '.db_auth_config.authenticateDb="admin"' >"${RG_HOME}/config/mongo-config.json"
109+
echo "Modifying global-config.json"
110+
if [ -z "$baseurl" ]; then
111+
echo "WARNING: Base URL is not passed. global-config.json file may not be configured correctly"
112+
fi
113+
jq -r ".secureURL.PROD=\"$baseurl\"" "$mytemp/global-config.json" |
114+
jq -r ".linksForRg.termsAndConditions=\"$baseurl\"" >"${RG_HOME}/config/global-config.json"
115+
echo "Modifying email-config.json"
116+
if [ -z "$baseurl" ]; then
117+
echo "WARNING: Base URL is not passed. The following file may not be configured correctly"
118+
fi
119+
jq -r ".email.url=\"$baseurl:2687/bot/sns_notify_bot/exec\"" "$mytemp/email-config.json" |
120+
jq -r '.email.options.body.data.from="rlc.support@relevancelab.com"' |
121+
jq -r '.email.options.body.data.url="https://serviceone.rlcatalyst.com"' >"${RG_HOME}/config/email-config.json"
122+
echo "Modifying notification-config.json"
123+
jq -r ".tokenID=[\"$generated_token\"]" "$mytemp/notification-config.json" >"${RG_HOME}/config/notification-config.json"
124+
echo "Modifying trustPolicy.json"
125+
jq -r ".trustPolicy.Statement[0].Principal.AWS=\"arn:aws:iam::$ac_name:role/$role_name\"" "$mytemp/trustPolicy.json" |
126+
jq -r ".roleName=\"RG-Portal-ProjectRole-$RG_ENV-$myrunid\"" |
127+
jq -r ".policyName=\"RG-Portal-ProjectPolicy-$RG_ENV-$myrunid\"" >"${RG_HOME}/config/trustPolicy.json"
128+
129+
tar -czf config.tar.gz "$RG_HOME/config"/*
130+
tar -tf config.tar.gz
131+
echo 'Configuration changed successfully'

0 commit comments

Comments
 (0)