Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions __tests__/buildx/imagetools.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
5 changes: 5 additions & 0 deletions src/buildx/imagetools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/types/buildx/imagetools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface CreateOpts {
sources: Array<string>;
tags?: Array<string>;
platforms?: Array<string>;
annotations?: Array<string>;
dryRun?: boolean;
silent?: boolean;
skipExec?: boolean;
Expand Down
Loading