fix(image-details): fix the ability to pull an image from a tag (#878)

pull/879/head
Anthony Lapenna 8 years ago committed by GitHub
parent 6834c20b5d
commit d3ecf1d7a8

@ -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() {

@ -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 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];
}
var imageConfig = {
repo: image,
tag: imageNameAndTag[1] ? imageNameAndTag[1] : 'latest'
return {
registry: registry,
image: image
};
};
return imageConfig;
},
createImageConfigForContainer: function (imageName, registry) {
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];
}
var imageConfig = {
fromImage: image,
tag: imageNameAndTag[1] ? imageNameAndTag[1] : 'latest'
return {
image: image,
tag: tag
};
return imageConfig;
}
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;
}]);

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

Loading…
Cancel
Save