mirror of
https://github.com/docker/metadata-action.git
synced 2025-07-05 09:48:24 +02:00
bake: split definition into two files
Allows to either include tags or labels or both definitions. Keep bake-file output for backward compatibility. Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
17
src/main.ts
17
src/main.ts
@ -81,11 +81,16 @@ actionsToolkit.run(
|
||||
setOutput('json', JSON.stringify(jsonOutput));
|
||||
});
|
||||
|
||||
// Bake file definition
|
||||
const bakeFile: string = meta.getBakeFile();
|
||||
await core.group(`Bake file definition`, async () => {
|
||||
core.info(fs.readFileSync(bakeFile, 'utf8'));
|
||||
setOutput('bake-file', bakeFile);
|
||||
});
|
||||
// Bake files
|
||||
for (const kind of ['tags', 'labels']) {
|
||||
const bakeFile: string = meta.getBakeFile(kind);
|
||||
await core.group(`Bake file definition (${kind})`, async () => {
|
||||
core.info(fs.readFileSync(bakeFile, 'utf8'));
|
||||
setOutput(`bake-file-${kind}`, bakeFile);
|
||||
});
|
||||
}
|
||||
|
||||
// Bake file with tags and labels
|
||||
setOutput(`bake-file`, meta.getBakeFileTagsLabels());
|
||||
}
|
||||
);
|
||||
|
33
src/meta.ts
33
src/meta.ts
@ -494,7 +494,33 @@ export class Meta {
|
||||
};
|
||||
}
|
||||
|
||||
public getBakeFile(): string {
|
||||
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];
|
||||
return res;
|
||||
}, {})
|
||||
});
|
||||
default:
|
||||
throw new Error(`Unknown bake file type: ${kind}`);
|
||||
}
|
||||
}
|
||||
|
||||
public getBakeFileTagsLabels(): string {
|
||||
const bakeFile = path.join(ToolkitContext.tmpDir(), 'docker-metadata-action-bake.json');
|
||||
fs.writeFileSync(
|
||||
bakeFile,
|
||||
@ -522,7 +548,12 @@ export class Meta {
|
||||
2
|
||||
)
|
||||
);
|
||||
return bakeFile;
|
||||
}
|
||||
|
||||
private generateBakeFile(name: string, dt): string {
|
||||
const bakeFile = path.join(ToolkitContext.tmpDir(), `docker-metadata-action-bake-${name}.json`);
|
||||
fs.writeFileSync(bakeFile, JSON.stringify({target: {[this.inputs.bakeTarget]: dt}}, null, 2));
|
||||
return bakeFile;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user