2019-03-21 05:46:49 +00:00
|
|
|
import _ from 'lodash-es';
|
|
|
|
|
2018-02-01 12:27:52 +00:00
|
|
|
angular.module('portainer.docker')
|
2017-01-31 23:26:29 +00:00
|
|
|
.factory('ImageHelper', [function ImageHelperFactory() {
|
|
|
|
'use strict';
|
2017-05-23 18:25:56 +00:00
|
|
|
|
|
|
|
var helper = {};
|
|
|
|
|
2017-06-20 11:00:32 +00:00
|
|
|
helper.extractImageAndRegistryFromRepository = function(repository) {
|
|
|
|
var slashCount = _.countBy(repository)['/'];
|
2017-05-23 18:25:56 +00:00
|
|
|
var registry = null;
|
2017-06-20 11:00:32 +00:00
|
|
|
var image = repository;
|
2017-08-09 08:40:46 +00:00
|
|
|
if (slashCount >= 1) {
|
|
|
|
// assume something/something[/...]
|
2017-06-20 11:00:32 +00:00
|
|
|
registry = repository.substr(0, repository.indexOf('/'));
|
2017-08-09 08:40:46 +00:00
|
|
|
// assume valid DNS name or IP (contains at least one '.')
|
|
|
|
if (_.countBy(registry)['.'] > 0) {
|
|
|
|
image = repository.substr(repository.indexOf('/') + 1);
|
|
|
|
} else {
|
|
|
|
registry = null;
|
|
|
|
}
|
2017-01-31 23:26:29 +00:00
|
|
|
}
|
2017-05-23 18:25:56 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
registry: registry,
|
|
|
|
image: image
|
|
|
|
};
|
2017-01-31 23:26:29 +00:00
|
|
|
};
|
2017-05-23 18:25:56 +00:00
|
|
|
|
2018-07-26 13:09:48 +00:00
|
|
|
helper.getImagesNamesForDownload = function(images) {
|
|
|
|
var names = images.map(function(image) {
|
|
|
|
return image.RepoTags[0] !== '<none>:<none>' ? image.RepoTags[0] : image.Id;
|
|
|
|
});
|
|
|
|
return {
|
|
|
|
names: names
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-05-23 18:25:56 +00:00
|
|
|
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
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2018-06-20 13:53:58 +00:00
|
|
|
helper.removeDigestFromRepository = function(repository) {
|
|
|
|
return repository.split('@sha')[0];
|
|
|
|
};
|
|
|
|
|
2017-05-23 18:25:56 +00:00
|
|
|
return helper;
|
2017-01-31 23:26:29 +00:00
|
|
|
}]);
|