mirror of https://github.com/portainer/portainer
46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
import { imageContainsURL } from '@/react/docker/images/utils';
|
|
|
|
import { ImageConfigValues } from '@@/ImageConfigFieldset';
|
|
|
|
import {
|
|
Registry,
|
|
RegistryId,
|
|
} from '../../portainer/registries/types/registry';
|
|
import { findBestMatchRegistry } from '../../portainer/registries/utils/findRegistryMatch';
|
|
import { getURL } from '../../portainer/registries/utils/getUrl';
|
|
|
|
export function getDefaultImageConfig(): ImageConfigValues {
|
|
return {
|
|
registryId: 0,
|
|
image: '',
|
|
useRegistry: true,
|
|
};
|
|
}
|
|
|
|
export function getImageConfig(
|
|
repository: string,
|
|
registries: Registry[],
|
|
registryId?: RegistryId
|
|
): ImageConfigValues {
|
|
const registry = findBestMatchRegistry(repository, registries, registryId);
|
|
if (registry) {
|
|
const url = getURL(registry);
|
|
let lastIndex = repository.lastIndexOf(url);
|
|
lastIndex = lastIndex === -1 ? 0 : lastIndex + url.length;
|
|
let image = repository.substring(lastIndex);
|
|
if (image.startsWith('/')) {
|
|
image = image.substring(1);
|
|
}
|
|
|
|
return {
|
|
useRegistry: true,
|
|
image,
|
|
registryId: registry.Id,
|
|
};
|
|
}
|
|
return {
|
|
image: repository,
|
|
useRegistry: imageContainsURL(repository),
|
|
};
|
|
}
|