Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create new naming convetion #40

Merged
merged 2 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions upload-ami/src/upload_ami/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down
3 changes: 2 additions & 1 deletion upload-ami/src/upload_ami/smoke_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down