Handle the cases where an existing tag manifest or manifest has already been created
This commit is contained in:
parent
f297249100
commit
581ec47798
1 changed files with 20 additions and 3 deletions
|
@ -612,7 +612,13 @@ def get_possibly_expired_tag(namespace, repo_name, tag_name):
|
||||||
|
|
||||||
def associate_generated_tag_manifest(namespace, repo_name, tag_name, manifest, storage_id_map):
|
def associate_generated_tag_manifest(namespace, repo_name, tag_name, manifest, storage_id_map):
|
||||||
tag = get_active_tag(namespace, repo_name, tag_name)
|
tag = get_active_tag(namespace, repo_name, tag_name)
|
||||||
return _create_manifest(tag, manifest, storage_id_map)
|
try:
|
||||||
|
manifest = TagManifest.get(digest=manifest.digest)
|
||||||
|
manifest.tag = tag
|
||||||
|
manifest.save()
|
||||||
|
return manifest, False
|
||||||
|
except TagManifest.DoesNotExist:
|
||||||
|
return _create_manifest(tag, manifest, storage_id_map), True
|
||||||
|
|
||||||
|
|
||||||
def _create_manifest(tag, manifest, storage_id_map):
|
def _create_manifest(tag, manifest, storage_id_map):
|
||||||
|
@ -639,9 +645,20 @@ def _create_manifest(tag, manifest, storage_id_map):
|
||||||
def populate_manifest(repository, manifest, legacy_image, storage_ids):
|
def populate_manifest(repository, manifest, legacy_image, storage_ids):
|
||||||
""" Populates the rows for the manifest, including its blobs and legacy image. """
|
""" Populates the rows for the manifest, including its blobs and legacy image. """
|
||||||
media_type = Manifest.media_type.get_id(manifest.media_type)
|
media_type = Manifest.media_type.get_id(manifest.media_type)
|
||||||
|
|
||||||
|
# Check for an existing manifest. If present, return it.
|
||||||
|
try:
|
||||||
|
return Manifest.get(repository=repository, digest=manifest.digest)
|
||||||
|
except Manifest.DoesNotExist:
|
||||||
|
pass
|
||||||
|
|
||||||
with db_transaction():
|
with db_transaction():
|
||||||
manifest_row = Manifest.create(digest=manifest.digest, repository=repository,
|
try:
|
||||||
manifest_bytes=manifest.bytes, media_type=media_type)
|
manifest_row = Manifest.create(digest=manifest.digest, repository=repository,
|
||||||
|
manifest_bytes=manifest.bytes, media_type=media_type)
|
||||||
|
except IntegrityError:
|
||||||
|
return Manifest.get(repository=repository, digest=manifest.digest)
|
||||||
|
|
||||||
ManifestLegacyImage.create(manifest=manifest_row, repository=repository, image=legacy_image)
|
ManifestLegacyImage.create(manifest=manifest_row, repository=repository, image=legacy_image)
|
||||||
|
|
||||||
blobs_to_insert = [dict(manifest=manifest_row, repository=repository,
|
blobs_to_insert = [dict(manifest=manifest_row, repository=repository,
|
||||||
|
|
Reference in a new issue