Fix add tag operation in UI on manifests without legacy images
This commit is contained in:
parent
a6ffad9759
commit
1e4e424d64
4 changed files with 43 additions and 14 deletions
|
@ -160,15 +160,30 @@ class RepositoryTag(RepositoryParamResource):
|
|||
else:
|
||||
raise InvalidRequest('Could not update tag expiration; Tag has probably changed')
|
||||
|
||||
if 'image' in request.get_json():
|
||||
if 'image' in request.get_json() or 'manifest_digest' in request.get_json():
|
||||
existing_tag = registry_model.get_repo_tag(repo_ref, tag, include_legacy_image=True)
|
||||
|
||||
image_id = request.get_json()['image']
|
||||
image = registry_model.get_legacy_image(repo_ref, image_id)
|
||||
if image is None:
|
||||
manifest_or_image = None
|
||||
image_id = None
|
||||
manifest_digest = None
|
||||
|
||||
if 'image' in request.get_json():
|
||||
image_id = request.get_json()['image']
|
||||
manifest_or_image = registry_model.get_legacy_image(repo_ref, image_id)
|
||||
else:
|
||||
manifest_digest = request.get_json()['manifest_digest']
|
||||
manifest_or_image = registry_model.lookup_manifest_by_digest(repo_ref, manifest_digest)
|
||||
|
||||
if manifest_or_image is None:
|
||||
raise NotFound()
|
||||
|
||||
if not registry_model.retarget_tag(repo_ref, tag, image, storage):
|
||||
# TODO(jschorr): Remove this check once fully on V22
|
||||
existing_manifest_digest = None
|
||||
if existing_tag:
|
||||
existing_manifest = registry_model.get_manifest_for_tag(existing_tag)
|
||||
existing_manifest_digest = existing_manifest.digest if existing_manifest else None
|
||||
|
||||
if not registry_model.retarget_tag(repo_ref, tag, manifest_or_image, storage):
|
||||
raise InvalidRequest('Could not move tag')
|
||||
|
||||
username = get_authenticated_user().username
|
||||
|
@ -179,7 +194,11 @@ class RepositoryTag(RepositoryParamResource):
|
|||
'tag': tag,
|
||||
'namespace': namespace,
|
||||
'image': image_id,
|
||||
'original_image': existing_tag.legacy_image.docker_image_id if existing_tag else None,
|
||||
'manifest_digest': manifest_digest,
|
||||
'original_image': (existing_tag.legacy_image.docker_image_id
|
||||
if existing_tag and existing_tag.legacy_image_if_present
|
||||
else None),
|
||||
'original_manifest_digest': existing_manifest_digest,
|
||||
}, repo_name=repository)
|
||||
|
||||
return 'Updated', 201
|
||||
|
|
Reference in a new issue