From d8fcca3cf37f6b9a9d8ed3cf79f5fffa7743b62d Mon Sep 17 00:00:00 2001 From: git-hyagi <45576767+git-hyagi@users.noreply.github.com> Date: Wed, 24 Apr 2024 12:50:30 -0300 Subject: [PATCH] draft/wip --- pulp_container/app/models.py | 3 +-- pulp_container/app/registry_api.py | 19 +++---------------- pulp_container/constants.py | 5 +++-- 3 files changed, 7 insertions(+), 20 deletions(-) diff --git a/pulp_container/app/models.py b/pulp_container/app/models.py index 5a13471ac..46b8baa01 100644 --- a/pulp_container/app/models.py +++ b/pulp_container/app/models.py @@ -145,8 +145,7 @@ def init_labels(self): config = json.loads(self.config_blob.config_blob.instance.data)["config"] if "Labels" in config.keys(): self.labels = config["Labels"] or {} - # TODO: DO NOT USE BARE 'EXCEPT' - except: + except KeyError: # if not, we'll retrieve the config from file config_artifact = self.config_blob._artifacts.get() diff --git a/pulp_container/app/registry_api.py b/pulp_container/app/registry_api.py index 085ab297a..1086966a6 100644 --- a/pulp_container/app/registry_api.py +++ b/pulp_container/app/registry_api.py @@ -82,7 +82,7 @@ validate_manifest, ) from pulp_container.constants import ( - CONFIG_BLOB_SIZE, + ARTIFACTLESS_BLOB_SIZE, EMPTY_BLOB, MEDIA_TYPE, SIGNATURE_API_EXTENSION_VERSION, @@ -792,7 +792,7 @@ def create_blob(self, artifact, digest): blob.touch() blob_size = artifact.file.size - if blob_size > CONFIG_BLOB_SIZE: + if blob_size > ARTIFACTLESS_BLOB_SIZE: self._create_blob_content_artifact(artifact, blob, digest) else: with storage.open(artifact.file.name) as artifact_file: @@ -804,7 +804,7 @@ def create_blob(self, artifact, digest): def _create_blob_content_artifact(self, artifact, blob, digest): """ - Blobs with size > CONFIG_BLOB_SIZE will be considered layer blobs and + Blobs with size > ARTIFACTLESS_BLOB_SIZE are often layer blobs and will be stored as artifacts. """ try: @@ -1004,19 +1004,6 @@ def handle_safe_method(self, request, path, pk): blob = repository.pending_blobs.get(digest=pk) blob.touch() except models.Blob.DoesNotExist: - # try: - # # configblobs do not have a repository_version nor artifact - # blob = models.Blob.objects.get(digest=pk) - # media_type = MEDIA_TYPE.CONFIG_BLOB_OCI - # headers = { - # "Content-Type": media_type, - # "Docker-Content-Digest": pk, - # "Docker-Distribution-API-Version": "registry/2.0", - # } - # #return web.Response(text=blob.data,headers=headers) - # #return UploadResponse(upload=blob, path=path, request=request) - # return Response(data=blob.data) - # except models.Blob.DoesNotExist: raise BlobNotFound(digest=pk) if blob.data: diff --git a/pulp_container/constants.py b/pulp_container/constants.py index cb7a04157..a932f27b6 100644 --- a/pulp_container/constants.py +++ b/pulp_container/constants.py @@ -70,8 +70,9 @@ MEGABYTE = 1_000_000 SIGNATURE_PAYLOAD_MAX_SIZE = 4 * MEGABYTE -# TO-DO: ADD A COMMENT EXPLAINING WHY WE CHOSEN SUCH VALUE -CONFIG_BLOB_SIZE = 2000 +# we defined the following size based on the average container config size of some +# ubi and bootable images +ARTIFACTLESS_BLOB_SIZE = 22000 SIGNATURE_API_EXTENSION_VERSION = 2