Skip to content

Commit

Permalink
make image public
Browse files Browse the repository at this point in the history
  • Loading branch information
arianvp committed Dec 16, 2023
1 parent 9ce5cae commit b215b49
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions upload_ami/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ def register_image_if_not_exists(ec2, image_name, image_info, snapshot_id):
raise Exception("Unknown system: " + image_info["system"])

logging.info(f"Registering image {image_name} with snapshot {snapshot_id}")
tpmsupport = { }
tpmsupport = {}
if architecture == "x86_64" and image_info["boot_mode"] == "uefi":
tpmsupport['TpmSupport'] = "v2.0"
tpmsupport["TpmSupport"] = "v2.0"
register_image = ec2.register_image(
Name=image_name,
Architecture=architecture,
Expand All @@ -96,13 +96,21 @@ def register_image_if_not_exists(ec2, image_name, image_info, snapshot_id):
EnaSupport=True,
ImdsSupport="v2.0",
SriovNetSupport="simple",
**tpmsupport
**tpmsupport,
)
image_id = register_image["ImageId"]

ec2.get_waiter("image_available").wait(ImageIds=[image_id])
return image_id

def make_image_public(ec2, image_id: str):
"""
Set launch permissions for image
"""
ec2.modify_image_attribute(
ImageId=image_id,
LaunchPermission={"Add": [{"Group": "all"}]},
)

def copy_image_to_regions(image_id, image_name, source_region, target_regions):
"""
Expand Down Expand Up @@ -139,6 +147,7 @@ def copy_image(image_id, image_name, source_region, target_region_name):
logging.info(
f"Finished image {image_id} from {source_region} to {target_region_name}"
)
make_image_public(ec2r, copy_image["ImageId"])
return (target_region_name, copy_image["ImageId"])

with ThreadPoolExecutor() as executor:
Expand All @@ -155,6 +164,8 @@ def copy_image(image_id, image_name, source_region, target_region_name):
return image_ids




def upload_ami(image_info, s3_bucket, copy_to_regions, run_id):
"""
Upload NixOS AMI to AWS and return the image ids for each region
Expand All @@ -174,6 +185,7 @@ def upload_ami(image_info, s3_bucket, copy_to_regions, run_id):
image_format = image_info.get("format") or "VHD"
snapshot_id = import_snapshot(ec2, s3_bucket, s3_key, image_format)
image_id = register_image_if_not_exists(ec2, image_name, image_info, snapshot_id)
make_image_public(ec2, image_id)

regions = ec2.describe_regions()["Regions"]

Expand Down

0 comments on commit b215b49

Please sign in to comment.