Skip to content

Commit 260204b

Browse files
committed
Route53 configs updated. Configs locally created.
1 parent 640917b commit 260204b

5 files changed

Lines changed: 62 additions & 157 deletions

File tree

deploy.sh

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ aws s3 cp "$localhome"/updatescripts.sh s3://"$bucketname"
228228

229229

230230
#Modify file rg_userpool.yml to refer new S3 bucket
231-
sed -i -e "s/S3Bucket:.*/S3Bucket: $bucketname/" "$localhome"/rg_userpool.yml
231+
#sed -i -e "s/S3Bucket:.*/S3Bucket: $bucketname/" "$localhome"/rg_userpool.yml
232232

233233
#Copy extracted cft template to the new bucket
234234
echo "Copying deployment files to new bucket"
@@ -315,7 +315,7 @@ function create_cognito_pool() {
315315
--stack-name "$1" \
316316
--parameter-overrides UserPoolNameParam="$1" PortalURLParam="$rgurl" \
317317
Function1Name="post_verification_send_message-$runid" Function2Name="pre_verification_custom_message-$runid" \
318-
--capabilities CAPABILITY_IAM
318+
CFTBucketName="$bucketname" --capabilities CAPABILITY_IAM
319319

320320
aws cloudformation wait stack-create-complete --stack-name "$userpoolstackname"
321321
}
@@ -367,11 +367,11 @@ function create_main_stack() {
367367
echo "Source Bucket: $S3_SOURCE"
368368
aws cloudformation deploy --template-file "$localhome"/rg_main_stack.yml \
369369
--stack-name "$mainstackname" \
370-
--parameter-overrides ClientId="$userpoolclient_id" UserPoolId="$userpool_id" \
371-
CFTBucketName="$bucketname" RGUrl="$rgurl" UserPassword="$appuserpassword" AdminPassword="$adminpassword" \
370+
--parameter-overrides CFTBucketName="$bucketname" RGUrl="$rgurl"\
371+
UserPassword="$appuserpassword" AdminPassword="$adminpassword" \
372372
VPC="$vpcid" Subnet1="$subnet1id" KeyName1="$keypairname" TGARN="$tgarn" \
373373
DocumentDBInstanceURL="$docdburl" Environment="$env" BaseAccountPolicyName="RG-Portal-Base-Account-Policy-$env-$runid" \
374-
StackRunId="$runid" --capabilities CAPABILITY_NAMED_IAM
374+
--capabilities CAPABILITY_NAMED_IAM
375375
echo "Waiting for stack $1 to finish deploying..."
376376
aws cloudformation wait stack-create-complete --stack-name "$mainstackname"
377377
}
@@ -487,13 +487,18 @@ echo "Image Builder stack outputs"
487487
aws cloudformation describe-stacks --stack-name "$imgbldrstackname" | jq -r '.Stacks[] | .Outputs[] | .OutputValue'
488488

489489
#===============================================================================================================
490-
#Creating Main stack
490+
#Creating configs locally
491491
ac_name=$(aws sts get-caller-identity --query "Account" --output text)
492492
r53_domain_name="${rgurl//http[s]*:\/\//}"
493493
jqcmd='.HostedZones[] | select(.Name=='"\"${r53_domain_name}.\""')|.Id'
494494
hosted_zone=$(aws route53 list-hosted-zones-by-name --dns-name "$r53_domain_name" | jq -r "$jqcmd" | sed -e 's#\/hostedzone\/##')
495+
echo "Creating configs locally"
495496
./makeconfigs.sh "$userpoolclient_id" "$userpool_id" "$bucketname" "$appuser" "$appuserpassword" \
496497
"$runid" "$rgurl" "$region" "ROLE_NAME" "$ac_name" "$hosted_zone"
498+
echo "Uploading configs to $bucketname"
499+
aws s3 cp "$localhome"/config.tar.gz s3://"$bucketname"
500+
#===============================================================================================================
501+
#Creating Main stack
497502
echo "Deploying main stack (roles, ec2 instance etc.)"
498503
mainstack_start_time=$SECONDS
499504
mainstackname="RG-PortalStack-$runid"

makeconfigs.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ jq -r ".trustPolicy.Statement[0].Principal.AWS=\"arn:aws:iam::$ac_name:role/$rol
126126
jq -r ".roleName=\"RG-Portal-ProjectRole-$RG_ENV-$myrunid\"" |
127127
jq -r ".policyName=\"RG-Portal-ProjectPolicy-$RG_ENV-$myrunid\"" >"${RG_HOME}/config/trustPolicy.json"
128128

