Merge pull request #17 from crazy-max/docker-configdir
docker: configDir
This commit is contained in:
@@ -14,8 +14,10 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {beforeEach, describe, expect, it, jest} from '@jest/globals';
|
import {afterEach, beforeEach, describe, expect, it, jest} from '@jest/globals';
|
||||||
import * as exec from '@actions/exec';
|
import * as exec from '@actions/exec';
|
||||||
|
import path from 'path';
|
||||||
|
import osm = require('os');
|
||||||
|
|
||||||
import {Docker} from '../src/docker';
|
import {Docker} from '../src/docker';
|
||||||
|
|
||||||
@@ -23,10 +25,32 @@ beforeEach(() => {
|
|||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('configDir', () => {
|
||||||
|
const originalEnv = process.env;
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.resetModules();
|
||||||
|
process.env = {
|
||||||
|
...originalEnv,
|
||||||
|
DOCKER_CONFIG: '/var/docker/config'
|
||||||
|
};
|
||||||
|
});
|
||||||
|
afterEach(() => {
|
||||||
|
process.env = originalEnv;
|
||||||
|
});
|
||||||
|
it('returns default', async () => {
|
||||||
|
process.env.DOCKER_CONFIG = '';
|
||||||
|
jest.spyOn(osm, 'homedir').mockImplementation(() => path.join('/tmp', 'home'));
|
||||||
|
expect(Docker.configDir).toEqual(path.join('/tmp', 'home', '.docker'));
|
||||||
|
});
|
||||||
|
it('returns from env', async () => {
|
||||||
|
expect(Docker.configDir).toEqual('/var/docker/config');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('isAvailable', () => {
|
describe('isAvailable', () => {
|
||||||
it('cli', () => {
|
it('cli', () => {
|
||||||
const execSpy = jest.spyOn(exec, 'getExecOutput');
|
const execSpy = jest.spyOn(exec, 'getExecOutput');
|
||||||
Docker.isAvailable();
|
Docker.isAvailable;
|
||||||
// eslint-disable-next-line jest/no-standalone-expect
|
// eslint-disable-next-line jest/no-standalone-expect
|
||||||
expect(execSpy).toHaveBeenCalledWith(`docker`, undefined, {
|
expect(execSpy).toHaveBeenCalledWith(`docker`, undefined, {
|
||||||
silent: true,
|
silent: true,
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ export class Buildx {
|
|||||||
this.context = opts.context;
|
this.context = opts.context;
|
||||||
this.inputs = new Inputs(this.context);
|
this.inputs = new Inputs(this.context);
|
||||||
this.install = new Install({standalone: opts.standalone});
|
this.install = new Install({standalone: opts.standalone});
|
||||||
this.standalone = opts?.standalone ?? !Docker.isAvailable();
|
this.standalone = opts?.standalone ?? !Docker.isAvailable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getCommand(args: Array<string>) {
|
public getCommand(args: Array<string>) {
|
||||||
|
|||||||
@@ -14,10 +14,16 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import os from 'os';
|
||||||
|
import path from 'path';
|
||||||
import * as exec from '@actions/exec';
|
import * as exec from '@actions/exec';
|
||||||
|
|
||||||
export class Docker {
|
export class Docker {
|
||||||
public static isAvailable(): boolean {
|
static get configDir(): string {
|
||||||
|
return process.env.DOCKER_CONFIG || path.join(os.homedir(), '.docker');
|
||||||
|
}
|
||||||
|
|
||||||
|
static get isAvailable(): boolean {
|
||||||
let dockerAvailable = false;
|
let dockerAvailable = false;
|
||||||
exec
|
exec
|
||||||
.getExecOutput('docker', undefined, {
|
.getExecOutput('docker', undefined, {
|
||||||
@@ -39,7 +45,7 @@ export class Docker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static async printVersion(standalone?: boolean) {
|
public static async printVersion(standalone?: boolean) {
|
||||||
const noDocker = standalone ?? !Docker.isAvailable();
|
const noDocker = standalone ?? !Docker.isAvailable;
|
||||||
if (noDocker) {
|
if (noDocker) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -49,7 +55,7 @@ export class Docker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static async printInfo(standalone?: boolean) {
|
public static async printInfo(standalone?: boolean) {
|
||||||
const noDocker = standalone ?? !Docker.isAvailable();
|
const noDocker = standalone ?? !Docker.isAvailable;
|
||||||
if (noDocker) {
|
if (noDocker) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user