buildx(imagetools): add skip support and configurable create command silence

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2026-03-09 11:11:00 +01:00
parent 09c0f6a78e
commit d92ed04680
4 changed files with 48 additions and 3 deletions

View File

@@ -94,3 +94,14 @@ maybe('attestationDigests', () => {
expect(digests).toEqual(['sha256:0709528fae1747ce17638ad2978ee7936b38a294136eaadaf692e415f64b1e03']);
});
});
maybe('create', () => {
it('skips create command execution when skipExec is set', async () => {
const result = await new ImageTools().create({
sources: ['sha256:0709528fae1747ce17638ad2978ee7936b38a294136eaadaf692e415f64b1e03'],
tags: ['docker.io/user/app', 'docker.io/user/app2'],
skipExec: true
});
expect(result).toBeUndefined();
});
});

View File

@@ -70,7 +70,8 @@ describe('create', () => {
const result = await new ImageTools({buildx}).create({
sources: ['cwd://descriptor.json', 'docker.io/library/alpine:latest'],
tags: ['docker.io/user/app:latest']
tags: ['docker.io/user/app:latest'],
silent: true
});
expect(getCommand).toHaveBeenCalledWith(['imagetools', 'create', '--tag', 'docker.io/user/app:latest', '--metadata-file', metadataFile, '--file', 'descriptor.json', 'docker.io/library/alpine:latest']);
@@ -104,7 +105,8 @@ describe('create', () => {
const result = await new ImageTools({buildx}).create({
sources: ['docker.io/library/alpine:latest'],
dryRun: true
dryRun: true,
silent: true
});
expect(getCommand).toHaveBeenCalledWith(['imagetools', 'create', '--dry-run', 'docker.io/library/alpine:latest']);
@@ -114,4 +116,26 @@ describe('create', () => {
});
expect(result).toBeUndefined();
});
it('skips command execution when skipExec is enabled', 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'],
skipExec: true
});
expect(getCommand).toHaveBeenCalledWith(['imagetools', 'create', '--metadata-file', metadataFile, 'docker.io/library/alpine:latest']);
expect(execSpy).not.toHaveBeenCalled();
expect(result).toBeUndefined();
});
});