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 24, 2024
1 parent d8fcca3 commit a9ce379
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@

from django.core.exceptions import ObjectDoesNotExist
from django.core.management import BaseCommand
from django.core.files.storage import default_storage as storage

from pulp_container.app.models import Manifest

from pulp_container.constants import MEDIA_TYPE
from pulp_container.constants import ARTIFACTLESS_BLOB_SIZE, MEDIA_TYPE


class Command(BaseCommand):
Expand Down Expand Up @@ -41,11 +42,30 @@ def handle(self, *args, **options):
media_type__in=[MEDIA_TYPE.MANIFEST_LIST, MEDIA_TYPE.INDEX_OCI], annotations={}
)
manifests_updated_count += self.update_manifests(manifest_lists)
manifests_updated_count += self.update_config_blobs()

self.stdout.write(
self.style.SUCCESS("Successfully updated %d manifests." % manifests_updated_count)
)

# TODO: check if it worth finding a better way to do it because here we are iterating over
# all of the available manifests again (we are also iterating over a list of manifests in
# the update_manifests method)
def update_config_blobs(self):
manifests_updated_count = 0
manifests = Manifest.objects.all()
for manifest in manifests.iterator():
artifact = manifest.config_blob._artifacts.get().file
blob_size = artifact.size
if blob_size < ARTIFACTLESS_BLOB_SIZE:
with storage.open(artifact.name) as artifact_file:
raw_data = artifact_file.read()
blob = manifest.config_blob
blob.data = raw_data
blob.save()
manifests_updated_count += 1
return manifests_updated_count

def update_manifests(self, manifests_qs):
manifests_updated_count = 0
manifests_to_update = []
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.10 on 2024-04-16 12:41
# Generated by Django 4.2.10 on 2024-04-24 15:52

from django.db import migrations, models

Expand Down
2 changes: 1 addition & 1 deletion pulp_container/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +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 {}
except KeyError:
except json.decoder.JSONDecodeError:
# if not, we'll retrieve the config from file
config_artifact = self.config_blob._artifacts.get()

Expand Down

0 comments on commit a9ce379

Please sign in to comment.