129-
tar -czf config.tar.gz "$RG_HOME/config"/*
129+
tar -C "$RG_HOME" -czf config.tar.gz "config"/*
130130
tar -tf config.tar.gz
131+
rm -rf "$RG_HOME"
131132
echo 'Configuration changed successfully'

rg_main_stack.yml

Lines changed: 35 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,6 @@ Parameters:
2525
Description: URL at which this instance of Research Gateway can be reached. e.g. myrg.example.com
2626
Type: String
2727
ConstraintDescription: RG URL
28-
UserPoolId:
29-
Description: UserPoolId of the Cognito UserPool created for this instance of Research Gateway
30-
Type: String
31-
Default: ""
32-
ConstraintDescription: User Pool Id
33-
ClientId:
34-
Description: ClientId of the Cognito UserPool created for this instance of Research Gateway
35-
Type: String
36-
Default: ""
37-
ConstraintDescription: ClientId
3828
CFTBucketName:
3929
Description: Bucket that is created to hold CFT templates used by Research Gateway
4030
Type: String
@@ -75,11 +65,6 @@ Parameters:
7565
BaseAccountPolicyName:
7666
Description: Name for RG Portal Base Account Policy
7767
Type: String
78-
StackRunId:
79-
Description: Run Id to make the config unique
80-
Type: String
81-
Default: ""
82-
ConstraintDescription: Run ID
8368
Conditions:
8469
DocumentDBSelected:
8570
Fn::Equals:
@@ -96,7 +81,7 @@ Conditions:
9681
- Condition: DocumentDBURLProvided
9782
UseLocalMongoDB:
9883
Fn::Not:
99-
- Condition: DocumentDBSelected
84+
- Condition: UseDocumentDB
10085
Resources:
10186
RGPortalRole:
10287
Type: AWS::IAM::Role
@@ -152,7 +137,7 @@ Resources:
152137
- sns:*
153138
- sts:AssumeRole
154139
- cloudformation:*
155-
Resource: '*'
140+
Resource: "*"
156141
RGPortalSG:
157142
Type: AWS::EC2::SecurityGroup
158143
Properties:
@@ -189,49 +174,51 @@ Resources:
189174
- DeviceName: /dev/xvda
190175
Ebs:
191176
VolumeType: gp2
192-
VolumeSize: '30'
193-
DeleteOnTermination: 'true'
194-
Encrypted: 'true'
177+
VolumeSize: "100"
178+
DeleteOnTermination: "true"
179+
Encrypted: "true"
195180
SubnetId:
196181
Ref: Subnet1
197182
SecurityGroupIds:
198183
- Ref: RGPortalSG
199184
UserData:
200-
Fn::Base64:
185+
Fn::Base64:
201186
Fn::If:
202187
- UseLocalMongoDB
203188
- !Sub |
204-
#!/bin/bash
205-
exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1
206-
export RG_HOME=/opt/deploy/sp2
207-
export RG_ENV=${Environment}
208-
export RG_SRC=/home/ubuntu
209-
export S3_SOURCE="${CFTBucketName}"
210-
aws s3 cp s3://${CFTBucketName}/updatescripts.sh /home/ubuntu
211-
chmod +x /home/ubuntu/updatescripts.sh
212-
/home/ubuntu/updatescripts.sh
213-
fixmongo.sh ${Environment}-cc ${AdminPassword} rguser ${UserPassword} ${RGUrl}
214-
fixconfigs.sh ${UserPoolId} ${ClientId} ${CFTBucketName} rguser ${UserPassword} ${StackRunId} ${RGUrl}
215-
start_server.sh ${RGUrl} ${TGARN}
216-
/opt/aws/bin/cfn-signal -e 0 --stack ${AWS::StackName} --resource RGEC2Instance --region ${AWS::Region}
189+
#!/bin/bash
190+
exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1
191+
export RG_HOME=/opt/deploy/sp2
192+
export RG_ENV=${Environment}
193+
export RG_SRC=/home/ubuntu
194+
export S3_SOURCE="${CFTBucketName}"
195+
aws s3 cp s3://${CFTBucketName}/updatescripts.sh /home/ubuntu
196+
aws s3 cp s3://${CFTBucketName}/config.tar.gz /home/ubuntu
197+
chmod +x /home/ubuntu/updatescripts.sh
198+
/home/ubuntu/updatescripts.sh
199+
fixmongo.sh ${Environment}-cc ${AdminPassword} rguser ${UserPassword} ${RGUrl}
200+
fixconfigs.sh
201+
start_server.sh ${RGUrl} ${TGARN}
202+
/opt/aws/bin/cfn-signal -e 0 --stack ${AWS::StackName} --resource RGEC2Instance --region ${AWS::Region}
217203
- !Sub |
218-
#!/bin/bash
219-
exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1
220-
export RG_HOME=/opt/deploy/sp2
221-
export RG_ENV=${Environment}
222-
export RG_SRC=/home/ubuntu
223-
export S3_SOURCE="${CFTBucketName}"
224-
aws s3 cp s3://${CFTBucketName}/updatescripts.sh /home/ubuntu
225-
chmod +x /home/ubuntu/updatescripts.sh
226-
/home/ubuntu/updatescripts.sh
227-
fixconfigs.sh ${UserPoolId} ${ClientId} ${CFTBucketName} rguser ${UserPassword} ${StackRunId} ${RGUrl}
228-
fixdocdb.sh ${DocumentDBInstanceURL} ${Environment}-cc rguser ${UserPassword} ${RGUrl}
229-
start_server.sh ${RGUrl} ${TGARN}
230-
/opt/aws/bin/cfn-signal -e 0 --stack ${AWS::StackName} --resource RGEC2Instance --region ${AWS::Region}
204+
#!/bin/bash
205+
exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1
206+
export RG_HOME=/opt/deploy/sp2
207+
export RG_ENV=${Environment}
208+
export RG_SRC=/home/ubuntu
209+
export S3_SOURCE="${CFTBucketName}"
210+
aws s3 cp s3://${CFTBucketName}/updatescripts.sh /home/ubuntu
211+
aws s3 cp s3://${CFTBucketName}/config.tar.gz /home/ubuntu
212+
chmod +x /home/ubuntu/updatescripts.sh
213+
/home/ubuntu/updatescripts.sh
214+
fixconfigs.sh
215+
fixdocdb.sh ${DocumentDBInstanceURL} ${Environment}-cc rguser ${UserPassword} ${RGUrl}
216+
start_server.sh ${RGUrl} ${TGARN}
217+
/opt/aws/bin/cfn-signal -e 0 --stack ${AWS::StackName} --resource RGEC2Instance --region ${AWS::Region}
231218
CreationPolicy:
232219
ResourceSignal:
233220
Timeout: PT9M
234221
Outputs:
235222
RGAccessURL:
236223
Description: URL to access Research Gateway
237-
Value: !Ref RGUrl
224+
Value: !Ref RGUrl

rg_userpool.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ Parameters:
3737
MaxLength: 64
3838
Default: UserManagement
3939
ConstraintDescription: A Name to identify LambdaFunction2
40+
CFTBucketName:
41+
Description: Bucket that is created to hold CFT templates used by Research Gateway
42+
Type: String
43+
Default: ""
44+
ConstraintDescription: Bucket Name
4045
Resources:
4146
UserPoolCustomMessageLambdaInvokePermission:
4247
Type: AWS::Lambda::Permission
@@ -355,7 +360,7 @@ Resources:
355360
FunctionName: !Ref Function1Name
356361
Handler: "index.handler"
357362
Code:
358-
S3Bucket: rg-deployment-docs
363+
S3Bucket: !Ref CFTBucketName
359364
S3Key: post_verification_send_message.zip
360365
Role: !GetAtt "LambdaExecutionRole.Arn"
361366
MemorySize: 128
@@ -374,7 +379,7 @@ Resources:
374379
FunctionName: !Ref Function2Name
375380
Handler: "index.handler"
376381
Code:
377-
S3Bucket: rg-deployment-docs
382+
S3Bucket: !Ref CFTBucketName
378383
S3Key: pre_verification_custom_message.zip
379384
Role: !GetAtt "LambdaExecutionRole.Arn"
380385
MemorySize: 128

scripts/fixconfigs.sh

Lines changed: 7 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,7 @@
11
#!/bin/bash
22
version="0.1.10"
33
echo "Fixing configs...(fixconfig.sh v$version)"
4-
# Ensure right number of params
5-
if [ $# -lt 5 ]; then
6-
echo 'At least 5 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: (Optional) 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 ' Will use public-host-name if not passed'
17-
exit 1
18-
fi
194

20-
myuserpoolid=$1
21-
myclientid=$2
22-
mys3bucket=$3
23-
myappuser=$4
24-
myapppwd=$5
25-
myrunid=$6
26-
myurl=$7
275
[ -z "$RG_HOME" ] && RG_HOME='/opt/deploy/sp2'
286
echo "RG_HOME=$RG_HOME"
297
[ -z "$RG_SRC" ] && RG_SRC='/home/ubuntu'
@@ -33,33 +11,14 @@ echo "RG_ENV=$RG_ENV"
3311
[ -z "$S3_SOURCE" ] && S3_SOURCE=rg-deployment-docs
3412
echo "S3_SOURCE=$S3_SOURCE"
3513

36-
mypubip=$(wget -q -O - http://169.254.169.254/latest/meta-data/public-ipv4)
37-
echo "Public IP : $mypubip"
3814
myip=$(wget -q -O - http://169.254.169.254/latest/meta-data/local-ipv4)
3915
echo "Local IP : $myip"
40-
region="$(wget -q -O - http://169.254.169.254/latest/meta-data/placement/region)"
41-
echo "Region : $region"
4216
role_name="$(wget -q -O - http://169.254.169.254/latest/meta-data/iam/security-credentials/)"
4317
echo "Role name : $role_name"
4418
ac_name=$(wget -q -O - http://169.254.169.254/latest/dynamic/instance-identity/document | jq -r .accountId)
4519
echo "Account number : $ac_name"
4620
instanceid=$(wget -q -O - http://169.254.169.254/latest/meta-data/instance-id)
4721
echo "Instance-id : $instanceid"
48-
if [ -z "$myurl" ]; then
49-
public_host_name="$(wget -q -O - http://169.254.169.254/latest/meta-data/public-hostname)"
50-
if [ -z "$public_host_name" ]; then
51-
echo "FATAL: No RG URL passed. Instance does not have public hostname. One of the two is required. Not modifying configs."
52-
exit 1
53-
else
54-
baseurl="http://$public_host_name/"
55-
snsprotocol="http"
56-
fi
57-
else
58-
baseurl="$myurl/"
59-
snsprotocol=$(echo "$myurl" | sed -e 's/\(http.*:\/\/\).*/\1/' | sed -e 's/://' -e 's/\///g')
60-
fi
61-
echo "Base URL set to $baseurl"
62-
echo "snsprotocol set to $snsprotocol"
6322

