From b436e2e8f15c0dc59bad43ede2c81018d463c9fd Mon Sep 17 00:00:00 2001 From: git-hyagi <45576767+git-hyagi@users.noreply.github.com> Date: Wed, 20 Mar 2024 17:09:36 -0300 Subject: [PATCH] [draft/wip] image pull --- pulp_container/app/__init__.py | 3 +++ pulp_container/app/content.py | 2 +- pulp_container/app/redirects.py | 5 +++++ pulp_container/app/registry.py | 14 +++++++++++++- pulp_container/app/registry_api.py | 20 ++++++++++++++++++++ pulp_container/app/tasks/sync_stages.py | 1 - pulp_container/app/viewsets.py | 2 +- 7 files changed, 43 insertions(+), 4 deletions(-) diff --git a/pulp_container/app/__init__.py b/pulp_container/app/__init__.py index 9f5456a75..ca823578e 100644 --- a/pulp_container/app/__init__.py +++ b/pulp_container/app/__init__.py @@ -1,5 +1,8 @@ from pulpcore.plugin import PulpPluginAppConfig +#import debugpy +#debugpy.listen(('0.0.0.0',5678)) +#debugpy.wait_for_client() class PulpContainerPluginAppConfig(PulpPluginAppConfig): """Entry point for the container plugin.""" diff --git a/pulp_container/app/content.py b/pulp_container/app/content.py index fcdc7786f..adf92b486 100644 --- a/pulp_container/app/content.py +++ b/pulp_container/app/content.py @@ -8,7 +8,7 @@ app.add_routes( [ web.get( - r"/pulp/container/{path:.+}/{content:(blobs|manifests)}/sha256:{digest:.+}", + r"/pulp/container/{path:.+}/{content:(blobs|manifests|config-blobs)}/sha256:{digest:.+}", registry.get_by_digest, ) ] diff --git a/pulp_container/app/redirects.py b/pulp_container/app/redirects.py index d88cbe093..9617978ca 100644 --- a/pulp_container/app/redirects.py +++ b/pulp_container/app/redirects.py @@ -7,6 +7,8 @@ from pulp_container.app.utils import get_accepted_media_types from pulp_container.constants import BLOB_CONTENT_TYPE, MEDIA_TYPE +#from pulp_container.app.models import ConfigBlob + class CommonRedirects: """ @@ -102,6 +104,9 @@ def issue_blob_redirect(self, blob): """ Redirect to the passed blob or stream content when an associated artifact is not present. """ + #if type(blob) is ConfigBlob: + # return self.redirect_to_content_app("config-blobs", blob.digest) + try: artifact = blob._artifacts.get() except ObjectDoesNotExist: diff --git a/pulp_container/app/registry.py b/pulp_container/app/registry.py index 007b789a4..e8ec01d14 100644 --- a/pulp_container/app/registry.py +++ b/pulp_container/app/registry.py @@ -23,7 +23,7 @@ from pulpcore.plugin.tasking import dispatch from pulp_container.app.cache import RegistryContentCache -from pulp_container.app.models import ContainerDistribution, Tag, Blob, Manifest, BlobManifest +from pulp_container.app.models import ContainerDistribution, Tag, Blob, Manifest, BlobManifest, ConfigBlob from pulp_container.app.tasks import download_image_data from pulp_container.app.utils import ( calculate_digest, @@ -246,6 +246,9 @@ async def get_by_digest(self, request): """ Return a response to the "GET" action. """ + #import debugpy + #debugpy.listen(('0.0.0.0',5679)) + #debugpy.wait_for_client() path = request.match_info["path"] digest = "sha256:{digest}".format(digest=request.match_info["digest"]) distribution = await sync_to_async(self._match_distribution)(path, add_trailing_slash=False) @@ -301,6 +304,15 @@ async def get_by_digest(self, request): return await self._stream_content_artifact(request, web.StreamResponse(), ca) else: raise RuntimeError("Only blobs or manifests are supported by the parser.") + elif request.match_info["content"] == "config-blobs": + blob = await ConfigBlob.objects.aget(digest=digest) + media_type=MEDIA_TYPE.CONFIG_BLOB ### need to find a better way to identify the media_type + headers = { + "Content-Type": media_type, + "Docker-Content-Digest": digest, + "Docker-Distribution-API-Version": "registry/2.0", + } + return web.Response(text=blob.data,headers=headers) else: raise PathNotResolved(path) else: diff --git a/pulp_container/app/registry_api.py b/pulp_container/app/registry_api.py index a655a748b..cce789658 100644 --- a/pulp_container/app/registry_api.py +++ b/pulp_container/app/registry_api.py @@ -780,6 +780,10 @@ def create_single_chunk_artifact(self, chunk): artifact.touch() return artifact + ### CHECK IF THIS WILL NEED TO BE MODIFIED + ### CHECK IF THIS WILL NEED TO BE MODIFIED + ### CHECK IF THIS WILL NEED TO BE MODIFIED + ### CHECK IF THIS WILL NEED TO BE MODIFIED def create_blob(self, artifact, digest): with transaction.atomic(): try: @@ -974,6 +978,7 @@ def get(self, request, path, pk): @RegistryApiCache(base_key=lambda req, cac: find_base_path_cached(req, cac)) def handle_safe_method(self, request, path, pk): + """Handles safe requests for Blobs.""" distribution, repository, repository_version = self.get_drv_pull(path) redirects = self.redirects_class(distribution, path, request) @@ -983,12 +988,27 @@ def handle_safe_method(self, request, path, pk): except models.Blob.DoesNotExist: if pk == EMPTY_BLOB: return redirects.redirect_to_content_app("blobs", pk) + try: + blob = models.ConfigBlob.objects.get(digest=pk) + return redirects.redirect_to_content_app("config-blobs",pk) + except: + pass repository = repository.cast() try: blob = repository.pending_blobs.get(digest=pk) blob.touch() except models.Blob.DoesNotExist: raise BlobNotFound(digest=pk) + #try: + # blob = models.ConfigBlob.objects.get(digest=pk,pk__in=repository_version.content) + #except: + # raise BlobNotFound(digest=pk) + # # pass + +# try: +# config_blob = models.ConfigBlob.get(digest=pk,pk__in=repository_version.content) +# except: +# pass return redirects.issue_blob_redirect(blob) diff --git a/pulp_container/app/tasks/sync_stages.py b/pulp_container/app/tasks/sync_stages.py index e2833c557..30c661716 100644 --- a/pulp_container/app/tasks/sync_stages.py +++ b/pulp_container/app/tasks/sync_stages.py @@ -570,7 +570,6 @@ def create_blob(self, blob_data, deferred_download=True): remote=self.remote, deferred_download=deferred_download and self.deferred_download, ) - blob_dc = DeclarativeContent(content=blob, d_artifacts=[da]) return blob_dc diff --git a/pulp_container/app/viewsets.py b/pulp_container/app/viewsets.py index 7696b809d..03b2f38f6 100644 --- a/pulp_container/app/viewsets.py +++ b/pulp_container/app/viewsets.py @@ -335,7 +335,7 @@ class ConfigBlobViewSet(ContainerContentQuerySetMixin, ReadOnlyContentViewSet): ViewSet for ConfigBlobs. """ - endpoint_name = "config-blob" + endpoint_name = "config-blobs" queryset = models.ConfigBlob.objects.all() serializer_class = serializers.ConfigBlobSerializer filterset_class = ConfigBlobFilter