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 3, 2024
1 parent 63a36bc commit 6e1b382
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 33 deletions.
21 changes: 5 additions & 16 deletions pulp_container/app/migrations/0039_artifactless_config_blob.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.10 on 2024-04-03 10:54
# Generated by Django 4.2.10 on 2024-04-03 15:51

from django.db import migrations, models
import django.db.models.deletion
Expand All @@ -11,27 +11,16 @@ 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=[
('content_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='core.content')),
('data', models.TextField()),
('architecture', models.TextField()),
('os', models.TextField()),
('rootfs', models.JSONField(default=dict)),
('digest', models.TextField(db_index=True)),
('created', models.DateTimeField()),
('author', models.TextField(blank=True, default='')),
('os_version', models.TextField(blank=True, default='')),
('os_features', models.TextField(blank=True, default='')),
('variant', models.TextField(blank=True, default='')),
('config', models.JSONField(default=dict)),
('history', models.JSONField(default=dict)),
('os', models.TextField()),
('architecture', models.TextField()),
('digest', models.TextField(db_index=True)),
],
options={
'default_related_name': '%(app_label)s_%(model_name)s',
Expand All @@ -52,6 +41,6 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='manifest',
name='config',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='config_blob', to='container.configblob'),
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='config', to='container.configblob'),
),
]
18 changes: 5 additions & 13 deletions pulp_container/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,11 @@ class ConfigBlob(Content):
TYPE = "config-blob"

data = models.TextField()
architecture = models.TextField()
os = models.TextField()
rootfs = models.JSONField(default=dict)
digest = models.TextField(db_index=True)

created = models.DateTimeField()
author = models.TextField(default="", blank=True)
os_version = models.TextField(default="", blank=True)
os_features = models.TextField(default="", blank=True)
variant = models.TextField(default="", blank=True)

config = models.JSONField(default=dict)
history = models.JSONField(default=dict)
os = models.TextField()
architecture = models.TextField()
digest = models.TextField(db_index=True)

class Meta:
default_related_name = "%(app_label)s_%(model_name)s"
Expand Down Expand Up @@ -149,10 +141,10 @@ class Manifest(Content):

blobs = models.ManyToManyField(Blob, through="BlobManifest")
config_blob = models.ForeignKey(
Blob, related_name="config", null=True, on_delete=models.CASCADE
Blob, related_name="config_blob", null=True, on_delete=models.CASCADE
)
config = models.ForeignKey(
ConfigBlob, related_name="config_blob", null=True, on_delete=models.CASCADE
ConfigBlob, related_name="config", null=True, on_delete=models.CASCADE
)

# Order matters for through fields, (source, target)
Expand Down
38 changes: 34 additions & 4 deletions pulp_container/app/registry.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import json
import time
import logging
import os

Expand Down Expand Up @@ -293,7 +292,6 @@ async def get_by_digest(self, request):
# "/pulp/container/{path:.+}/{content:(blobs|manifests)}/sha256:{digest:.+}"
content_type = request.match_info["content"]
if content_type == "manifests":
time.sleep(10)
raw_manifest, digest, media_type = await pull_downloader.download_manifest()
headers = {
"Content-Type": media_type,
Expand Down Expand Up @@ -431,12 +429,11 @@ async def run_pipeline(self, saved_artifact):
"tag_name": self.identifier,
},
)
time.sleep(5)

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 ConfigBlob.objects.aget(digest=config_digest)
config_blob = await self.save_config_blob(config_digest)
await sync_to_async(self.repository.pending_config_blobs.add)(config_blob)
else:
config_blob = None
Expand Down Expand Up @@ -505,3 +502,36 @@ async def save_blob(self, digest, manifest):
await ra.asave()

return blob

async def save_config_blob(self, 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()

with open(response.path, "r") as content_file:
raw_data = content_file.read()
content_data = json.loads(raw_data)
config_blob = ConfigBlob(
data=raw_data,
digest=config_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)()
return config_blob

0 comments on commit 6e1b382

Please sign in to comment.