6423
if ! [ -d "$RG_HOME/tmp" ]; then
6524
echo "$RG_HOME/tmp does not exist. Creating"
@@ -70,77 +29,25 @@ if ! [ -d "$RG_HOME/config" ]; then
7029
echo "$RG_HOME/config does not exist. Creating"
7130
mkdir -p "$RG_HOME/config"
7231
fi
73-
mkdir -p "$RG_HOME/config"
32+
tar -xvf "$RG_SRC/config.tar.gz" -C "$RG_HOME"
7433
if [ -z "$(ls -A $RG_HOME/config)" ]; then
75-
echo "$RG_HOME/config is empty. Extracting templates"
76-
tar -xvf "$RG_SRC/config.tar.gz" -C "$RG_HOME"
77-
if [ -z "$(ls -A $RG_HOME/config)" ]; then
78-
echo "FATAL: $RG_HOME/config is still empty. Exiting"
79-
exit 1
80-
fi
34+
echo "FATAL: $RG_HOME/config is still empty. Exiting"
35+
exit 1
8136
fi
8237
mytemp=$(mktemp -d -p "${RG_HOME}/tmp" -t "config.old.XXX")
8338
echo "$mytemp"
8439
cp "${RG_HOME}/config/config.json" "$mytemp"
85-
cp "${RG_HOME}/config/snsConfig.json" "$mytemp"
86-
cp "${RG_HOME}/config/mongo-config.json" "$mytemp"
87-
cp "${RG_HOME}/config/global-config.json" "$mytemp"
88-
cp "${RG_HOME}/config/email-config.json" "$mytemp"
8940
cp "${RG_HOME}/config/notification-config.json" "$mytemp"
9041
cp "${RG_HOME}/config/trustPolicy.json" "$mytemp"
9142

