1616
1717
1818class 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 :
0 commit comments