diff --git a/app/components/image/imageController.js b/app/components/image/imageController.js index 6f0c17eae..9a5ac8fba 100644 --- a/app/components/image/imageController.js +++ b/app/components/image/imageController.js @@ -17,7 +17,7 @@ function ($scope, $stateParams, $state, ImageService, Notifications) { $state.go('image', {id: $stateParams.id}, {reload: true}); }) .catch(function error(err) { - Notifications.error("Failure", err, "Unable to tag image"); + Notifications.error('Failure', err, 'Unable to tag image'); }) .finally(function final() { $('#loadingViewSpinner').hide(); @@ -31,7 +31,7 @@ function ($scope, $stateParams, $state, ImageService, Notifications) { Notifications.success('Image successfully pushed'); }) .catch(function error(err) { - Notifications.error("Failure", err, "Unable to push image tag"); + Notifications.error('Failure', err, 'Unable to push image tag'); }) .finally(function final() { $('#loadingViewSpinner').hide(); @@ -40,15 +40,13 @@ function ($scope, $stateParams, $state, ImageService, Notifications) { $scope.pullImage = function(tag) { $('#loadingViewSpinner').show(); - var image = $scope.config.Image; - var registry = $scope.config.Registry; - ImageService.pullImage(image, registry) + ImageService.pullTag(tag) .then(function success(data) { - Notifications.success('Image successfully pulled', image); + Notifications.success('Image successfully pulled', tag); }) .catch(function error(err){ - Notifications.error("Failure", err, "Unable to pull image"); + Notifications.error('Failure', err, 'Unable to pull image'); }) .finally(function final() { $('#loadingViewSpinner').hide(); @@ -68,7 +66,7 @@ function ($scope, $stateParams, $state, ImageService, Notifications) { } }) .catch(function error(err) { - Notifications.error("Failure", err, 'Unable to remove image'); + Notifications.error('Failure', err, 'Unable to remove image'); }) .finally(function final() { $('#loadingViewSpinner').hide(); @@ -83,7 +81,7 @@ function ($scope, $stateParams, $state, ImageService, Notifications) { $state.go('images', {}, {reload: true}); }) .catch(function error(err) { - Notifications.error("Failure", err, 'Unable to remove image'); + Notifications.error('Failure', err, 'Unable to remove image'); }) .finally(function final() { $('#loadingViewSpinner').hide(); @@ -97,7 +95,7 @@ function ($scope, $stateParams, $state, ImageService, Notifications) { $scope.image = data; }) .catch(function error(err) { - Notifications.error("Failure", err, "Unable to retrieve image details"); + Notifications.error('Failure', err, 'Unable to retrieve image details'); $state.go('images'); }) .finally(function final() { diff --git a/app/helpers/imageHelper.js b/app/helpers/imageHelper.js index 864f248bc..03cb21efa 100644 --- a/app/helpers/imageHelper.js +++ b/app/helpers/imageHelper.js @@ -1,30 +1,55 @@ angular.module('portainer.helpers') .factory('ImageHelper', [function ImageHelperFactory() { 'use strict'; - return { - createImageConfigForCommit: function(imageName, registry) { - var imageNameAndTag = imageName.split(':'); - var image = imageNameAndTag[0]; - if (registry) { - image = registry + '/' + imageNameAndTag[0]; - } - var imageConfig = { - repo: image, - tag: imageNameAndTag[1] ? imageNameAndTag[1] : 'latest' - }; - return imageConfig; - }, - createImageConfigForContainer: function (imageName, registry) { - var imageNameAndTag = imageName.split(':'); - var image = imageNameAndTag[0]; - if (registry) { - image = registry + '/' + imageNameAndTag[0]; - } - var imageConfig = { - fromImage: image, - tag: imageNameAndTag[1] ? imageNameAndTag[1] : 'latest' - }; - return imageConfig; + + var helper = {}; + + helper.extractImageAndRegistryFromTag = function(tag) { + var slashCount = _.countBy(tag)['/']; + var registry = null; + var image = tag; + if (slashCount > 1) { + // assume something/some/thing[/...] + var registryAndImage = _.split(tag, '/'); + registry = registryAndImage[0]; + image = registryAndImage[1]; } + + return { + registry: registry, + image: image + }; }; + + function extractNameAndTag(imageName, registry) { + var imageNameAndTag = imageName.split(':'); + var image = imageNameAndTag[0]; + var tag = imageNameAndTag[1] ? imageNameAndTag[1] : 'latest'; + if (registry) { + image = registry + '/' + imageNameAndTag[0]; + } + + return { + image: image, + tag: tag + }; + } + + helper.createImageConfigForCommit = function(imageName, registry) { + var imageAndTag = extractNameAndTag(imageName, registry); + return { + repo: imageAndTag.image, + tag: imageAndTag.tag + }; + }; + + helper.createImageConfigForContainer = function (imageName, registry) { + var imageAndTag = extractNameAndTag(imageName, registry); + return { + fromImage: imageAndTag.image, + tag: imageAndTag.tag + }; + }; + + return helper; }]); diff --git a/app/services/imageService.js b/app/services/imageService.js index a8a29cac5..a43f0c53f 100644 --- a/app/services/imageService.js +++ b/app/services/imageService.js @@ -40,10 +40,10 @@ angular.module('portainer.services') var imageConfiguration = ImageHelper.createImageConfigForContainer(image, registry); Image.create(imageConfiguration).$promise .then(function success(data) { - var err = data.length > 0 && data[data.length - 1].hasOwnProperty('error'); + var err = data.length > 0 && data[data.length - 1].hasOwnProperty('message'); if (err) { var detail = data[data.length - 1]; - deferred.reject({ msg: detail.error }); + deferred.reject({ msg: detail.message }); } else { deferred.resolve(data); } @@ -54,6 +54,11 @@ angular.module('portainer.services') return deferred.promise; }; + service.pullTag = function(tag) { + var imageAndRegistry = ImageHelper.extractImageAndRegistryFromTag(tag); + return service.pullImage(imageAndRegistry.image, imageAndRegistry.registry); + }; + service.tagImage = function(id, image, registry) { var imageConfig = ImageHelper.createImageConfigForCommit(image, registry); return Image.tag({id: id, tag: imageConfig.tag, repo: imageConfig.repo}).$promise;