mirror of
https://code.forgejo.org/docker/build-push-action.git
synced 2025-08-11 17:10:54 +00:00
31 lines
801 B
TypeScript
31 lines
801 B
TypeScript
|
export interface Image {
|
||
|
registry?: string;
|
||
|
namespace?: string;
|
||
|
repository: string;
|
||
|
tag?: string;
|
||
|
}
|
||
|
|
||
|
export const parseImage = async (image: string): Promise<Image | undefined> => {
|
||
|
const match = image.match(/^(?:([^\/]+)\/)?(?:([^\/]+)\/)?([^@:\/]+)(?:[@:](.+))?$/);
|
||
|
if (!match) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
let res: Image = {
|
||
|
registry: match[1],
|
||
|
namespace: match[2],
|
||
|
repository: match[3],
|
||
|
tag: match[4]
|
||
|
};
|
||
|
|
||
|
if (!res.namespace && res.registry && !/[:.]/.test(res.registry)) {
|
||
|
res.namespace = res.registry;
|
||
|
res.registry = undefined;
|
||
|
}
|
||
|
|
||
|
res.registry = res.registry ? `${res.registry}/` : '';
|
||
|
res.namespace = res.namespace && res.namespace !== 'library' ? `${res.namespace}/` : '';
|
||
|
res.tag = res.tag && res.tag !== 'latest' ? `:${res.tag}` : '';
|
||
|
return res;
|
||
|
};
|