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:
@@ -94,3 +94,14 @@ maybe('attestationDigests', () => {
|
|||||||
expect(digests).toEqual(['sha256:0709528fae1747ce17638ad2978ee7936b38a294136eaadaf692e415f64b1e03']);
|
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();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -70,7 +70,8 @@ describe('create', () => {
|
|||||||
|
|
||||||
const result = await new ImageTools({buildx}).create({
|
const result = await new ImageTools({buildx}).create({
|
||||||
sources: ['cwd://descriptor.json', 'docker.io/library/alpine:latest'],
|
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']);
|
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({
|
const result = await new ImageTools({buildx}).create({
|
||||||
sources: ['docker.io/library/alpine:latest'],
|
sources: ['docker.io/library/alpine:latest'],
|
||||||
dryRun: true
|
dryRun: true,
|
||||||
|
silent: true
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(getCommand).toHaveBeenCalledWith(['imagetools', 'create', '--dry-run', 'docker.io/library/alpine:latest']);
|
expect(getCommand).toHaveBeenCalledWith(['imagetools', 'create', '--dry-run', 'docker.io/library/alpine:latest']);
|
||||||
@@ -114,4 +116,26 @@ describe('create', () => {
|
|||||||
});
|
});
|
||||||
expect(result).toBeUndefined();
|
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();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -15,6 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
import * as core from '@actions/core';
|
||||||
|
|
||||||
import {Buildx} from './buildx.js';
|
import {Buildx} from './buildx.js';
|
||||||
import {Context} from '../context.js';
|
import {Context} from '../context.js';
|
||||||
import {Exec} from '../exec.js';
|
import {Exec} from '../exec.js';
|
||||||
@@ -164,9 +166,15 @@ export class ImageTools {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const cmd = await this.getCreateCommand(args);
|
const cmd = await this.getCreateCommand(args);
|
||||||
|
if (opts.skipExec) {
|
||||||
|
core.info(`[command]${cmd.command} ${cmd.args.join(' ')}`);
|
||||||
|
core.info(`Skipped create command`);
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
return await Exec.getExecOutput(cmd.command, cmd.args, {
|
return await Exec.getExecOutput(cmd.command, cmd.args, {
|
||||||
ignoreReturnCode: true,
|
ignoreReturnCode: true,
|
||||||
silent: true
|
silent: opts.silent
|
||||||
}).then(res => {
|
}).then(res => {
|
||||||
if (res.stderr.length > 0 && res.exitCode != 0) {
|
if (res.stderr.length > 0 && res.exitCode != 0) {
|
||||||
throw new Error(res.stderr.trim());
|
throw new Error(res.stderr.trim());
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ export interface CreateOpts {
|
|||||||
tags?: Array<string>;
|
tags?: Array<string>;
|
||||||
platforms?: Array<string>;
|
platforms?: Array<string>;
|
||||||
dryRun?: boolean;
|
dryRun?: boolean;
|
||||||
|
silent?: boolean;
|
||||||
|
skipExec?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CreateResponse {
|
export interface CreateResponse {
|
||||||
|
|||||||
Reference in New Issue
Block a user