-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: find images when there is an oci index (#462)
This was causing the API to consider some images as non-existing. Whereas in reality they exist. I noticed this with this image: ghcr.io/salimkayal/renku-devcontainer-wizard:latest.
- Loading branch information
Showing
2 changed files
with
228 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
214 changes: 214 additions & 0 deletions
214
test/components/renku_data_services/notebooks/test_notebooks_image_checks.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,214 @@ | ||
from dataclasses import asdict | ||
from pathlib import PurePosixPath | ||
|
||
import pytest | ||
|
||
from renku_data_services.notebooks.api.classes.image import Image | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"name,expected", | ||
[ | ||
( | ||
"nginx", | ||
{ | ||
"hostname": "registry-1.docker.io", | ||
"name": "library/nginx", | ||
"tag": "latest", | ||
}, | ||
), | ||
( | ||
"nginx:1.28", | ||
{ | ||
"hostname": "registry-1.docker.io", | ||
"name": "library/nginx", | ||
"tag": "1.28", | ||
}, | ||
), | ||
( | ||
"nginx@sha256:24235rt2rewg345ferwf", | ||
{ | ||
"hostname": "registry-1.docker.io", | ||
"name": "library/nginx", | ||
"tag": "sha256:24235rt2rewg345ferwf", | ||
}, | ||
), | ||
( | ||
"username/image", | ||
{ | ||
"hostname": "registry-1.docker.io", | ||
"name": "username/image", | ||
"tag": "latest", | ||
}, | ||
), | ||
( | ||
"username/image:1.0.0", | ||
{ | ||
"hostname": "registry-1.docker.io", | ||
"name": "username/image", | ||
"tag": "1.0.0", | ||
}, | ||
), | ||
( | ||
"username/image@sha256:fdsaf345tre3412t1413r", | ||
{ | ||
"hostname": "registry-1.docker.io", | ||
"name": "username/image", | ||
"tag": "sha256:fdsaf345tre3412t1413r", | ||
}, | ||
), | ||
( | ||
"gitlab.smth.com/username/project", | ||
{ | ||
"hostname": "gitlab.smth.com", | ||
"name": "username/project", | ||
"tag": "latest", | ||
}, | ||
), | ||
( | ||
"gitlab.smth.com:443/username/project", | ||
{ | ||
"hostname": "gitlab.smth.com:443", | ||
"name": "username/project", | ||
"tag": "latest", | ||
}, | ||
), | ||
( | ||
"gitlab.smth.com/username/project/image/subimage", | ||
{ | ||
"hostname": "gitlab.smth.com", | ||
"name": "username/project/image/subimage", | ||
"tag": "latest", | ||
}, | ||
), | ||
( | ||
"gitlab.smth.com:443/username/project/image/subimage", | ||
{ | ||
"hostname": "gitlab.smth.com:443", | ||
"name": "username/project/image/subimage", | ||
"tag": "latest", | ||
}, | ||
), | ||
( | ||
"gitlab.smth.com/username/project:1.2.3", | ||
{ | ||
"hostname": "gitlab.smth.com", | ||
"name": "username/project", | ||
"tag": "1.2.3", | ||
}, | ||
), | ||
( | ||
"gitlab.smth.com:443/username/project:1.2.3", | ||
{ | ||
"hostname": "gitlab.smth.com:443", | ||
"name": "username/project", | ||
"tag": "1.2.3", | ||
}, | ||
), | ||
( | ||
"gitlab.smth.com/username/project/image/subimage:1.2.3", | ||
{ | ||
"hostname": "gitlab.smth.com", | ||
"name": "username/project/image/subimage", | ||
"tag": "1.2.3", | ||
}, | ||
), | ||
( | ||
"gitlab.smth.com:443/username/project/image/subimage:1.2.3", | ||
{ | ||
"hostname": "gitlab.smth.com:443", | ||
"name": "username/project/image/subimage", | ||
"tag": "1.2.3", | ||
}, | ||
), | ||
( | ||
"gitlab.smth.com/username/project@sha256:324fet13t4", | ||
{ | ||
"hostname": "gitlab.smth.com", | ||
"name": "username/project", | ||
"tag": "sha256:324fet13t4", | ||
}, | ||
), | ||
( | ||
"gitlab.smth.com:443/username/project@sha256:324fet13t4", | ||
{ | ||
"hostname": "gitlab.smth.com:443", | ||
"name": "username/project", | ||
"tag": "sha256:324fet13t4", | ||
}, | ||
), | ||
( | ||
"gitlab.smth.com/username/project/image/subimage@sha256:324fet13t4", | ||
{ | ||
"hostname": "gitlab.smth.com", | ||
"name": "username/project/image/subimage", | ||
"tag": "sha256:324fet13t4", | ||
}, | ||
), | ||
( | ||
"gitlab.smth.com:443/username/project/image/subimage@sha256:324fet13t4", | ||
{ | ||
"hostname": "gitlab.smth.com:443", | ||
"name": "username/project/image/subimage", | ||
"tag": "sha256:324fet13t4", | ||
}, | ||
), | ||
( | ||
"us.gcr.io/image/subimage@sha256:324fet13t4", | ||
{ | ||
"hostname": "us.gcr.io", | ||
"name": "image/subimage", | ||
"tag": "sha256:324fet13t4", | ||
}, | ||
), | ||
( | ||
"us.gcr.io/proj/image", | ||
{"hostname": "us.gcr.io", "name": "proj/image", "tag": "latest"}, | ||
), | ||
( | ||
"us.gcr.io/proj/image/subimage", | ||
{"hostname": "us.gcr.io", "name": "proj/image/subimage", "tag": "latest"}, | ||
), | ||
], | ||
) | ||
def test_public_image_name_parsing(name: str, expected: dict[str, str]) -> None: | ||
assert asdict(Image.from_path(name)) == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"image,exists_expected", | ||
[ | ||
("nginx:1.19.3", True), | ||
("nginx", True), | ||
("renku/singleuser:cb70d7e", True), | ||
("renku/singleuser", True), | ||
("madeuprepo/madeupproject:tag", False), | ||
("olevski90/oci-image:0.0.1", True), | ||
("ghcr.io/linuxserver/nginx:latest", True), | ||
], | ||
) | ||
@pytest.mark.asyncio | ||
@pytest.mark.integration | ||
async def test_public_image_check(image: str, exists_expected: bool) -> None: | ||
parsed_image = Image.from_path(image) | ||
exists_observed = await parsed_image.repo_api().image_exists(parsed_image) | ||
assert exists_expected == exists_observed | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"image,expected_path", | ||
[ | ||
("jupyter/minimal-notebook", PurePosixPath("/home/jovyan")), | ||
("nginx", None), | ||
("madeuprepo/madeupproject:tag", None), | ||
], | ||
) | ||
@pytest.mark.asyncio | ||
@pytest.mark.integration | ||
async def test_image_workdir_check(image: str, expected_path: PurePosixPath | None) -> None: | ||
parsed_image = Image.from_path(image) | ||
workdir = await parsed_image.repo_api().image_workdir(parsed_image) | ||
if expected_path is None: | ||
assert workdir is None, f"The image workdir should be None but instead it is {workdir}" | ||
else: | ||
assert workdir == expected_path |