Skip to content

Commit

Permalink
Merge pull request #90 from louishourcade/bug/cross_region_deployment
Browse files Browse the repository at this point in the history
fix bugs when depoying cicd stack and backend stacks in different reg…
  • Loading branch information
dlpzx authored Jul 19, 2022
2 parents fb38443 + 23a2773 commit eec67a0
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion deploy/configs/frontend_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def create_react_env_file(
f.write(file_content)

if cw_rum_enabled == 'True':
rum = boto3.client('rum')
rum = boto3.client('rum', region=region)
app_monitor = rum.get_app_monitor(Name=f'{resource_prefix}-{envname}-monitor')[
'AppMonitor'
]
Expand Down
7 changes: 4 additions & 3 deletions deploy/configs/rum_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
from botocore.exceptions import ClientError


def setup_rum_domain(resource_prefix, envname, custom_domain):
def setup_rum_domain(resource_prefix, envname, custom_domain, region):
try:
if custom_domain == 'False':
ssm = boto3.client('ssm', region_name='us-east-1')
webapp_domain = ssm.get_parameter(
Name=f'/dataall/{envname}/CloudfrontDistributionDomainName'
)['Parameter']['Value']
rum = boto3.client('rum')
rum = boto3.client('rum', region_name=region)
rum.get_app_monitor(Name=f'{resource_prefix}-{envname}-monitor')
print('Updating RUM Monitor')
response = rum.update_app_monitor(
Expand All @@ -30,6 +30,7 @@ def setup_rum_domain(resource_prefix, envname, custom_domain):
print(f'Starting RUM Configuration...')
envname = os.environ.get('envname', 'prod')
custom_domain = os.environ.get('custom_domain', 'False')
region = os.environ.get('deployment_region', 'eu-west-1')
resource_prefix = os.environ.get('resource_prefix', 'dataall')
setup_rum_domain(resource_prefix, envname, custom_domain)
setup_rum_domain(resource_prefix, envname, custom_domain, region)
print(f'RUM Configuration Finished Successfully')
1 change: 1 addition & 0 deletions deploy/stacks/ecr_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def __init__(

regions = list(set(regions))
if len(regions) > 1:
regions.remove(self.region)
replication_destinations = []
for region in regions:
replication_destinations.append(
Expand Down
8 changes: 4 additions & 4 deletions deploy/stacks/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ def set_backend_stage(self, target_env, repository_name):
resource_prefix=self.resource_prefix,
tooling_account_id=self.account,
pipeline_bucket=self.pipeline_bucket_name,
ecr_repository=f'arn:aws:ecr:{self.region}:{self.account}:repository/{repository_name}',
ecr_repository=f'arn:aws:ecr:{target_env.get("region", self.region)}:{self.account}:repository/{repository_name}',
commit_id=self.image_tag,
vpc_id=target_env.get('vpc_id'),
vpc_endpoints_sg=target_env.get('vpc_endpoints_sg'),
Expand Down Expand Up @@ -556,9 +556,9 @@ def set_db_migration_stage(
f'echo "role_arn = arn:aws:iam::{target_env["account"]}:role/{self.resource_prefix}-{target_env["envname"]}-cb-dbmigration-role" >> ~/.aws/config',
'echo "credential_source = EcsContainer" >> ~/.aws/config',
'aws sts get-caller-identity --profile buildprofile',
f'aws codebuild start-build --project-name {self.resource_prefix}-{target_env["envname"]}-dbmigration --profile buildprofile > codebuild-id.json',
'aws codebuild batch-get-builds --ids $(jq -r .build.id codebuild-id.json) --profile buildprofile > codebuild-output.json',
'while [ "$(jq -r .builds[0].buildStatus codebuild-output.json)" != "SUCCEEDED" ] && [ "$(jq -r .builds[0].buildStatus codebuild-output.json)" != "FAILED" ]; do echo "running migration"; aws codebuild batch-get-builds --ids $(jq -r .build.id codebuild-id.json) --profile buildprofile > codebuild-output.json; echo "$(jq -r .builds[0].buildStatus codebuild-output.json)"; sleep 5; done',
f'aws codebuild start-build --project-name {self.resource_prefix}-{target_env["envname"]}-dbmigration --profile buildprofile --region {target_env.get("region", self.region)} > codebuild-id.json',
f'aws codebuild batch-get-builds --ids $(jq -r .build.id codebuild-id.json) --profile buildprofile --region {target_env.get("region", self.region)} > codebuild-output.json',
f'while [ "$(jq -r .builds[0].buildStatus codebuild-output.json)" != "SUCCEEDED" ] && [ "$(jq -r .builds[0].buildStatus codebuild-output.json)" != "FAILED" ]; do echo "running migration"; aws codebuild batch-get-builds --ids $(jq -r .build.id codebuild-id.json) --profile buildprofile --region {target_env.get("region", self.region)} > codebuild-output.json; echo "$(jq -r .builds[0].buildStatus codebuild-output.json)"; sleep 5; done',
'if [ "$(jq -r .builds[0].buildStatus codebuild-output.json)" = "FAILED" ]; then echo "Failed"; cat codebuild-output.json; exit -1; fi',
'cat codebuild-output.json ',
],
Expand Down

0 comments on commit eec67a0

Please sign in to comment.