mirror of
https://github.com/docker/metadata-action.git
synced 2024-12-22 09:55:36 +00:00
Merge pull request #370 from crazy-max/bake-cwd
bake: set cwd:// prefix for bake files path
This commit is contained in:
commit
41e1fe3437
28
.github/workflows/ci.yml
vendored
28
.github/workflows/ci.yml
vendored
|
@ -424,7 +424,7 @@ jobs:
|
|||
name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
with:
|
||||
version: v0.12.0-rc1
|
||||
version: latest
|
||||
-
|
||||
name: Build
|
||||
uses: docker/bake-action@v4
|
||||
|
@ -455,3 +455,29 @@ jobs:
|
|||
-
|
||||
name: Print envs
|
||||
run: env|sort
|
||||
|
||||
bake-cwd:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
-
|
||||
name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
with:
|
||||
version: latest
|
||||
-
|
||||
name: Docker meta
|
||||
id: docker_meta
|
||||
uses: ./
|
||||
-
|
||||
name: Build
|
||||
uses: docker/bake-action@v4
|
||||
with:
|
||||
files: |
|
||||
./test/docker-bake.hcl
|
||||
${{ steps.docker_meta.outputs.bake-file-tags }}
|
||||
${{ steps.docker_meta.outputs.bake-file-labels }}
|
||||
targets: |
|
||||
release
|
||||
|
|
2
dist/index.js
generated
vendored
2
dist/index.js
generated
vendored
File diff suppressed because one or more lines are too long
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
|
@ -94,17 +94,22 @@ actionsToolkit.run(
|
|||
setOutput('json', JSON.stringify(jsonOutput));
|
||||
});
|
||||
|
||||
// Specifying local and remote bake files is supported since Buildx 0.12.0.
|
||||
// Set cwd:// prefix for local bake files to avoid ambiguity with remote
|
||||
// https://github.com/docker/buildx/pull/1838
|
||||
const bakeFileCwdPrefix = (await toolkit.buildx.versionSatisfies('>=0.12.0').catch(() => false)) ? 'cwd://' : '';
|
||||
|
||||
// Bake files
|
||||
for (const kind of ['tags', 'labels', 'annotations:' + annotationsLevels]) {
|
||||
const outputName = kind.split(':')[0];
|
||||
const bakeFile: string = meta.getBakeFile(kind);
|
||||
await core.group(`Bake file definition (${outputName})`, async () => {
|
||||
core.info(fs.readFileSync(bakeFile, 'utf8'));
|
||||
setOutput(`bake-file-${outputName}`, bakeFile);
|
||||
setOutput(`bake-file-${outputName}`, `${bakeFileCwdPrefix}${bakeFile}`);
|
||||
});
|
||||
}
|
||||
|
||||
// Bake file with tags and labels
|
||||
setOutput(`bake-file`, meta.getBakeFileTagsLabels());
|
||||
setOutput(`bake-file`, `${bakeFileCwdPrefix}${meta.getBakeFileTagsLabels()}`);
|
||||
}
|
||||
);
|
||||
|
|
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 a new issue