Add logging to webapp deployer (#863)
All checks were successful
Lint Checks / Run linter (push) Successful in 32s
Publish / Build and publish (push) Successful in 1m7s
Deploy Test / Run deploy test suite (push) Successful in 4m46s
Webapp Test / Run webapp test suite (push) Successful in 4m17s
Smoke Test / Run basic test suite (push) Successful in 3m59s

Helps with diagnosing failures and odd behavior seen in the deployer in production.

Reviewed-on: #863
Co-authored-by: David Boreham <david@bozemanpass.com>
Co-committed-by: David Boreham <david@bozemanpass.com>
This commit is contained in:
David Boreham 2024-07-04 19:46:42 +00:00 committed by David Boreham
parent df776c1b4c
commit ca5fffaed5
2 changed files with 11 additions and 5 deletions

View File

@ -122,21 +122,26 @@ 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
logger.log(f"Using existing app image {app_image_shared_tag} for {deployment_container_tag}") logger.log(
f"Existing image found for this app: {app_image_shared_tag} "
"tagging it with: {deployment_container_tag} to use in this deployment"
)
add_tags_to_image(image_registry, app_image_shared_tag, deployment_container_tag) add_tags_to_image(image_registry, app_image_shared_tag, deployment_container_tag)
logger.log("Tag complete") logger.log("Tag complete")
else: else:
extra_build_args = [] # TODO: pull from request extra_build_args = [] # TODO: pull from request
logger.log(f"Building container image {deployment_container_tag}") logger.log(f"Building container image: {deployment_container_tag}")
build_container_image(app, deployment_container_tag, extra_build_args, logger) build_container_image(app, deployment_container_tag, extra_build_args, logger)
logger.log("Build complete") logger.log("Build complete")
logger.log(f"Pushing container image {deployment_container_tag}") logger.log(f"Pushing container image: {deployment_container_tag}")
push_container_image(deployment_dir, logger) push_container_image(deployment_dir, logger)
logger.log("Push complete") logger.log("Push complete")
# 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.
logger.log(f"Updating app image tag {app_image_shared_tag} from build of {deployment_container_tag}") logger.log(f"Adding global app image tag: {app_image_shared_tag} to newly built image: {deployment_container_tag}")
add_tags_to_image(image_registry, deployment_container_tag, app_image_shared_tag) add_tags_to_image(image_registry, deployment_container_tag, app_image_shared_tag)
logger.log("Tag complete") logger.log("Tag complete")
else:
logger.log("Requested app is already deployed, skipping build and image push")
# 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:

View File

@ -299,11 +299,12 @@ def push_container_image(deployment_dir, logger):
def deploy_to_k8s(deploy_record, deployment_dir, logger): def deploy_to_k8s(deploy_record, deployment_dir, logger):
if not deploy_record: if not deploy_record:
command = "up" command = "start"
else: else:
command = "update" command = "update"
logger.log("Deploying to k8s ...") logger.log("Deploying to k8s ...")
logger.log(f"Running {command} command on deployment dir: {deployment_dir}")
result = subprocess.run([sys.argv[0], "deployment", "--dir", deployment_dir, command], result = subprocess.run([sys.argv[0], "deployment", "--dir", deployment_dir, command],
stdout=logger.file, stderr=logger.file) stdout=logger.file, stderr=logger.file)
result.check_returncode() result.check_returncode()