forked from cerc-io/stack-orchestrator
Update existing deployment spec with new urls
This commit is contained in:
parent
3d1a455344
commit
cdd431d8a5
@ -15,6 +15,7 @@
|
||||
|
||||
import click
|
||||
import os
|
||||
import yaml
|
||||
from pathlib import Path
|
||||
from urllib.parse import urlparse
|
||||
from tempfile import NamedTemporaryFile
|
||||
@ -36,26 +37,35 @@ def _fixup_container_tag(deployment_dir: str, image: str):
|
||||
wfile.write(contents)
|
||||
|
||||
|
||||
def _fixup_url_spec(spec_file_name: str, urls: list[str]):
|
||||
def fixup_url_spec(spec_file_name: str, urls: list[str]):
|
||||
spec_file_path = Path(spec_file_name)
|
||||
|
||||
# Load existing spec
|
||||
with open(spec_file_path, "r") as file:
|
||||
spec_data = yaml.safe_load(file) or {}
|
||||
|
||||
# Build new http-proxy entries
|
||||
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''')
|
||||
http_proxy_entries.append({
|
||||
"host-name": parsed_url.hostname,
|
||||
"routes": [
|
||||
{
|
||||
"path": parsed_url.path if parsed_url.path else "/",
|
||||
"proxy-to": "webapp:80"
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
http_proxy_spec = f'''
|
||||
http-proxy:{''.join(http_proxy_entries)}
|
||||
'''
|
||||
# Update the spec
|
||||
if "network" not in spec_data:
|
||||
spec_data["network"] = {}
|
||||
spec_data["network"]["http-proxy"] = http_proxy_entries
|
||||
|
||||
spec_file_path = Path(spec_file_name)
|
||||
with open(spec_file_path, "r") as rfile:
|
||||
contents = rfile.read()
|
||||
contents += http_proxy_spec
|
||||
with open(spec_file_path, "w") as wfile:
|
||||
wfile.write(contents)
|
||||
# Write back the updated YAML
|
||||
with open(spec_file_path, "w") as file:
|
||||
yaml.dump(spec_data, file, default_flow_style=False, sort_keys=False)
|
||||
|
||||
|
||||
def create_deployment(ctx, deployment_dir, image, urls, kube_config, image_registry, env_file):
|
||||
@ -90,7 +100,7 @@ def create_deployment(ctx, deployment_dir, image, urls, kube_config, image_regis
|
||||
None
|
||||
)
|
||||
# Add the TLS and DNS spec
|
||||
_fixup_url_spec(spec_file_name, urls)
|
||||
fixup_url_spec(spec_file_name, urls)
|
||||
create_operation(
|
||||
deploy_command_context,
|
||||
spec_file_name,
|
||||
|
@ -26,6 +26,7 @@ import yaml
|
||||
import click
|
||||
import gnupg
|
||||
|
||||
from stack_orchestrator import constants
|
||||
from stack_orchestrator.deploy.images import remote_image_exists
|
||||
from stack_orchestrator.deploy.webapp import deploy_webapp
|
||||
from stack_orchestrator.deploy.webapp.util import (
|
||||
@ -207,7 +208,8 @@ def process_app_deployment_request(
|
||||
deployment_config_file = os.path.join(deployment_dir, "config.env")
|
||||
shutil.copyfile(env_filename, deployment_config_file)
|
||||
|
||||
# TODO: Update spec with new urls
|
||||
# Update existing deployment spec with new urls
|
||||
deploy_webapp.fixup_url_spec(os.path.join(deployment_dir, constants.spec_file_name))
|
||||
|
||||
# TODO: Update with deployment_container_tag if it's not a redeployment
|
||||
# as for redeployment, deployment_container_tag won't get built
|
||||
|
Loading…
Reference in New Issue
Block a user