mirror of
https://github.com/docker/metadata-action.git
synced 2025-07-05 09:48:24 +02:00
annotations support
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
27
src/main.ts
27
src/main.ts
@ -74,19 +74,38 @@ actionsToolkit.run(
|
||||
setOutput('labels', labels.join(inputs.sepLabels));
|
||||
});
|
||||
|
||||
// Annotations
|
||||
const alevels = process.env.DOCKER_METADATA_ANNOTATIONS_LEVELS || 'manifest';
|
||||
if (labels.length > 0) {
|
||||
await core.group(`Annotations`, async () => {
|
||||
const annotations: Array<string> = [];
|
||||
for (const level of alevels.split(',')) {
|
||||
annotations.push(
|
||||
...labels.map(label => {
|
||||
const v = `${level}:${label}`;
|
||||
core.info(v);
|
||||
return v;
|
||||
})
|
||||
);
|
||||
}
|
||||
setOutput(`annotations`, annotations.join(inputs.sepLabels));
|
||||
});
|
||||
}
|
||||
|
||||
// JSON
|
||||
const jsonOutput = meta.getJSON();
|
||||
const jsonOutput = meta.getJSON(alevels.split(','));
|
||||
await core.group(`JSON output`, async () => {
|
||||
core.info(JSON.stringify(jsonOutput, null, 2));
|
||||
setOutput('json', JSON.stringify(jsonOutput));
|
||||
});
|
||||
|
||||
// Bake files
|
||||
for (const kind of ['tags', 'labels']) {
|
||||
for (const kind of ['tags', 'labels', 'annotations:' + alevels]) {
|
||||
const outputName = kind.split(':')[0];
|
||||
const bakeFile: string = meta.getBakeFile(kind);
|
||||
await core.group(`Bake file definition (${kind})`, async () => {
|
||||
await core.group(`Bake file definition (${outputName})`, async () => {
|
||||
core.info(fs.readFileSync(bakeFile, 'utf8'));
|
||||
setOutput(`bake-file-${kind}`, bakeFile);
|
||||
setOutput(`bake-file-${outputName}`, bakeFile);
|
||||
});
|
||||
}
|
||||
|
||||
|
58
src/meta.ts
58
src/meta.ts
@ -480,7 +480,11 @@ export class Meta {
|
||||
.map(([key, value]) => `${key}=${value}`);
|
||||
}
|
||||
|
||||
public getJSON(): unknown {
|
||||
public getJSON(alevels: string[]): unknown {
|
||||
const annotations: Array<string> = [];
|
||||
for (const level of alevels) {
|
||||
annotations.push(...this.getLabels().map(label => `${level}:${label}`));
|
||||
}
|
||||
return {
|
||||
tags: this.getTags(),
|
||||
labels: this.getLabels().reduce((res, label) => {
|
||||
@ -490,34 +494,42 @@ export class Meta {
|
||||
}
|
||||
res[matches[1]] = matches[2];
|
||||
return res;
|
||||
}, {})
|
||||
}, {}),
|
||||
annotations: annotations
|
||||
};
|
||||
}
|
||||
|
||||
public getBakeFile(kind: string): string {
|
||||
switch (kind) {
|
||||
case 'tags':
|
||||
return this.generateBakeFile(kind, {
|
||||
tags: this.getTags(),
|
||||
args: {
|
||||
DOCKER_META_IMAGES: this.getImageNames().join(','),
|
||||
DOCKER_META_VERSION: this.version.main
|
||||
}
|
||||
});
|
||||
case 'labels':
|
||||
return this.generateBakeFile(kind, {
|
||||
labels: this.getLabels().reduce((res, label) => {
|
||||
const matches = label.match(/([^=]*)=(.*)/);
|
||||
if (!matches) {
|
||||
return res;
|
||||
}
|
||||
res[matches[1]] = matches[2];
|
||||
if (kind == 'tags') {
|
||||
return this.generateBakeFile(kind, {
|
||||
tags: this.getTags(),
|
||||
args: {
|
||||
DOCKER_META_IMAGES: this.getImageNames().join(','),
|
||||
DOCKER_META_VERSION: this.version.main
|
||||
}
|
||||
});
|
||||
} else if (kind == 'labels') {
|
||||
return this.generateBakeFile(kind, {
|
||||
labels: this.getLabels().reduce((res, label) => {
|
||||
const matches = label.match(/([^=]*)=(.*)/);
|
||||
if (!matches) {
|
||||
return res;
|
||||
}, {})
|
||||
});
|
||||
default:
|
||||
throw new Error(`Unknown bake file type: ${kind}`);
|
||||
}
|
||||
res[matches[1]] = matches[2];
|
||||
return res;
|
||||
}, {})
|
||||
});
|
||||
} else if (kind.startsWith('annotations:')) {
|
||||
const name = kind.split(':')[0];
|
||||
const annotations: Array<string> = [];
|
||||
for (const level of kind.split(':')[1].split(',')) {
|
||||
annotations.push(...this.getLabels().map(label => `${level}:${label}`));
|
||||
}
|
||||
return this.generateBakeFile(name, {
|
||||
annotations: annotations
|
||||
});
|
||||
}
|
||||
throw new Error(`Unknown bake file type: ${kind}`);
|
||||
}
|
||||
|
||||
public getBakeFileTagsLabels(): string {
|
||||
|
Reference in New Issue
Block a user