-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: clean image transfer and add tests
Signed-off-by: ThibaultFy <[email protected]>
- Loading branch information
1 parent
d52438e
commit 2eef17a
Showing
11 changed files
with
472 additions
and
59 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,4 @@ mypy==1.4.1 | |
djangorestframework-stubs==1.8.0 | ||
django-stubs==1.14.0 | ||
celery-types==0.14.0 | ||
docker==6.1.3 |
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
from image_transfer.decoder import BlobNotFound | ||
from image_transfer.decoder import ManifestNotFound | ||
# The image transfer module is a copy of docker charon -> https://github.com/gabrieldemarmiesse/docker-charon | ||
# Some unused features have been remove and can be found in the original repository. | ||
|
||
from image_transfer.decoder import push_payload | ||
from image_transfer.encoder import make_payload | ||
|
||
__all__ = (BlobNotFound, ManifestNotFound, push_payload, make_payload) | ||
__all__ = (push_payload, make_payload) |
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
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
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
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,12 @@ | ||
class ManifestNotFoundError(Exception): | ||
"""The given docker image is not present in the | ||
registry. while it was specified in | ||
`docker_images_already_transferred`.""" | ||
|
||
pass | ||
|
||
|
||
class ManifestContentError(Exception): | ||
"""The Manifest content must be str, bytes or bytearray.""" | ||
|
||
pass |
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,3 @@ | ||
FROM ubuntu:mantic-20230926 | ||
|
||
RUN echo "hello-world" > /hello-world.txt |
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,54 @@ | ||
from pathlib import Path | ||
|
||
import docker | ||
import pytest | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def ubuntu_base_image(): | ||
return "ubuntu:mantic-20230926" | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def tag_ubuntu_custom_image(): | ||
return "ubuntu:augmented" | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def base_registry_local_port(): | ||
return 5555 | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def docker_client(): | ||
return docker.from_env() | ||
|
||
|
||
def transfer_to_base_registry(image_name, docker_client, base_registry_local_port): | ||
# we transfer the image to the local registry | ||
image = docker_client.images.pull(image_name) | ||
new_name = f"localhost:{base_registry_local_port}/{image_name}" | ||
image.tag(new_name) | ||
docker_client.images.push(new_name) | ||
|
||
|
||
@pytest.fixture(scope="session", autouse=True) | ||
def initialize_local_registry(docker_client, ubuntu_base_image, tag_ubuntu_custom_image, base_registry_local_port): | ||
# we create a local registry and add a docker image to it | ||
base_registry = docker_client.containers.run( | ||
"registry:2", | ||
detach=True, | ||
ports={"5000/tcp": base_registry_local_port}, | ||
name="image-transfer-test-registry", | ||
) | ||
transfer_to_base_registry(ubuntu_base_image, docker_client, base_registry_local_port) | ||
# transfer_to_base_registry("busybox:1.36.1", docker_client, base_registry_local_port) | ||
|
||
image, _ = docker_client.images.build( | ||
path=str(Path(__file__).parent), | ||
tag=f"localhost:{base_registry_local_port}/{tag_ubuntu_custom_image}", | ||
) | ||
docker_client.images.push(image.tags[0]) | ||
|
||
yield | ||
base_registry.remove(force=True, v=True) |
Oops, something went wrong.