From 19232a2f5a5457c9d23d3c7cb82fd42b754cc7aa Mon Sep 17 00:00:00 2001 From: Arian van Putten Date: Fri, 29 Dec 2023 16:54:02 +0100 Subject: [PATCH 1/2] Create new naming convetion We want the nix store path in there for reference --- upload-ami/src/upload_ami/cli.py | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/upload-ami/src/upload_ami/cli.py b/upload-ami/src/upload_ami/cli.py index e4a2a9e..963124f 100644 --- a/upload-ami/src/upload_ami/cli.py +++ b/upload-ami/src/upload_ami/cli.py @@ -173,14 +173,6 @@ def copy_image(image_id, image_name, source_region, target_region_name): return image_ids -def get_name(image_info, prefix, run_id): - revision = "." + run_id if run_id else "" - image_name = "nixos-" + image_info["label"] + \ - revision + "-" + image_info["system"] - image_name = prefix + image_name if prefix else image_name - return image_name - - def upload_ami(image_info, s3_bucket, copy_to_regions, prefix, run_id, public): """ Upload NixOS AMI to AWS and return the image ids for each region @@ -191,15 +183,15 @@ def upload_ami(image_info, s3_bucket, copy_to_regions, prefix, run_id, public): s3 = boto3.client("s3") image_file = image_info["file"] - s3_key = os.path.join( - os.path.basename(os.path.dirname(image_file) - ), os.path.basename(image_file) - ) + base_name = os.path.basename(os.path.dirname(image_file)) + file_name = os.path.basename(image_file) + s3_key = os.path.join(base_name, file_name) upload_to_s3_if_not_exists(s3, s3_bucket, s3_key, image_file) + image_format = image_info.get("format") or "VHD" snapshot_id = import_snapshot(ec2, s3_bucket, s3_key, image_format) - image_name = get_name(image_info, prefix, run_id) + image_name = prefix + base_name + ("." + run_id if run_id else "") image_id = register_image_if_not_exists( ec2, image_name, image_info, snapshot_id, public) From 5326308a980cf292d921e56da7880228eff57d1b Mon Sep 17 00:00:00 2001 From: Arian van Putten Date: Fri, 29 Dec 2023 16:58:02 +0100 Subject: [PATCH 2/2] Drive by: fix tries in smoke test --- upload-ami/src/upload_ami/smoke_test.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/upload-ami/src/upload_ami/smoke_test.py b/upload-ami/src/upload_ami/smoke_test.py index ef0d98a..45ee306 100644 --- a/upload-ami/src/upload_ami/smoke_test.py +++ b/upload-ami/src/upload_ami/smoke_test.py @@ -38,13 +38,14 @@ def smoke_test(image_id, region, run_id, cancel): tries = 5 console_output = ec2.get_console_output(InstanceId=instance_id, Latest=True) output = console_output.get("Output") - while output is None: + while not output and tries > 0: time.sleep(10) logging.info( f"Waiting for console output to become available ({tries} tries left)" ) console_output = ec2.get_console_output(InstanceId=instance_id, Latest=True) output = console_output.get("Output") + tries -= 1 print(output) finally: logging.info(f"Terminating instance {instance_id}")