Skip to content

Commit

Permalink
draft/wip
Browse files Browse the repository at this point in the history
  • Loading branch information
git-hyagi committed Apr 2, 2024
1 parent 43a92a7 commit f92df55
Show file tree
Hide file tree
Showing 15 changed files with 76 additions and 208 deletions.
6 changes: 0 additions & 6 deletions pulp_container/app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
from pulpcore.plugin import PulpPluginAppConfig

#import debugpy
#try:
# debugpy.listen(('0.0.0.0',5678))
# debugpy.wait_for_client()
#except:
# pass

class PulpContainerPluginAppConfig(PulpPluginAppConfig):
"""Entry point for the container plugin."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from django.core.paginator import Paginator
from django.db import IntegrityError, transaction

from pulp_container.app.models import Manifest,ConfigBlob
from pulp_container.app.models import Manifest, ConfigBlob

from pulp_container.constants import MEDIA_TYPE

Expand Down Expand Up @@ -77,19 +77,19 @@ def update_manifests(self, manifests_qs):

return manifests_updated_count

def update_config_blob(self,manifest):
def update_config_blob(self, manifest):
raw_manifest = manifest.config_blob._artifacts.get().file.read().decode("utf-8")
config_blob = json.loads(raw_manifest)
digest = manifest.config_blob.digest
with transaction.atomic():
try:
blob = ConfigBlob(
data = raw_manifest,
digest = digest,
data=raw_manifest,
digest=digest,
architecture=config_blob.get("architecture"),
os=config_blob.get("os"),
created=config_blob.get("created"),
author=config_blob .get("author", ""),
author=config_blob.get("author", ""),
os_version=config_blob.get("os_version", ""),
os_features=config_blob.get("os_features", ""),
variant=config_blob.get("variant", ""),
Expand All @@ -100,4 +100,4 @@ def update_config_blob(self,manifest):
blob.save()
except IntegrityError:
blob = ConfigBlob.objects.get(digest=digest)
blob.touch()
blob.touch()
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.10 on 2024-04-01 18:15
# Generated by Django 4.2.10 on 2024-04-02 12:32

from django.db import migrations, models
import django.db.models.deletion
Expand All @@ -11,6 +11,11 @@ class Migration(migrations.Migration):
]

operations = [
migrations.AlterField(
model_name='manifest',
name='config_blob',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='config', to='container.blob'),
),
migrations.CreateModel(
name='ConfigBlob',
fields=[
Expand All @@ -34,11 +39,6 @@ class Migration(migrations.Migration):
},
bases=('core.content',),
),
migrations.AlterField(
model_name='manifest',
name='config_blob',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='config', to='container.blob'),
),
migrations.AddField(
model_name='containerpushrepository',
name='pending_config_blobs',
Expand All @@ -54,15 +54,4 @@ class Migration(migrations.Migration):
name='config',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='config_blob', to='container.configblob'),
),
migrations.CreateModel(
name='ConfigBlobManifest',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('manifest', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='config_blob_manifests', to='container.manifest')),
('manifest_blob', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='manifest_blobs', to='container.configblob')),
],
options={
'unique_together': {('manifest', 'manifest_blob')},
},
),
]
4 changes: 3 additions & 1 deletion pulp_container/app/modelresource.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ def set_up_queryset(self):
"""
:return: ConfigBlobs specific to a specified repo-version.
"""
return ConfigBlob.objects.filter(pk__in=self.repo_version.content).order_by("content_ptr_id")
return ConfigBlob.objects.filter(pk__in=self.repo_version.content).order_by(
"content_ptr_id"
)

class Meta:
model = ConfigBlob
Expand Down
21 changes: 0 additions & 21 deletions pulp_container/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class ConfigBlob(Content):
config (models.ForeignKey):
rootfs (models.ForeignKey):
history (models.ForeignKey):
"""

PROTECTED_FROM_RECLAIM = False
Expand Down Expand Up @@ -184,10 +183,6 @@ def init_annotations(self, manifest_data=None):

def init_labels(self):
if self.config and "Labels" in self.config.config.keys():
#if isinstance(self.config_blob.config["Labels"],str):
# self.labels = json.loads(self.config_blob.config)["Labels"]
#else:
# self.labels = self.config_blob.config["Labels"] or {}
self.labels = self.config.config["Labels"] or {}
else:
self.labels = {}
Expand Down Expand Up @@ -252,22 +247,6 @@ class Meta:
unique_together = ("manifest", "manifest_blob")


class ConfigBlobManifest(models.Model):
"""
Many-to-many relationship between ConfigBlobs and Manifests.
"""

