From 3d1a455344614e28488f256a5a527ce0ae0dc521 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Wed, 5 Feb 2025 18:45:46 +0530 Subject: [PATCH] Configure spec with all given URLs --- .../deploy/webapp/deploy_webapp.py | 26 +++++++++++-------- .../webapp/deploy_webapp_from_registry.py | 4 +-- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/stack_orchestrator/deploy/webapp/deploy_webapp.py b/stack_orchestrator/deploy/webapp/deploy_webapp.py index 4c91dec3..54f833aa 100644 --- a/stack_orchestrator/deploy/webapp/deploy_webapp.py +++ b/stack_orchestrator/deploy/webapp/deploy_webapp.py @@ -36,25 +36,29 @@ def _fixup_container_tag(deployment_dir: str, image: str): wfile.write(contents) -def _fixup_url_spec(spec_file_name: str, url: str): - # url is like: https://example.com/path - parsed_url = urlparse(url) - http_proxy_spec = f''' - http-proxy: +def _fixup_url_spec(spec_file_name: str, urls: list[str]): + http_proxy_entries = [] + for url in urls: + parsed_url = urlparse(url) + http_proxy_entries.append(f''' - host-name: {parsed_url.hostname} routes: - path: '{parsed_url.path if parsed_url.path else "/"}' - proxy-to: webapp:80 + proxy-to: webapp:80''') + + http_proxy_spec = f''' + http-proxy:{''.join(http_proxy_entries)} ''' + spec_file_path = Path(spec_file_name) - with open(spec_file_path) as rfile: + with open(spec_file_path, "r") as rfile: contents = rfile.read() - contents = contents + http_proxy_spec + contents += http_proxy_spec with open(spec_file_path, "w") as wfile: wfile.write(contents) -def create_deployment(ctx, deployment_dir, image, url, kube_config, image_registry, env_file): +def create_deployment(ctx, deployment_dir, image, urls, kube_config, image_registry, env_file): # Do the equivalent of: # 1. laconic-so --stack webapp-template deploy --deploy-to k8s init --output webapp-spec.yml # --config (eqivalent of the contents of my-config.env) @@ -86,7 +90,7 @@ def create_deployment(ctx, deployment_dir, image, url, kube_config, image_regist None ) # Add the TLS and DNS spec - _fixup_url_spec(spec_file_name, url) + _fixup_url_spec(spec_file_name, urls) create_operation( deploy_command_context, spec_file_name, @@ -120,4 +124,4 @@ def command(ctx): def create(ctx, deployment_dir, image, url, kube_config, image_registry, env_file): '''create a deployment for the specified webapp container''' - return create_deployment(ctx, deployment_dir, image, url, kube_config, image_registry, env_file) + return create_deployment(ctx, deployment_dir, image, [url], kube_config, image_registry, env_file) diff --git a/stack_orchestrator/deploy/webapp/deploy_webapp_from_registry.py b/stack_orchestrator/deploy/webapp/deploy_webapp_from_registry.py index e9559ea5..92c16bce 100644 --- a/stack_orchestrator/deploy/webapp/deploy_webapp_from_registry.py +++ b/stack_orchestrator/deploy/webapp/deploy_webapp_from_registry.py @@ -189,12 +189,11 @@ def process_app_deployment_request( logger.log( f"Creating webapp deployment in: {deployment_dir} with container id: {deployment_container_tag}" ) - # TODO: Pass URLs for all fqdns deploy_webapp.create_deployment( ctx, deployment_dir, deployment_container_tag, - f"https://{fqdns[-1]}", + [f"https://{fqdn}" for fqdn in fqdns], kube_config, image_registry, env_filename, @@ -649,7 +648,6 @@ def command( # noqa: C901 requests_to_check_for_payment.append(r) requests_to_execute = [] - # TODO: Charge more for multiple dns? for r in requests_to_check_for_payment: if r.attributes.auction: if auction_requests: