mirror of
https://github.com/docker/metadata-action.git
synced 2024-11-22 20:15:41 +01:00
bake: refactor generateBakeFile
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
parent
74fa878183
commit
36ea4ee555
42
src/meta.ts
42
src/meta.ts
@ -522,15 +522,19 @@ export class Meta {
|
||||
|
||||
public getBakeFile(kind: string): string {
|
||||
if (kind == 'tags') {
|
||||
return this.generateBakeFile(kind, {
|
||||
return this.generateBakeFile(
|
||||
{
|
||||
tags: this.getTags(),
|
||||
args: {
|
||||
DOCKER_META_IMAGES: this.getImageNames().join(','),
|
||||
DOCKER_META_VERSION: this.version.main
|
||||
}
|
||||
});
|
||||
},
|
||||
kind
|
||||
);
|
||||
} else if (kind == 'labels') {
|
||||
return this.generateBakeFile(kind, {
|
||||
return this.generateBakeFile(
|
||||
{
|
||||
labels: this.getLabels().reduce((res, label) => {
|
||||
const matches = label.match(/([^=]*)=(.*)/);
|
||||
if (!matches) {
|
||||
@ -539,28 +543,27 @@ export class Meta {
|
||||
res[matches[1]] = matches[2];
|
||||
return res;
|
||||
}, {})
|
||||
});
|
||||
},
|
||||
kind
|
||||
);
|
||||
} 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.getAnnotations().map(label => `${level}:${label}`));
|
||||
}
|
||||
return this.generateBakeFile(name, {
|
||||
return this.generateBakeFile(
|
||||
{
|
||||
annotations: annotations
|
||||
});
|
||||
},
|
||||
name
|
||||
);
|
||||
}
|
||||
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,
|
||||
JSON.stringify(
|
||||
{
|
||||
target: {
|
||||
[this.inputs.bakeTarget]: {
|
||||
return this.generateBakeFile({
|
||||
tags: this.getTags(),
|
||||
labels: this.getLabels().reduce((res, label) => {
|
||||
const matches = label.match(/([^=]*)=(.*)/);
|
||||
@ -574,18 +577,11 @@ export class Meta {
|
||||
DOCKER_META_IMAGES: this.getImageNames().join(','),
|
||||
DOCKER_META_VERSION: this.version.main
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
null,
|
||||
2
|
||||
)
|
||||
);
|
||||
return bakeFile;
|
||||
});
|
||||
}
|
||||
|
||||
private generateBakeFile(name: string, dt): string {
|
||||
const bakeFile = path.join(ToolkitContext.tmpDir(), `docker-metadata-action-bake-${name}.json`);
|
||||
private generateBakeFile(dt, suffix?: string): string {
|
||||
const bakeFile = path.join(ToolkitContext.tmpDir(), `docker-metadata-action-bake${suffix ? `-${suffix}` : ''}.json`);
|
||||
fs.writeFileSync(bakeFile, JSON.stringify({target: {[this.inputs.bakeTarget]: dt}}, null, 2));
|
||||
return bakeFile;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user