manifest = models.ForeignKey(
Manifest, related_name="config_blob_manifests", on_delete=models.CASCADE
)
manifest_blob = models.ForeignKey(
ConfigBlob, related_name="manifest_blobs", on_delete=models.CASCADE
)

class Meta:
unique_together = ("manifest", "manifest_blob")


class ManifestListManifest(models.Model):
"""
The manifest referenced by a manifest list.
Expand Down
80 changes: 14 additions & 66 deletions pulp_container/app/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@
from pulpcore.plugin.tasking import dispatch

from pulp_container.app.cache import RegistryContentCache
from pulp_container.app.models import ContainerDistribution, Tag, Blob, Manifest, BlobManifest, ConfigBlob
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 @@ -259,8 +266,6 @@ async def get_by_digest(self, request):

repository = await repository_version.repository.acast()
pending_blobs = repository.pending_blobs.values_list("pk")
#pending_config_blobs = repository.pending_config_blobs.values_list("pk")
#pending_blobs.union(pending_config_blobs)
pending_manifests = repository.pending_manifests.values_list("pk")
pending_content = pending_blobs.union(pending_manifests)
content = repository_version.content | Content.objects.filter(pk__in=pending_content)
Expand Down Expand Up @@ -304,25 +309,11 @@ async def get_by_digest(self, request):
ca = await blob.contentartifact_set.afirst()
return await self._stream_content_artifact(request, web.StreamResponse(), ca)
elif content_type == "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)
return await self._config_blob_response(digest)
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)
return await self._config_blob_response(digest)
else:
raise PathNotResolved(path)
else:
Expand All @@ -332,15 +323,15 @@ async def get_by_digest(self, request):
else:
return await self._stream_content_artifact(request, web.StreamResponse(), ca)

async def _config_blob_response(self,digest):
async def _config_blob_response(self, digest):
blob = await ConfigBlob.objects.aget(digest=digest)
media_type=MEDIA_TYPE.CONFIG_BLOB ### need to find a better way to identify the media_type
media_type = MEDIA_TYPE.CONFIG_BLOB_OCI
headers = {
"Content-Type": media_type,
"Docker-Content-Digest": digest,
"Docker-Distribution-API-Version": "registry/2.0",
}
return web.Response(text=blob.data,headers=headers)
return web.Response(text=blob.data, headers=headers)

@staticmethod
async def _empty_blob():
Expand Down Expand Up @@ -445,7 +436,7 @@ async def run_pipeline(self, saved_artifact):
async def init_pending_content(self, digest, manifest_data, media_type, artifact):
if config := manifest_data.get("config", None):
config_digest = config["digest"]
config_blob = await self.save_config_blob(config_digest)
config_blob = await ConfigBlob.objects.aget(digest=config_digest)
await sync_to_async(self.repository.pending_config_blobs.add)(config_blob)
else:
config_blob = None
Expand Down Expand Up @@ -514,46 +505,3 @@ async def save_blob(self, digest, manifest):
await ra.asave()

return blob

async def save_config_blob(self, config_digest):
return await ConfigBlob.objects.aget(digest=config_digest)

# blob_relative_url = "/v2/{name}/blobs/{digest}".format(
# name=self.remote.namespaced_upstream_name, digest=config_digest
# )
# blob_url = urljoin(self.remote.url, blob_relative_url)
# downloader = self.remote.get_downloader(url=blob_url)
# response = await downloader.run()
#
# response.artifact_attributes["file"] = response.path
# #saved_artifact = await save_artifact(response.artifact_attributes)
#
# config_blob = ConfigBlob(
# data = raw_data.decode("utf-8"),
# digest = digest,
# architecture=content_data.get("architecture"),
# os=content_data.get("os"),
# created=content_data.get("created"),
# author=content_data.get("author", ""),
# os_version=content_data.get("os_version", ""),
# os_features=content_data.get("os_features", ""),
# variant=content_data.get("variant", ""),
# rootfs=content_data.get("rootfs", {}),
# config=content_data.get("config", {}),
# history=content_data.get("history", {}),
# )
# try:
# await config_blob.asave()
# except IntegrityError:
# config_blob = await ConfigBlob.objects.aget(digest=config_digest)
# await sync_to_async(config_blob.touch)()
#
# #content_artifact = ContentArtifact(
# # content=config_blob,
# # artifact=saved_artifact,
# # relative_path=config_digest,
# #)
# #with suppress(IntegrityError):
# # await content_artifact.asave()
#
# return config_blob
Loading

0 comments on commit f92df55

Please sign in to comment.