92-
93-
s3url="https://${mys3bucket}.s3.${region}.amazonaws.com/"
9443
echo "Modifying config.json"
95-
if [ -z "$baseurl" ]; then
96-
echo "WARNING: Base URL is not passed. config.json file may not be configured correctly"
97-
fi
98-
jq -r ".baseURL=\"$baseurl\"" "$mytemp/config.json" |
99-
jq -r ".googleOAuthCredentials.callbackURL=\"$baseurl\"" |
100-
jq -r ".baseAccountInstanceRoleName=\"$role_name\"" |
101-
jq -r '.baseAccountPolicyName="RG-Portal-CrossAccount-Policy"' |
102-
jq -r ".baseAccountNumber=\"$ac_name\"" |
103-
jq -r ".researchGatewayAPIToken=\"$instanceid\"" |
104-
jq -r ".BucketName=\"$mys3bucket\"" |
105-
jq -r ".cftTemplateURL=\"$s3url\"" |
106-
jq -r ".AWSCognito.userPoolId=\"$myuserpoolid\"" |
107-
jq -r ".AWSCognito.clientId=\"$myclientid\"" |
108-
jq -r ".AWSCognito.region=\"$region\"" |
109-
jq -r ".enableB2CMode=false" >"${RG_HOME}/config/config.json"
110-
echo "Modifying snsConfig.json"
111-
if [ -z "$snsprotocol" ]; then
112-
echo "WARNING: SNS protocol could not be determined. Did you pass in the correct RG URL?"
113-
echo "snsConfig.json file may not be configured correctly"
114-
fi
115-
jq -r ".snsProtocol=\"$snsprotocol\"" "$mytemp/snsConfig.json" >"${RG_HOME}/config/snsConfig.json"
116-
echo "Modifying mongo-config.json"
117-
jq -r ".db_ssl_enable=true" "$mytemp/mongo-config.json" |
118-
jq -r '.db_ssl_config.CAFile="RL-CA.pem"' |
119-
jq -r '.db_ssl_config.PEMFile="mongodb.pem"' |
120-
jq -r ".db_auth_enable=true" |
121-
jq -r ".db_documentdb_enable=false" |
122-
jq -r ".db_auth_config.username=\"$myappuser\"" |
123-
jq -r ".db_auth_config.password=\"$myapppwd\"" |
124-
jq -r '.db_auth_config.authenticateDb="admin"' >"${RG_HOME}/config/mongo-config.json"
125-
echo "Modifying global-config.json"
126-
if [ -z "$baseurl" ]; then
127-
echo "WARNING: Base URL is not passed. global-config.json file may not be configured correctly"
128-
fi
129-
jq -r ".secureURL.PROD=\"$baseurl\"" "$mytemp/global-config.json" |
130-
jq -r ".linksForRg.termsAndConditions=\"$baseurl\"" >"${RG_HOME}/config/global-config.json"
131-
echo "Modifying email-config.json"
132-
if [ -z "$baseurl" ]; then
133-
echo "WARNING: Base URL is not passed. The following file may not be configured correctly"
134-
fi
135-
jq -r ".email.url=\"$baseurl:2687/bot/sns_notify_bot/exec\"" "$mytemp/email-config.json" |
136-
jq -r '.email.options.body.data.from="rlc.support@relevancelab.com"' |
137-
jq -r '.email.options.body.data.url="https://serviceone.rlcatalyst.com"' >"${RG_HOME}/config/email-config.json"
44+
jq -r ".baseAccountInstanceRoleName=\"$role_name\"" "$mytemp/config.json" >"${RG_HOME}/config/config.json"
45+
13846
echo "Modifying notification-config.json"
13947
jq -r ".tokenID=[\"$instanceid\"]" "$mytemp/notification-config.json" >"${RG_HOME}/config/notification-config.json"
48+
14049
echo "Modifying trustPolicy.json"
141-
jq -r ".trustPolicy.Statement[0].Principal.AWS=\"arn:aws:iam::$ac_name:role/$role_name\"" "$mytemp/trustPolicy.json" |
142-
jq -r ".roleName=\"RG-Portal-ProjectRole-$RG_ENV-$myrunid\"" |
143-
jq -r ".policyName=\"RG-Portal-ProjectPolicy-$RG_ENV-$myrunid\"" >"${RG_HOME}/config/trustPolicy.json"
50+
jq -r ".trustPolicy.Statement[0].Principal.AWS=\"arn:aws:iam::$ac_name:role/$role_name\"" "$mytemp/trustPolicy.json" >"${RG_HOME}/config/trustPolicy.json"
14451

14552
echo "Fetching latest docker-compose.yml"
14653
aws s3 cp s3://${S3_SOURCE}/docker-compose.yml $RG_SRC

0 commit comments

Comments
 (0)