Skip to content

Commit cbf299b

Browse files
Yadan-WeiYadan Wei
andauthored
Add support for public release only (#5408)
* add support for public release only * format and add 2.4 for test * update ecr public describe images * change saved release information * revert temp change and format * remove blank line --------- Co-authored-by: Yadan Wei <[email protected]>
1 parent 9634533 commit cbf299b

File tree

3 files changed

+87
-25
lines changed

3 files changed

+87
-25
lines changed

generate_dlc_image_release_information.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,15 @@ def parse_args():
6969
github_publishing_metadata = json.loads(f.read())
7070

7171
dlc_account_id = github_publishing_metadata.get("target_account_id_classic")
72+
dlc_public_account_id = github_publishing_metadata.get("target_account_id_public")
7273
dlc_tag = github_publishing_metadata.get("tag_with_dlc_version")
74+
is_private_release = github_publishing_metadata.get("private_registry_release", True)
7375
dlc_soci_tag = github_publishing_metadata.get("tag_with_dlc_version_soci", None)
7476
dlc_repository = github_publishing_metadata.get("target_ecr_repository")
7577
dlc_release_successful = github_publishing_metadata.get("release_successful")
7678
dlc_region = os.getenv("REGION")
7779

7880
dlc_public_registry = github_publishing_metadata.get("target_ecr_public_registry")
79-
public_registry_image_uri_with_dlc_version = None
80-
if dlc_public_registry is not None:
81-
public_registry_image_uri_with_dlc_version = (
82-
f"{dlc_public_registry}/{dlc_repository}:{dlc_tag}"
83-
)
8481

8582
if dlc_release_successful != "1":
8683
LOGGER.error(
@@ -89,7 +86,14 @@ def parse_args():
8986
sys.exit(0)
9087

9188
dlc_release_information = DLCReleaseInformation(
92-
dlc_account_id, dlc_region, dlc_repository, dlc_tag, dlc_soci_tag=dlc_soci_tag
89+
dlc_account_id,
90+
dlc_public_account_id,
91+
dlc_region,
92+
dlc_repository,
93+
dlc_tag,
94+
dlc_soci_tag=dlc_soci_tag,
95+
is_private_release=is_private_release,
96+
public_registry=dlc_public_registry,
9397
)
9498

9599
# bom objects below are used to create .tar.gz file to be uploaded as an asset, 'imp' objects are used as release information
@@ -102,8 +106,10 @@ def parse_args():
102106
"image_digest": dlc_release_information.image_digest,
103107
"soci_image_digest": dlc_release_information.soci_image_digest,
104108
"image_uri_with_dlc_version": dlc_release_information.image,
109+
"is_private_registry_release": is_private_release,
105110
"soci_image_uri_with_dlc_version": dlc_release_information.soci_image,
106-
"public_registry_image_uri_with_dlc_version": public_registry_image_uri_with_dlc_version,
111+
"public_image_uri_with_dlc_version": dlc_release_information.public_image,
112+
"public_soci_image_uri_with_dlc_version": dlc_release_information.public_soci_image,
107113
"image_tags": dlc_release_information.image_tags,
108114
"soci_image_tags": dlc_release_information.soci_image_tags,
109115
"dlc_release_successful": dlc_release_successful,
@@ -161,5 +167,10 @@ def parse_args():
161167
os.remove(tarfile_name)
162168
shutil.rmtree(directory)
163169

164-
LOGGER.info(f"Release Information collected for image: {dlc_release_information.image}")
170+
if is_private_release:
171+
LOGGER.info(f"Release Information collected for image: {dlc_release_information.image}")
172+
else:
173+
LOGGER.info(
174+
f"Release Information collected for public image: {dlc_release_information.public_image}"
175+
)
165176
LOGGER.info(f"Release information and BOM uploaded to: {s3BucketURI}")

release/dlc_release_information.py

Lines changed: 67 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,37 @@
1616

1717

1818
class DLCReleaseInformation:
19-
def __init__(self, dlc_account_id, dlc_region, dlc_repository, dlc_tag, dlc_soci_tag=None):
20-
if not all([dlc_account_id, dlc_tag, dlc_repository, dlc_region]):
19+
def __init__(
20+
self,
21+
dlc_account_id,
22+
dlc_public_account_id,
23+
dlc_region,
24+
dlc_repository,
25+
dlc_tag,
26+
dlc_soci_tag=None,
27+
is_private_release=True,
28+
public_registry=None,
29+
):
30+
if not all([dlc_tag, dlc_repository, dlc_region]):
2131
raise ValueError(
22-
"One or multiple environment variables TARGET_ACCOUNT_ID_CLASSIC, TAG_WITH_DLC_VERSION, "
23-
"TARGET_ECR_REPOSITORY, REGION not set. This environment variable is expected to be set by the promoter stage."
32+
"One or multiple environment variables TAG_WITH_DLC_VERSION, "
33+
"TARGET_ECR_REPOSITORY, REGION not set. This environment variable is expected to be set by the promoter stage."
2434
)
2535

36+
if is_private_release and not dlc_account_id:
37+
raise ValueError("dlc_account_id is required for private releases")
38+
39+
if not is_private_release and not dlc_public_account_id:
40+
raise ValueError("dlc_public_account_id is required for public releases only")
41+
2642
self.dlc_account_id = dlc_account_id
43+
self.dlc_public_account_id = dlc_public_account_id
2744
self.dlc_region = dlc_region
2845
self.dlc_repository = dlc_repository
2946
self.dlc_tag = dlc_tag
3047
self.dlc_soci_tag = dlc_soci_tag
48+
self.is_private_release = is_private_release
49+
self.public_registry = public_registry
3150

3251
self.container_name = self.run_container()
3352

@@ -43,6 +62,9 @@ def __init__(self, dlc_account_id, dlc_region, dlc_repository, dlc_tag, dlc_soci
4362
def get_boto3_ecr_client(self):
4463
return boto3.Session(region_name=self.dlc_region).client("ecr")
4564

65+
def get_boto3_ecr_public_client(self):
66+
return boto3.Session(region_name="us-east-1").client("ecr-public")
67+
4668
def run_container(self):
4769
"""
4870
Quickly run a container and assign it a name, so that different commands may be run on it
@@ -53,8 +75,12 @@ def run_container(self):
5375

5476
run(f"docker rm -f {container_name}", warn=True, hide=True)
5577

78+
if self.is_private_release:
79+
image_uri = self.image
80+
else:
81+
image_uri = self.public_image
5682
run(
57-
f"docker run -id --privileged --name {container_name} --entrypoint='/bin/bash' {self.image}",
83+
f"docker run -id --privileged --name {container_name} --entrypoint='/bin/bash' {image_uri}",
5884
hide=True,
5985
)
6086

@@ -75,23 +101,42 @@ def get_container_command_output(self, command):
75101
def get_image_details_from_ecr(self, tag):
76102
if tag is None:
77103
return None
78-
_ecr = self.get_boto3_ecr_client()
79104

80-
try:
81-
response = _ecr.describe_images(
82-
registryId=self.dlc_account_id,
83-
repositoryName=self.dlc_repository,
84-
imageIds=[{"imageTag": tag}],
85-
)
86-
except ClientError as e:
87-
LOGGER.error("ClientError when performing ECR operation. Exception: {}".format(e))
88-
89-
return response["imageDetails"][0]
105+
if self.is_private_release:
106+
_ecr = self.get_boto3_ecr_client()
107+
try:
108+
response = _ecr.describe_images(
109+
registryId=self.dlc_account_id,
110+
repositoryName=self.dlc_repository,
111+
imageIds=[{"imageTag": tag}],
112+
)
113+
except ClientError as e:
114+
LOGGER.error("ClientError when performing ECR operation. Exception: {}".format(e))
115+
return response["imageDetails"][0]
116+
else:
117+
_ecr_public = self.get_boto3_ecr_public_client()
118+
try:
119+
response = _ecr_public.describe_images(
120+
registryId=self.dlc_public_account_id,
121+
repositoryName=self.dlc_repository,
122+
imageIds=[{"imageTag": tag}],
123+
)
124+
except ClientError as e:
125+
LOGGER.error(
126+
"ClientError when performing ECR Public operation. Exception: {}".format(e)
127+
)
128+
return response["imageDetails"][0]
90129

91130
@property
92131
def image(self):
93132
return f"{self.dlc_account_id}.dkr.ecr.{self.dlc_region}.amazonaws.com/{self.dlc_repository}:{self.dlc_tag}"
94133

134+
@property
135+
def public_image(self):
136+
if self.public_registry is None:
137+
return None
138+
return f"{self.public_registry}/{self.dlc_repository}:{self.dlc_tag}"
139+
95140
@property
96141
def image_tags(self):
97142
return self._image_details["imageTags"]
@@ -106,6 +151,12 @@ def soci_image(self):
106151
return None
107152
return f"{self.dlc_account_id}.dkr.ecr.{self.dlc_region}.amazonaws.com/{self.dlc_repository}:{self.dlc_soci_tag}"
108153

154+
@property
155+
def public_soci_image(self):
156+
if self.dlc_soci_tag is None or self.public_registry is None:
157+
return None
158+
return f"{self.public_registry}/{self.dlc_repository}:{self.dlc_soci_tag}"
159+
109160
@property
110161
def soci_image_tags(self):
111162
if self.dlc_soci_tag is None:

release_images_training.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,4 @@ release_images:
103103
neuron_sdk_version: "sdk2.24.1"
104104
example: False
105105
disable_sm_tag: True
106-
force_release: False
106+
force_release: False

0 commit comments

Comments
 (0)