oci parsing: make image name case insensitive (#40858)
This commit is contained in:
parent
fe0cf80e05
commit
3082ce6a22
2 changed files with 14 additions and 3 deletions
|
@ -9,8 +9,10 @@
|
||||||
|
|
||||||
import spack.spec
|
import spack.spec
|
||||||
|
|
||||||
# all the building blocks
|
# notice: Docker is more strict (no uppercase allowed). We parse image names *with* uppercase
|
||||||
alphanumeric = r"[a-z0-9]+"
|
# 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"(?:[._]|__|[-]+)"
|
separator = r"(?:[._]|__|[-]+)"
|
||||||
localhost = r"localhost"
|
localhost = r"localhost"
|
||||||
domainNameComponent = r"(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])"
|
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}"
|
domainAndPort = rf"{host}{optionalPort}"
|
||||||
|
|
||||||
# image name
|
# image name
|
||||||
pathComponent = rf"{alphanumeric}(?:{separator}{alphanumeric})*"
|
pathComponent = rf"{alphanumeric_with_uppercase}(?:{separator}{alphanumeric_with_uppercase})*"
|
||||||
remoteName = rf"{pathComponent}(?:\/{pathComponent})*"
|
remoteName = rf"{pathComponent}(?:\/{pathComponent})*"
|
||||||
namePat = rf"(?:{domainAndPort}\/)?{remoteName}"
|
namePat = rf"(?:{domainAndPort}\/)?{remoteName}"
|
||||||
|
|
||||||
|
@ -130,6 +132,11 @@ def from_string(cls, string) -> "ImageReference":
|
||||||
name = f"{domain}/{name}"
|
name = f"{domain}/{name}"
|
||||||
domain = "index.docker.io"
|
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:
|
if not tag:
|
||||||
tag = "latest"
|
tag = "latest"
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,10 @@
|
||||||
("myname:1234/myimage:abc", ("myname:1234", "myimage", "abc", None)),
|
("myname:1234/myimage:abc", ("myname:1234", "myimage", "abc", None)),
|
||||||
("localhost/myimage:abc", ("localhost", "myimage", "abc", None)),
|
("localhost/myimage:abc", ("localhost", "myimage", "abc", None)),
|
||||||
("localhost:1234/myimage:abc", ("localhost:1234", "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):
|
def test_name_parsing(image_ref, expected):
|
||||||
|
|
Loading…
Reference in a new issue