Skip to content

Commit

Permalink
[draft/wip] image pull
Browse files Browse the repository at this point in the history
  • Loading branch information
git-hyagi committed Mar 22, 2024
1 parent 772f07c commit b436e2e
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 4 deletions.
3 changes: 3 additions & 0 deletions pulp_container/app/__init__.py
Original file line number Diff line number Diff line change
@@ -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."""
Expand Down
2 changes: 1 addition & 1 deletion pulp_container/app/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
]
Expand Down
5 changes: 5 additions & 0 deletions pulp_container/app/redirects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down Expand Up @@ -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:
Expand Down
14 changes: 13 additions & 1 deletion pulp_container/app/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
20 changes: 20 additions & 0 deletions pulp_container/app/registry_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -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)

Expand Down
1 change: 0 additions & 1 deletion pulp_container/app/tasks/sync_stages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pulp_container/app/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b436e2e

Please sign in to comment.