docker: set default standalone

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2023-01-23 14:48:00 +01:00
parent fe07aec685
commit fdc8b5d37b
4 changed files with 15 additions and 21 deletions

View File

@@ -78,7 +78,9 @@ describe('hasLocalOrTarExporter', () => {
describe('isAvailable', () => { describe('isAvailable', () => {
it('docker cli', async () => { it('docker cli', async () => {
const execSpy = jest.spyOn(exec, 'getExecOutput'); const execSpy = jest.spyOn(exec, 'getExecOutput');
const buildx = new Buildx(); const buildx = new Buildx({
standalone: false
});
await buildx.isAvailable(); await buildx.isAvailable();
// eslint-disable-next-line jest/no-standalone-expect // eslint-disable-next-line jest/no-standalone-expect
expect(execSpy).toHaveBeenCalledWith(`docker`, ['buildx'], { expect(execSpy).toHaveBeenCalledWith(`docker`, ['buildx'], {

View File

@@ -19,7 +19,7 @@ describe('isAvailable', () => {
describe('info', () => { describe('info', () => {
it('standard', () => { it('standard', () => {
const execSpy = jest.spyOn(exec, 'exec'); const execSpy = jest.spyOn(exec, 'exec');
Docker.info(); Docker.info(false);
expect(execSpy).toHaveBeenCalledWith(`docker`, ['version'], { expect(execSpy).toHaveBeenCalledWith(`docker`, ['version'], {
failOnStdErr: false failOnStdErr: false
}); });

View File

@@ -18,22 +18,10 @@ export class Buildx {
private tmpdir = fs.mkdtempSync(path.join(os.tmpdir(), 'docker-actions-toolkit-')).split(path.sep).join(path.posix.sep); private tmpdir = fs.mkdtempSync(path.join(os.tmpdir(), 'docker-actions-toolkit-')).split(path.sep).join(path.posix.sep);
constructor(opts?: BuildxOpts) { constructor(opts?: BuildxOpts) {
this.standalone = opts?.standalone ?? this.isStandalone(); this.standalone = opts?.standalone ?? !Docker.isAvailable();
this.version = this.getVersion(); this.version = this.getVersion();
} }
private isStandalone(): boolean {
let dockerAvailable = false;
Docker.isAvailable()
.then((res: boolean) => {
dockerAvailable = res;
})
.catch(e => {
dockerAvailable = false;
});
return dockerAvailable;
}
public getCommand(args: Array<string>) { public getCommand(args: Array<string>) {
return { return {
command: this.standalone ? 'buildx' : 'docker', command: this.standalone ? 'buildx' : 'docker',

View File

@@ -2,26 +2,30 @@ import * as core from '@actions/core';
import * as exec from '@actions/exec'; import * as exec from '@actions/exec';
export class Docker { export class Docker {
public static async isAvailable(): Promise<boolean> { public static isAvailable(): boolean {
return await exec let dockerAvailable = false;
exec
.getExecOutput('docker', undefined, { .getExecOutput('docker', undefined, {
ignoreReturnCode: true, ignoreReturnCode: true,
silent: true silent: true
}) })
.then(res => { .then(res => {
if (res.stderr.length > 0 && res.exitCode != 0) { if (res.stderr.length > 0 && res.exitCode != 0) {
return false; dockerAvailable = false;
} else {
dockerAvailable = res.exitCode == 0;
} }
return res.exitCode == 0;
}) })
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
.catch(error => { .catch(error => {
return false; dockerAvailable = false;
}); });
return dockerAvailable;
} }
public static async info(standalone?: boolean) { public static async info(standalone?: boolean) {
if (standalone) { const dockerAvailable = standalone ?? !Docker.isAvailable();
if (dockerAvailable) {
core.info(`Docker info skipped in standalone mode`); core.info(`Docker info skipped in standalone mode`);
} else { } else {
await exec.exec('docker', ['version'], { await exec.exec('docker', ['version'], {