oci parsing: make image name case insensitive (#40858)

This commit is contained in:
Harmen Stoppels 2023-11-03 12:50:30 +01:00 committed by GitHub
parent fe0cf80e05
commit 3082ce6a22
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 3 deletions

View file

@ -9,8 +9,10 @@
import spack.spec
# all the building blocks
alphanumeric = r"[a-z0-9]+"
# notice: Docker is more strict (no uppercase allowed). We parse image names *with* uppercase
# and normalize, so: example.com/Organization/Name -> example.com/organization/name. Tags are
# case sensitive though.
alphanumeric_with_uppercase = r"[a-zA-Z0-9]+"
separator = r"(?:[._]|__|[-]+)"
localhost = r"localhost"
domainNameComponent = r"(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])"
@ -25,7 +27,7 @@
domainAndPort = rf"{host}{optionalPort}"
# image name
pathComponent = rf"{alphanumeric}(?:{separator}{alphanumeric})*"
pathComponent = rf"{alphanumeric_with_uppercase}(?:{separator}{alphanumeric_with_uppercase})*"
remoteName = rf"{pathComponent}(?:\/{pathComponent})*"
namePat = rf"(?:{domainAndPort}\/)?{remoteName}"
@ -130,6 +132,11 @@ def from_string(cls, string) -> "ImageReference":
name = f"{domain}/{name}"
domain = "index.docker.io"
# Lowercase the image name. This is enforced by Docker, although the OCI spec isn't clear?
# We do this anyways, cause for example in Github Actions the <organization>/<repository>
# part can have uppercase, and may be interpolated when specifying the relevant OCI image.
name = name.lower()
if not tag:
tag = "latest"

View file

@ -34,6 +34,10 @@
("myname:1234/myimage:abc", ("myname:1234", "myimage", "abc", None)),
("localhost/myimage:abc", ("localhost", "myimage", "abc", None)),
("localhost:1234/myimage:abc", ("localhost:1234", "myimage", "abc", None)),
(
"example.com/UPPERCASE/lowercase:AbC",
("example.com", "uppercase/lowercase", "AbC", None),
),
],
)
def test_name_parsing(image_ref, expected):