|
6 | 6 | import shutil
|
7 | 7 | import tempfile
|
8 | 8 | import zipfile
|
9 |
| -from urllib.parse import urlparse, unquote |
10 | 9 |
|
11 | 10 | logger = logging.getLogger()
|
12 | 11 | logger.setLevel(logging.INFO)
|
@@ -95,26 +94,25 @@ def helm_handler(event, context):
|
95 | 94 |
|
96 | 95 | def get_oci_cmd(repository, version):
|
97 | 96 | # Generates OCI command based on pattern. Public ECR vs Private ECR are treated differently.
|
98 |
| - cmnd = [] |
99 |
| - private_ecr_pattern = '\d+.dkr.ecr.[a-z]+-[a-z]+-\d.amazonaws.com' |
100 |
| - public_ecr = 'public.ecr.aws' |
| 97 | + private_ecr_pattern = 'oci://(?P<registry>\d+.dkr.ecr.(?P<region>[a-z]+-[a-z]+-\d).amazonaws.com)*' |
| 98 | + public_ecr_pattern = 'oci://(?P<registry>public.ecr.aws)*' |
101 | 99 |
|
102 |
| - registry = repository.rsplit('/', 1)[0].replace('oci://', '') |
| 100 | + private_registry = re.match(private_ecr_pattern, repository).groupdict() |
| 101 | + public_registry = re.match(public_ecr_pattern, repository).groupdict() |
103 | 102 |
|
104 |
| - if re.fullmatch(private_ecr_pattern, registry) is not None: |
| 103 | + if private_registry['registry'] is not None: |
105 | 104 | logger.info("Found AWS private repository")
|
106 |
| - region = registry.replace('.amazonaws.com', '').split('.')[-1] |
107 | 105 | cmnd = [
|
108 |
| - f"aws ecr get-login-password --region {region} | " \ |
109 |
| - f"helm registry login --username AWS --password-stdin {registry}; helm pull {repository} --version {version} --untar" |
| 106 | + f"aws ecr get-login-password --region {private_registry['region']} | " \ |
| 107 | + f"helm registry login --username AWS --password-stdin {private_registry['registry']}; helm pull {repository} --version {version} --untar" |
110 | 108 | ]
|
111 |
| - elif registry.startswith(public_ecr): |
| 109 | + elif public_registry['registry'] is not None: |
112 | 110 | logger.info("Found AWS public repository, will use default region as deployment")
|
113 | 111 | region = os.environ.get('AWS_REGION', 'us-east-1')
|
114 | 112 |
|
115 | 113 | cmnd = [
|
116 | 114 | 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" |
| 115 | + f"helm registry login --username AWS --password-stdin {public_registry['registry']}; helm pull {repository} --version {version} --untar" |
118 | 116 | ]
|
119 | 117 | else:
|
120 | 118 | logger.error("OCI repository format not recognized, falling back to helm pull")
|
|
0 commit comments