mirror of
https://github.com/portainer/portainer.git
synced 2025-08-05 05:45:22 +02:00
refactor(ui/image-config): create react component [EE-5342] (#8856)
This commit is contained in:
parent
bf51f1b6c9
commit
10014ae171
34 changed files with 1464 additions and 84 deletions
|
@ -1,5 +1,4 @@
|
|||
import _ from 'lodash-es';
|
||||
import { RegistryTypes } from 'Portainer/models/registryTypes';
|
||||
import { buildImageFullURI, imageContainsURL } from '@/react/docker/images/utils';
|
||||
|
||||
angular.module('portainer.docker').factory('ImageHelper', ImageHelperFactory);
|
||||
function ImageHelperFactory() {
|
||||
|
@ -29,67 +28,13 @@ function ImageHelperFactory() {
|
|||
* @param {PorImageRegistryModel} registry
|
||||
*/
|
||||
function createImageConfigForContainer(imageModel) {
|
||||
const registry = imageModel.UseRegistry ? imageModel.Registry : undefined;
|
||||
return {
|
||||
fromImage: buildImageFullURI(imageModel),
|
||||
fromImage: buildImageFullURI(imageModel.Image, registry),
|
||||
};
|
||||
}
|
||||
|
||||
function imageContainsURL(image) {
|
||||
const split = _.split(image, '/');
|
||||
const url = split[0];
|
||||
if (split.length > 1) {
|
||||
return _.includes(url, '.') || _.includes(url, ':');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function removeDigestFromRepository(repository) {
|
||||
return repository.split('@sha')[0];
|
||||
}
|
||||
}
|
||||
/**
|
||||
* builds the complete uri for an image based on its registry
|
||||
* @param {PorImageRegistryModel} imageModel
|
||||
*/
|
||||
export function buildImageFullURI(imageModel) {
|
||||
if (!imageModel.UseRegistry) {
|
||||
return ensureTag(imageModel.Image);
|
||||
}
|
||||
|
||||
const imageName = buildImageFullURIWithRegistry(imageModel);
|
||||
|
||||
return ensureTag(imageName);
|
||||
|
||||
function ensureTag(image, defaultTag = 'latest') {
|
||||
return image.includes(':') ? image : `${image}:${defaultTag}`;
|
||||
}
|
||||
}
|
||||
|
||||
function buildImageFullURIWithRegistry(imageModel) {
|
||||
switch (imageModel.Registry.Type) {
|
||||
case RegistryTypes.GITLAB:
|
||||
return buildImageURIForGitLab(imageModel);
|
||||
case RegistryTypes.QUAY:
|
||||
return buildImageURIForQuay(imageModel);
|
||||
case RegistryTypes.ANONYMOUS:
|
||||
return imageModel.Image;
|
||||
default:
|
||||
return buildImageURIForOtherRegistry(imageModel);
|
||||
}
|
||||
|
||||
function buildImageURIForGitLab(imageModel) {
|
||||
const slash = imageModel.Image.startsWith(':') ? '' : '/';
|
||||
return `${imageModel.Registry.URL}/${imageModel.Registry.Gitlab.ProjectPath}${slash}${imageModel.Image}`;
|
||||
}
|
||||
|
||||
function buildImageURIForQuay(imageModel) {
|
||||
const name = imageModel.Registry.Quay.UseOrganisation ? imageModel.Registry.Quay.OrganisationName : imageModel.Registry.Username;
|
||||
const url = imageModel.Registry.URL ? imageModel.Registry.URL + '/' : '';
|
||||
return `${url}${name}/${imageModel.Image}`;
|
||||
}
|
||||
|
||||
function buildImageURIForOtherRegistry(imageModel) {
|
||||
const url = imageModel.Registry.URL ? imageModel.Registry.URL + '/' : '';
|
||||
return url + imageModel.Image;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import _ from 'lodash-es';
|
||||
import { getUniqueTagListFromImages } from '@/react/docker/images/utils';
|
||||
import { ImageViewModel } from '../models/image';
|
||||
import { ImageDetailsViewModel } from '../models/imageDetails';
|
||||
import { ImageLayerViewModel } from '../models/imageLayer';
|
||||
|
@ -200,16 +200,7 @@ angular.module('portainer.docker').factory('ImageService', [
|
|||
return deferred.promise;
|
||||
};
|
||||
|
||||
service.getUniqueTagListFromImages = function (availableImages) {
|
||||
return _.uniq(
|
||||
_.flatMap(availableImages, function (image) {
|
||||
_.remove(image.RepoTags, function (item) {
|
||||
return item.indexOf('<none>') !== -1;
|
||||
});
|
||||
return image.RepoTags ? _.uniqWith(image.RepoTags, _.isEqual) : [];
|
||||
})
|
||||
);
|
||||
};
|
||||
service.getUniqueTagListFromImages = getUniqueTagListFromImages;
|
||||
|
||||
return service;
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue