@@ -94,20 +94,30 @@ def helm_handler(event, context):
94
94
95
95
96
96
def get_oci_cmd (repository , version ):
97
-
97
+ # Generates OCI command based on pattern. Public ECR vs Private ECR are treated differently.
98
98
cmnd = []
99
- pattern = '\d+.dkr.ecr.[a-z]+-[a-z]+-\d.amazonaws.com'
99
+ private_ecr_pattern = '\d+.dkr.ecr.[a-z]+-[a-z]+-\d.amazonaws.com'
100
+ public_ecr = 'public.ecr.aws'
100
101
101
102
registry = repository .rsplit ('/' , 1 )[0 ].replace ('oci://' , '' )
102
103
103
- if re .fullmatch (pattern , registry ) is not None :
104
+ if re .fullmatch (private_ecr_pattern , registry ) is not None :
105
+ logger .info ("Found AWS private repository" )
104
106
region = registry .replace ('.amazonaws.com' , '' ).split ('.' )[- 1 ]
105
107
cmnd = [
106
108
f"aws ecr get-login-password --region { region } | " \
107
109
f"helm registry login --username AWS --password-stdin { registry } ; helm pull { repository } --version { version } --untar"
108
110
]
111
+ elif registry .startswith (public_ecr ):
112
+ logger .info ("Found AWS public repository, will use default region as deployment" )
113
+ region = os .environ .get ('AWS_REGION' , 'us-east-1' )
114
+
115
+ cmnd = [
116
+ f"aws ecr-public get-login-password --region { region } | " \
117
+ f"helm registry login --username AWS --password-stdin { public_ecr } ; helm pull { repository } --version { version } --untar"
118
+ ]
109
119
else :
110
- logger .info ( "Non AWS OCI repository found " )
120
+ logger .error ( " OCI repository format not recognized, falling back to helm pull " )
111
121
cmnd = ['helm' , 'pull' , repository , '--version' , version , '--untar' ]
112
122
113
123
return cmnd
@@ -122,8 +132,7 @@ def get_chart_from_oci(tmpdir, release, repository = None, version = None):
122
132
while retry > 0 :
123
133
try :
124
134
logger .info (cmnd )
125
- env = get_env_with_oci_flag ()
126
- output = subprocess .check_output (cmnd , stderr = subprocess .STDOUT , cwd = tmpdir , env = env )
135
+ output = subprocess .check_output (cmnd , stderr = subprocess .STDOUT , cwd = tmpdir , shell = True )
127
136
logger .info (output )
128
137
129
138
return os .path .join (tmpdir , release )
@@ -137,13 +146,6 @@ def get_chart_from_oci(tmpdir, release, repository = None, version = None):
137
146
raise Exception (f'Operation failed after { maxAttempts } attempts: { output } ' )
138
147
139
148
140
- def get_env_with_oci_flag ():
141
- env = os .environ .copy ()
142
- env ['HELM_EXPERIMENTAL_OCI' ] = '1'
143
-
144
- return env
145
-
146
-
147
149
def helm (verb , release , chart = None , repo = None , file = None , namespace = None , version = None , wait = False , timeout = None , create_namespace = None ):
148
150
import subprocess
149
151
@@ -172,8 +174,7 @@ def helm(verb, release, chart = None, repo = None, file = None, namespace = None
172
174
retry = maxAttempts
173
175
while retry > 0 :
174
176
try :
175
- env = get_env_with_oci_flag ()
176
- output = subprocess .check_output (cmnd , stderr = subprocess .STDOUT , cwd = outdir , env = env )
177
+ output = subprocess .check_output (cmnd , stderr = subprocess .STDOUT , cwd = outdir )
177
178
logger .info (output )
178
179
return
179
180
except subprocess .CalledProcessError as exc :
0 commit comments