From 0c563fb3fb63acfbfec18a71d4d728941cf68cb1 Mon Sep 17 00:00:00 2001 From: Eugene Kazakov Date: Mon, 1 May 2017 00:42:03 +0700 Subject: [PATCH] Delete tags with API v2 --- app/image/image-controller.js | 9 ++----- app/services/registry-services.js | 17 +++++++----- app/tag/delete-tags-controller.js | 43 ++++++++++--------------------- app/tag/tag-controller.js | 21 ++++++++++----- app/tag/tag-detail.html | 14 +++------- app/tag/tag-list-directive.html | 19 +++++++++----- develop/docker-compose.yml | 9 +++++-- start-apache.sh | 2 -- 8 files changed, 64 insertions(+), 70 deletions(-) diff --git a/app/image/image-controller.js b/app/image/image-controller.js index 65da230..c94a7e5 100644 --- a/app/image/image-controller.js +++ b/app/image/image-controller.js @@ -14,8 +14,7 @@ angular.module('image-controller', ['registry-services', 'app-mode-services']) $scope.appMode = AppMode.query(); $scope.totalImageSize = 0; - $scope.imageDetails = Manifest.query({repoUser: $scope.repositoryUser, repoName: $scope.repositoryName, tagName: $scope.tagName}); - + $scope.imageDetails = Manifest.query({repository: $scope.repository, tagName: $scope.tagName}); @@ -30,11 +29,7 @@ angular.module('image-controller', ['registry-services', 'app-mode-services']) $scope.totalImageSize = 0; var size; angular.forEach($scope.imageDetails.fsLayers, function (id, key) { - - Blob.query({repoUser: $scope.repositoryUser, repoName: $scope.repositoryName, digest: id.blobSum}).$promise.then( function(data, headers){ - size = data; - console.log(data) - console.log(size) + Blob.query({repository: $scope.repository, digest: id.blobSum}).$promise.then(function(data){ if(!isNaN(data.contentLength-0)){ $scope.totalImageSize += data.contentLength; } diff --git a/app/services/registry-services.js b/app/services/registry-services.js index ed4f843..6d2ec28 100644 --- a/app/services/registry-services.js +++ b/app/services/registry-services.js @@ -121,10 +121,6 @@ angular.module('registry-services', ['ngResource']) return res; }, }, - 'delete': { - url: '/v1/repositories/:repoUser/:repoName/tags/:tagName', - method: 'DELETE', - }, 'exists': { url: '/v1/repositories/:repoUser/:repoName/tags/:tagName', method: 'GET', @@ -143,7 +139,7 @@ angular.module('registry-services', ['ngResource']) }]) .factory('Manifest', ['$resource', function($resource){ - return $resource('/v2/:repoUser/:repoName/manifests/:tagName', {}, { + return $resource('/v2/:repository/manifests/:tagName', {}, { // Response example: // { // "schemaVersion": 1, @@ -169,6 +165,9 @@ angular.module('registry-services', ['ngResource']) // } 'query': { method:'GET', + headers: { + accept: 'application/vnd.docker.distribution.manifest.v2+json', + }, isArray: false, transformResponse: function(data, headers){ var res = {}; @@ -207,13 +206,17 @@ angular.module('registry-services', ['ngResource']) res.architecture = resp.architecture; return res; }, - } + }, + 'delete': { + url: '/v2/:repository/manifests/:digest', + method: 'DELETE', + }, }); }]) // This is not totally working right now (problem with big layers) /* .factory('Blob', ['$resource', function($resource){ - return $resource('/v2/:repoUser/:repoName/blobs/:digest', {}, { + return $resource('/v2/:repository/blobs/:digest', {}, { 'query': { method:'HEAD', diff --git a/app/tag/delete-tags-controller.js b/app/tag/delete-tags-controller.js index c3f7c54..6376aa8 100644 --- a/app/tag/delete-tags-controller.js +++ b/app/tag/delete-tags-controller.js @@ -8,46 +8,31 @@ * Controller of the docker-registry-frontend */ angular.module('delete-tags-controller', ['registry-services']) - .controller('DeleteTagsController', ['$scope', '$route', '$modalInstance', '$window', 'Tag', 'items', 'information', - function($scope, $route, $modalInstance, $window, Tag, items, information) + .controller('DeleteTagsController', ['$scope', '$route', '$modalInstance', '$window', 'Manifest', 'items', 'information', + function($scope, $route, $modalInstance, $window, Manifest, items, information) { $scope.items = items; $scope.information = information; // Callback that triggers deletion of tags and reloading of page $scope.ok = function () { - angular.forEach($scope.items, function(value, key) { - var tagStr = value; + angular.forEach($scope.items, function(value) { + var repository = value.split(":")[0]; var tagName = value.split(":")[1]; - var repoUser = value.split("/")[0]; - var repoName = value.split("/")[1].split(":")[0]; - var tag = { - repoUser: repoUser, - repoName: repoName, + Manifest.query({ + repository: repository, tagName: tagName - }; - - if (!Tag.exists(tag)) { - toastr.warning('Tag does no longer exist: ' + tagStr); - return; - } - - Tag.delete(tag, - // success - function(value, responseHeaders) { - toastr.success('Deleted tag: ' + tagStr); - }, - // error - function(httpResponse) { - toastr.error('Failed to delete tag: ' + tagStr + ' Response: ' + httpResponse.statusText); - } - ); + }).$promise.then(function (data) { + Manifest.delete({ + repository: repository, + digest: data.digest + }).$promise.then(function () { + $window.location.href = '/repository/' + repository; + }); + }); }); $modalInstance.close(); - - // Go to the repositories page - $window.location.href = 'repositories'; }; $scope.cancel = function () { diff --git a/app/tag/tag-controller.js b/app/tag/tag-controller.js index 23c89f0..da7ccc6 100644 --- a/app/tag/tag-controller.js +++ b/app/tag/tag-controller.js @@ -63,18 +63,12 @@ angular.module('tag-controller', ['registry-services']) if(!isNaN(idx)){ tmpIdx = parseInt(idx) + idxShift; if ( result[tmpIdx].hasOwnProperty('name') ) { - result[tmpIdx].details = Manifest.query({repoUser: $scope.repositoryUser, repoName: $scope.repositoryName, tagName: result[tmpIdx].name}); + result[tmpIdx].details = Manifest.query({repository: $scope.repository, tagName: result[tmpIdx].name}); } } } }); - - - // Copy collection for rendering in a smart-table - $scope.displayedTags = [].concat($scope.tags); - - // selected tags $scope.selection = []; @@ -83,6 +77,19 @@ angular.module('tag-controller', ['registry-services']) return filterFilter($scope.displayedTags, { selected: true }); }; + // Watch tags for changes + // To watch for changes on a property inside the object "tags" + // we first have to make sure the promise is ready. + $scope.tags.$promise.then(function(data) { + // Copy collection for rendering in a smart-table + $scope.displayedTags = [].concat(data); + $scope.$watch('displayedTags|filter:{selected:true}', function(nv) { + $scope.selection = nv.map(function (tag) { + return $scope.repository + ':' + tag.name; + }); + }, true); + }); + $scope.openConfirmTagDeletionDialog = function(size) { var modalInstance = $modal.open({ animation: true, diff --git a/app/tag/tag-detail.html b/app/tag/tag-detail.html index 085756b..16d62ef 100644 --- a/app/tag/tag-detail.html +++ b/app/tag/tag-detail.html @@ -3,27 +3,21 @@
  • Repositories
  • {{repositoryUser}}
  • {{repositoryName}}
  • -
  • {{tagName}}
  • +
  • {{tagName}}
  • Details for tag {{repositoryUser}} / - {{repositoryName}} : - {{tagName}} + {{repositoryName}} : + {{tagName}}
    -
    - -

    diff --git a/app/tag/tag-list-directive.html b/app/tag/tag-list-directive.html index c9fc235..8edfc3a 100644 --- a/app/tag/tag-list-directive.html +++ b/app/tag/tag-list-directive.html @@ -10,7 +10,8 @@ - + + @@ -19,13 +20,19 @@ - - + + + - - + + diff --git a/develop/docker-compose.yml b/develop/docker-compose.yml index 3ac4b0a..711d30d 100644 --- a/develop/docker-compose.yml +++ b/develop/docker-compose.yml @@ -1,7 +1,10 @@ frontend: build: . links: - - registry:path-to-your-registry-v2 + - registry:registry + environment: + - DOCKER_REGISTRY_HOST=registry + - DOCKER_REGISTRY_PORT=5000 ports: # Serves the page via grunt - "9000:9000" @@ -11,6 +14,8 @@ frontend: - ../:/source:rw - ./start-develop.sh:/root/start-develop.sh:ro registry: - image: registry:2.1.1 + image: registry ports: - "5000:5000" + environment: + - REGISTRY_STORAGE_DELETE_ENABLED=true diff --git a/start-apache.sh b/start-apache.sh index a5c5b9b..b957fca 100644 --- a/start-apache.sh +++ b/start-apache.sh @@ -37,8 +37,6 @@ echo "{\"host\": \"$ENV_REGISTRY_PROXY_FQDN\", \"port\": $ENV_REGISTRY_PROXY_POR # information about browse mode. [[ x$ENV_MODE_BROWSE_ONLY =~ ^x(true|false)$ ]] || ENV_MODE_BROWSE_ONLY=false -# Overwrite browse-only option for now since only browse-only is working right now -ENV_MODE_BROWSE_ONLY=true [[ -z "$ENV_DEFAULT_REPOSITORIES_PER_PAGE" ]] && ENV_DEFAULT_REPOSITORIES_PER_PAGE=20 [[ -z "$ENV_DEFAULT_TAGS_PER_PAGE" ]] && ENV_DEFAULT_TAGS_PER_PAGE=10 echo "{\"browseOnly\":$ENV_MODE_BROWSE_ONLY, \"defaultRepositoriesPerPage\":$ENV_DEFAULT_REPOSITORIES_PER_PAGE , \"defaultTagsPerPage\":$ENV_DEFAULT_TAGS_PER_PAGE }" > /var/www/html/app-mode.json
    Tag Tag Image ID Created Author
    + +
    - {{tag.name}} +
    + + + {{tag.name}}