forked from cerc-io/stack-orchestrator
Check for existing deployment
This commit is contained in:
parent
a8e7235267
commit
f5947a8a65
@ -158,18 +158,23 @@ def process_app_deployment_request(
|
|||||||
% app_deployment_request.attributes.deployment
|
% app_deployment_request.attributes.deployment
|
||||||
)
|
)
|
||||||
|
|
||||||
# Target deployment dir and existing deployment dir
|
# Target deployment dir
|
||||||
deployment_dir = os.path.join(deployment_parent_dir, fqdns[-1])
|
deployment_dir = os.path.join(deployment_parent_dir, fqdns[-1])
|
||||||
existing_deployment_dir = deployment_dir
|
|
||||||
|
|
||||||
# Existing deployment record: take the first lrn that resolves
|
# Existing deployment record: take the first lrn that resolves
|
||||||
deployment_record = None
|
deployment_record = None
|
||||||
|
existing_deployment_dir = deployment_dir # Default to target dir in case the app had been undeployed
|
||||||
for app_deployment_lrn in app_deployment_lrns:
|
for app_deployment_lrn in app_deployment_lrns:
|
||||||
deployment_record = laconic.get_record(app_deployment_lrn)
|
deployment_record = laconic.get_record(app_deployment_lrn)
|
||||||
if deployment_record is not None:
|
if deployment_record:
|
||||||
# TODO: Determine the deployment dir for existing deployment
|
# Determine the deployment dir for existing deployment
|
||||||
# prev_request = laconic.get_record(deployment_record.attributes.request, True)
|
dir_name = deployment_record.attributes.url.replace("https://", "")
|
||||||
# existing_deployment_dir = ...
|
existing_deployment_dir = os.path.join(deployment_parent_dir, dir_name)
|
||||||
|
if not os.path.exists(existing_deployment_dir):
|
||||||
|
raise Exception(
|
||||||
|
"Deployment record %s exists, but not deployment dir %s. Please remove name."
|
||||||
|
% (app_deployment_lrn, existing_deployment_dir)
|
||||||
|
)
|
||||||
|
|
||||||
break
|
break
|
||||||
|
|
||||||
@ -177,16 +182,10 @@ def process_app_deployment_request(
|
|||||||
# At present we use this to generate a unique but stable ID for the app's host container
|
# At present we use this to generate a unique but stable ID for the app's host container
|
||||||
# TODO: implement support to derive this transparently from the already-unique deployment id
|
# TODO: implement support to derive this transparently from the already-unique deployment id
|
||||||
unique_deployment_id = hashlib.md5(fqdns[-1].encode()).hexdigest()[:16]
|
unique_deployment_id = hashlib.md5(fqdns[-1].encode()).hexdigest()[:16]
|
||||||
deployment_config_file = os.path.join(existing_deployment_dir, "config.env")
|
|
||||||
deployment_container_tag = "laconic-webapp/%s:local" % unique_deployment_id
|
deployment_container_tag = "laconic-webapp/%s:local" % unique_deployment_id
|
||||||
app_image_shared_tag = f"laconic-webapp/{app.id}:local"
|
app_image_shared_tag = f"laconic-webapp/{app.id}:local"
|
||||||
# b. check for deployment directory (create if necessary)
|
# b. check for deployment directory (create if necessary)
|
||||||
if not os.path.exists(existing_deployment_dir):
|
if not os.path.exists(existing_deployment_dir):
|
||||||
if deployment_record:
|
|
||||||
raise Exception(
|
|
||||||
"Deployment record %s exists, but not deployment dir %s. Please remove name."
|
|
||||||
% (app_deployment_lrn, deployment_dir)
|
|
||||||
)
|
|
||||||
logger.log(
|
logger.log(
|
||||||
f"Creating webapp deployment in: {deployment_dir} with container id: {deployment_container_tag}"
|
f"Creating webapp deployment in: {deployment_dir} with container id: {deployment_container_tag}"
|
||||||
)
|
)
|
||||||
@ -200,8 +199,14 @@ def process_app_deployment_request(
|
|||||||
image_registry,
|
image_registry,
|
||||||
env_filename,
|
env_filename,
|
||||||
)
|
)
|
||||||
elif env_filename:
|
else:
|
||||||
shutil.copyfile(env_filename, deployment_config_file)
|
# Rename deployment dir according to new request (last fqdn from given dns)
|
||||||
|
os.rename(existing_deployment_dir, deployment_dir)
|
||||||
|
|
||||||
|
# Update config if required
|
||||||
|
if env_filename:
|
||||||
|
deployment_config_file = os.path.join(deployment_dir, "config.env")
|
||||||
|
shutil.copyfile(env_filename, deployment_config_file)
|
||||||
|
|
||||||
# TODO: Update spec with new urls
|
# TODO: Update spec with new urls
|
||||||
|
|
||||||
@ -210,8 +215,6 @@ def process_app_deployment_request(
|
|||||||
# if deployment_record.attributes.application != app.id:
|
# if deployment_record.attributes.application != app.id:
|
||||||
# ...
|
# ...
|
||||||
|
|
||||||
# Rename deployment dir according to new request (last fqdn from given dns)
|
|
||||||
os.rename(existing_deployment_dir, deployment_dir)
|
|
||||||
|
|
||||||
needs_k8s_deploy = False
|
needs_k8s_deploy = False
|
||||||
if force_rebuild:
|
if force_rebuild:
|
||||||
@ -646,6 +649,7 @@ def command( # noqa: C901
|
|||||||
requests_to_check_for_payment.append(r)
|
requests_to_check_for_payment.append(r)
|
||||||
|
|
||||||
requests_to_execute = []
|
requests_to_execute = []
|
||||||
|
# TODO: Charge more for multiple dns?
|
||||||
for r in requests_to_check_for_payment:
|
for r in requests_to_check_for_payment:
|
||||||
if r.attributes.auction:
|
if r.attributes.auction:
|
||||||
if auction_requests:
|
if auction_requests:
|
||||||
|
Loading…
Reference in New Issue
Block a user