mirror of https://github.com/portainer/portainer
fix(image-details): fix the ability to pull an image from a tag (#878)
parent
6834c20b5d
commit
d3ecf1d7a8
@ -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;
|
||||
}]);
|
||||
|
Loading…
Reference in new issue