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