Skip to content

Commit 1707161

Browse files
authored
Merge pull request #1014 from crazy-max/imagetools-annotations
buildx(imagetools): add annotations support for create command
2 parents b732db2 + 0cc9e68 commit 1707161

3 files changed

Lines changed: 43 additions & 0 deletions

File tree

__tests__/buildx/imagetools.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,43 @@ describe('create', () => {
117117
expect(result).toBeUndefined();
118118
});
119119

120+
it('passes annotations to imagetools create', async () => {
121+
const getCommand = vi.fn().mockResolvedValue({
122+
command: 'docker',
123+
args: ['buildx', 'imagetools', 'create']
124+
});
125+
const buildx = {getCommand} as unknown as Buildx;
126+
127+
const execSpy = vi.spyOn(Exec, 'getExecOutput').mockResolvedValue({
128+
exitCode: 0,
129+
stdout: '',
130+
stderr: ''
131+
});
132+
133+
const result = await new ImageTools({buildx}).create({
134+
sources: ['docker.io/library/alpine:latest'],
135+
annotations: ['index:org.opencontainers.image.title=Alpine', 'manifest-descriptor:org.opencontainers.image.description=Base image'],
136+
silent: true
137+
});
138+
139+
expect(getCommand).toHaveBeenCalledWith([
140+
'imagetools',
141+
'create',
142+
'--annotation',
143+
'index:org.opencontainers.image.title=Alpine',
144+
'--annotation',
145+
'manifest-descriptor:org.opencontainers.image.description=Base image',
146+
'--metadata-file',
147+
metadataFile,
148+
'docker.io/library/alpine:latest'
149+
]);
150+
expect(execSpy).toHaveBeenCalledWith('docker', ['buildx', 'imagetools', 'create'], {
151+
ignoreReturnCode: true,
152+
silent: true
153+
});
154+
expect(result).toBeUndefined();
155+
});
156+
120157
it('skips command execution when skipExec is enabled', async () => {
121158
const getCommand = vi.fn().mockResolvedValue({
122159
command: 'docker',

src/buildx/imagetools.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ export class ImageTools {
153153
args.push('--platform', platform);
154154
}
155155
}
156+
if (opts.annotations) {
157+
for (const annotation of opts.annotations) {
158+
args.push('--annotation', annotation);
159+
}
160+
}
156161
if (opts.dryRun) {
157162
args.push('--dry-run');
158163
} else {

src/types/buildx/imagetools.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export interface CreateOpts {
3232
sources: Array<string>;
3333
tags?: Array<string>;
3434
platforms?: Array<string>;
35+
annotations?: Array<string>;
3536
dryRun?: boolean;
3637
silent?: boolean;
3738
skipExec?: boolean;

0 commit comments

Comments
 (0)