refactor
All checks were successful
Lint Checks / Run linter (pull_request) Successful in 34s
Deploy Test / Run deploy test suite (pull_request) Successful in 5m17s
Webapp Test / Run webapp test suite (pull_request) Successful in 3m25s
K8s Deploy Test / Run deploy test suite on kind/k8s (pull_request) Successful in 6m20s
Smoke Test / Run basic test suite (pull_request) Successful in 4m58s

This commit is contained in:
Thomas E Lackey 2024-02-23 20:58:33 -06:00
parent 694590ed56
commit 39bf0e2795

View File

@ -94,7 +94,7 @@ def process_app_deployment_request(
deployment_dir = os.path.join(deployment_parent_dir, fqdn) deployment_dir = os.path.join(deployment_parent_dir, fqdn)
deployment_config_file = os.path.join(deployment_dir, "config.env") deployment_config_file = os.path.join(deployment_dir, "config.env")
# TODO: Is there any reason not to simplify the hash input to the app_deployment_crn? # TODO: Is there any reason not to simplify the hash input to the app_deployment_crn?
deployment_container_unique_tag = "laconic-webapp/%s:local" % hashlib.md5(deployment_dir.encode()).hexdigest() deployment_container_tag = "laconic-webapp/%s:local" % hashlib.md5(deployment_dir.encode()).hexdigest()
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(deployment_dir): if not os.path.exists(deployment_dir):
@ -102,7 +102,7 @@ def process_app_deployment_request(
raise Exception("Deployment record %s exists, but not deployment dir %s. Please remove name." % raise Exception("Deployment record %s exists, but not deployment dir %s. Please remove name." %
(app_deployment_crn, deployment_dir)) (app_deployment_crn, deployment_dir))
print("deploy_webapp", deployment_dir) print("deploy_webapp", deployment_dir)
deploy_webapp.create_deployment(ctx, deployment_dir, deployment_container_unique_tag, deploy_webapp.create_deployment(ctx, deployment_dir, deployment_container_tag,
f"https://{fqdn}", kube_config, image_registry, env_filename) f"https://{fqdn}", kube_config, image_registry, env_filename)
elif env_filename: elif env_filename:
shutil.copyfile(env_filename, deployment_config_file) shutil.copyfile(env_filename, deployment_config_file)
@ -115,15 +115,15 @@ def process_app_deployment_request(
shared_tag_exists = remote_image_exists(image_registry, app_image_shared_tag) shared_tag_exists = remote_image_exists(image_registry, app_image_shared_tag)
if shared_tag_exists and not force_rebuild: if shared_tag_exists and not force_rebuild:
# simply add our unique tag to the existing image and we are done # simply add our unique tag to the existing image and we are done
print(f"Using existing app image {app_image_shared_tag} for {deployment_container_unique_tag}", file=log_file) print(f"Using existing app image {app_image_shared_tag} for {deployment_container_tag}", file=log_file)
add_tags_to_image(image_registry, app_image_shared_tag, deployment_container_unique_tag) add_tags_to_image(image_registry, app_image_shared_tag, deployment_container_tag)
else: else:
extra_build_args = [] # TODO: pull from request extra_build_args = [] # TODO: pull from request
build_container_image(app, deployment_container_unique_tag, extra_build_args, log_file) build_container_image(app, deployment_container_tag, extra_build_args, log_file)
push_container_image(deployment_dir, log_file) push_container_image(deployment_dir, log_file)
# The build/push commands above will use the unique deployment tag, so now we need to add the shared tag. # The build/push commands above will use the unique deployment tag, so now we need to add the shared tag.
print(f"Updating app image tag {app_image_shared_tag} from build of {deployment_container_unique_tag}", file=log_file) print(f"Updating app image tag {app_image_shared_tag} from build of {deployment_container_tag}", file=log_file)
add_tags_to_image(image_registry, deployment_container_unique_tag, app_image_shared_tag) add_tags_to_image(image_registry, deployment_container_tag, app_image_shared_tag)
# 7. update config (if needed) # 7. update config (if needed)
if not deployment_record or file_hash(deployment_config_file) != deployment_record.attributes.meta.config: if not deployment_record or file_hash(deployment_config_file) != deployment_record.attributes.meta.config: