From 0cc9e68b03c0892b7dea37a8550649c09e87a9d4 Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Tue, 10 Mar 2026 12:06:12 +0100 Subject: [PATCH] buildx(imagetools): add annotations support for create command Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> --- __tests__/buildx/imagetools.test.ts | 37 +++++++++++++++++++++++++++++ src/buildx/imagetools.ts | 5 ++++ src/types/buildx/imagetools.ts | 1 + 3 files changed, 43 insertions(+) diff --git a/__tests__/buildx/imagetools.test.ts b/__tests__/buildx/imagetools.test.ts index a397fe9a..9fa08faf 100644 --- a/__tests__/buildx/imagetools.test.ts +++ b/__tests__/buildx/imagetools.test.ts @@ -117,6 +117,43 @@ describe('create', () => { expect(result).toBeUndefined(); }); + it('passes annotations to imagetools create', async () => { + const getCommand = vi.fn().mockResolvedValue({ + command: 'docker', + args: ['buildx', 'imagetools', 'create'] + }); + const buildx = {getCommand} as unknown as Buildx; + + const execSpy = vi.spyOn(Exec, 'getExecOutput').mockResolvedValue({ + exitCode: 0, + stdout: '', + stderr: '' + }); + + const result = await new ImageTools({buildx}).create({ + sources: ['docker.io/library/alpine:latest'], + annotations: ['index:org.opencontainers.image.title=Alpine', 'manifest-descriptor:org.opencontainers.image.description=Base image'], + silent: true + }); + + expect(getCommand).toHaveBeenCalledWith([ + 'imagetools', + 'create', + '--annotation', + 'index:org.opencontainers.image.title=Alpine', + '--annotation', + 'manifest-descriptor:org.opencontainers.image.description=Base image', + '--metadata-file', + metadataFile, + 'docker.io/library/alpine:latest' + ]); + expect(execSpy).toHaveBeenCalledWith('docker', ['buildx', 'imagetools', 'create'], { + ignoreReturnCode: true, + silent: true + }); + expect(result).toBeUndefined(); + }); + it('skips command execution when skipExec is enabled', async () => { const getCommand = vi.fn().mockResolvedValue({ command: 'docker', diff --git a/src/buildx/imagetools.ts b/src/buildx/imagetools.ts index aab77fe1..319ca319 100644 --- a/src/buildx/imagetools.ts +++ b/src/buildx/imagetools.ts @@ -153,6 +153,11 @@ export class ImageTools { args.push('--platform', platform); } } + if (opts.annotations) { + for (const annotation of opts.annotations) { + args.push('--annotation', annotation); + } + } if (opts.dryRun) { args.push('--dry-run'); } else { diff --git a/src/types/buildx/imagetools.ts b/src/types/buildx/imagetools.ts index 35f7fe6d..af88ab58 100644 --- a/src/types/buildx/imagetools.ts +++ b/src/types/buildx/imagetools.ts @@ -32,6 +32,7 @@ export interface CreateOpts { sources: Array; tags?: Array; platforms?: Array; + annotations?: Array; dryRun?: boolean; silent?: boolean; skipExec?: boolean;