Fix add tag operation in UI on manifests without legacy images

This commit is contained in:
Joseph Schorr 2018-11-20 14:01:35 +02:00
parent a6ffad9759
commit 1e4e424d64
4 changed files with 43 additions and 14 deletions

View file

@ -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

View file

@ -47,9 +47,9 @@
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true" ng-show="!addingTag">&times;</button>
<h4 class="modal-title">{{ isAnotherImageTag(toTagImage, tagToCreate) ? 'Move' : 'Add' }} Tag to Image {{ toTagImage.substr(0, 12) }}</h4>
<h4 class="modal-title">{{ isAnotherImageTag(toTagImage, tagToCreate) ? 'Move' : 'Add' }} Tag to {{ toTagManifestDigest ? ('Manifest ' + toTagManifestDigest.substr(0, 19)) : ('Image ' + toTagImage.substr(0, 12)) }}</h4>
</div>
<form name="addTagForm" ng-submit="createOrMoveTag(toTagImage, tagToCreate);">
<form name="addTagForm" ng-submit="createOrMoveTag(toTagImage, tagToCreate, toTagManifestDigest);">
<div class="modal-body">
<div class="cor-loader" ng-show="addingTag"></div>
<div ng-show="!addingTag">

View file

@ -92,6 +92,10 @@ angular.module('quay').directive('repoPanelTags', function () {
var imageIndexMap = {};
for (var i = 0; i < ordered.length; ++i) {
var tagInfo = ordered[i];
if (!tagInfo.image_id) {
continue;
}
if (!imageMap[tagInfo.image_id]) {
imageMap[tagInfo.image_id] = [];
imageIDs.push(tagInfo.image_id)
@ -360,7 +364,7 @@ angular.module('quay').directive('repoPanelTags', function () {
};
$scope.askAddTag = function(tag) {
$scope.tagActionHandler.askAddTag(tag.image_id);
$scope.tagActionHandler.askAddTag(tag.image_id, tag.manifest_digest);
};
$scope.showLabelEditor = function(tag) {

View file

@ -84,7 +84,7 @@ angular.module('quay').directive('tagOperationsDialog', function () {
return found.image_id == image;
};
$scope.createOrMoveTag = function(image, tag) {
$scope.createOrMoveTag = function(image, tag, opt_manifest_digest) {
if (!$scope.repository.can_write) { return; }
if ($scope.alertOnTagOpsDisabled()) {
return;
@ -97,9 +97,14 @@ angular.module('quay').directive('tagOperationsDialog', function () {
'tag': tag
};
var data = {
'image': image
};
var data = {};
if (image) {
data['image'] = image;
}
if (opt_manifest_digest) {
data['manifest_digest'] = opt_manifest_digest;
}
var errorHandler = ApiService.errorDisplay('Cannot create or move tag', function(resp) {
$element.find('#createOrMoveTagModal').modal('hide');
@ -330,13 +335,14 @@ angular.module('quay').directive('tagOperationsDialog', function () {
};
},
'askAddTag': function(image) {
'askAddTag': function(image, opt_manifest_digest) {
if ($scope.alertOnTagOpsDisabled()) {
return;
}
$scope.tagToCreate = '';
$scope.toTagImage = image;
$scope.toTagManifestDigest = opt_manifest_digest;
$scope.addingTag = false;
$scope.addTagForm.$setPristine();
$element.find('#createOrMoveTagModal').modal('show');