From ca3636807672f0234b39cc68559d320a46289659 Mon Sep 17 00:00:00 2001 From: Flippie Scholtz Date: Fri, 26 Aug 2022 14:50:51 +0200 Subject: [PATCH] CIV-5336 Dynamically set backend_url in frontend configmap based on environment ( did.civic.com for prod and did-dev.civic.com for dev ) --- .../configmap-uni-resolver-frontend.yaml | 2 +- ci/deploy-k8s-aws/scripts/prepare-deployment.py | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/ci/deploy-k8s-aws/app-specs/configmap-uni-resolver-frontend.yaml b/ci/deploy-k8s-aws/app-specs/configmap-uni-resolver-frontend.yaml index 3afebb6b2..bdaa14a64 100644 --- a/ci/deploy-k8s-aws/app-specs/configmap-uni-resolver-frontend.yaml +++ b/ci/deploy-k8s-aws/app-specs/configmap-uni-resolver-frontend.yaml @@ -3,4 +3,4 @@ kind: ConfigMap metadata: name: uni-resolver-frontend data: - backend_url: https://did.civic.com/ + backend_url: {{backendUrl}} diff --git a/ci/deploy-k8s-aws/scripts/prepare-deployment.py b/ci/deploy-k8s-aws/scripts/prepare-deployment.py index 42888b153..82846eb0b 100755 --- a/ci/deploy-k8s-aws/scripts/prepare-deployment.py +++ b/ci/deploy-k8s-aws/scripts/prepare-deployment.py @@ -202,18 +202,28 @@ def generate_ingress(containers, outputdir, deploymentdomain): fout.close() -def copy_app_deployment_specs(outputdir): +def copy_app_deployment_specs(outputdir, deploymentdomain): print('#### Current python working path') working_path = pathlib.Path().absolute() print(working_path) # Configmap has to be deployed before the applications - copy('/app-specs/configmap-uni-resolver-frontend.yaml', outputdir + '/configmap-uni-resolver-frontend.yaml') + replace_and_copy('/app-specs/configmap-uni-resolver-frontend.yaml', outputdir + '/configmap-uni-resolver-frontend.yaml', 'backendUrl', deploymentdomain) add_deployment('configmap-uni-resolver-frontend.yaml', outputdir) copy('/app-specs/deployment-uni-resolver-frontend.yaml', outputdir + '/deployment-uni-resolver-frontend.yaml') add_deployment('deployment-uni-resolver-frontend.yaml', outputdir) copy('/app-specs/deployment-uni-resolver-web.yaml', outputdir + '/deployment-uni-resolver-web.yaml') add_deployment('deployment-uni-resolver-web.yaml', outputdir) +def replace_and_copy(infile, outfile, templateKey, value): + fin = open(infile, "r") + fout = open(outfile, "w") + for line in fin: + print('Replacing ' + '{{' + templateKey + '}}' + ' with ' + value) + fout.write(line.replace('{{' + templateKey + '}}', value)) + fout.close() + fin.close() + + def main(argv): print('#### Current python script path') absolute_path = pathlib.Path(__file__).parent.absolute() @@ -258,7 +268,7 @@ def main(argv): generate_deployment_specs(containers, outputdir) # copy app deployment specs - copy_app_deployment_specs(outputdir) + copy_app_deployment_specs(outputdir, deploymentdomain) # copy namespace files copy('/namespace/namespace-setup.yaml', './deploy/namespace-setup.yaml')