Skip to content

Commit d21d31d

Browse files
authored
Merge pull request #17 from crazy-max/docker-configdir
docker: configDir
2 parents 3150492 + 765b236 commit d21d31d

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

__tests__/docker.test.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,43 @@
1414
* limitations under the License.
1515
*/
1616

17-
import {beforeEach, describe, expect, it, jest} from '@jest/globals';
17+
import {afterEach, beforeEach, describe, expect, it, jest} from '@jest/globals';
1818
import * as exec from '@actions/exec';
19+
import path from 'path';
20+
import osm = require('os');
1921

2022
import {Docker} from '../src/docker';
2123

2224
beforeEach(() => {
2325
jest.clearAllMocks();
2426
});
2527

28+
describe('configDir', () => {
29+
const originalEnv = process.env;
30+
beforeEach(() => {
31+
jest.resetModules();
32+
process.env = {
33+
...originalEnv,
34+
DOCKER_CONFIG: '/var/docker/config'
35+
};
36+
});
37+
afterEach(() => {
38+
process.env = originalEnv;
39+
});
40+
it('returns default', async () => {
41+
process.env.DOCKER_CONFIG = '';
42+
jest.spyOn(osm, 'homedir').mockImplementation(() => path.join('/tmp', 'home'));
43+
expect(Docker.configDir).toEqual(path.join('/tmp', 'home', '.docker'));
44+
});
45+
it('returns from env', async () => {
46+
expect(Docker.configDir).toEqual('/var/docker/config');
47+
});
48+
});
49+
2650
describe('isAvailable', () => {
2751
it('cli', () => {
2852
const execSpy = jest.spyOn(exec, 'getExecOutput');
29-
Docker.isAvailable();
53+
Docker.isAvailable;
3054
// eslint-disable-next-line jest/no-standalone-expect
3155
expect(execSpy).toHaveBeenCalledWith(`docker`, undefined, {
3256
silent: true,

src/buildx/buildx.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class Buildx {
3939
this.context = opts.context;
4040
this.inputs = new Inputs(this.context);
4141
this.install = new Install({standalone: opts.standalone});
42-
this.standalone = opts?.standalone ?? !Docker.isAvailable();
42+
this.standalone = opts?.standalone ?? !Docker.isAvailable;
4343
}
4444

4545
public getCommand(args: Array<string>) {

src/docker.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,16 @@
1414
* limitations under the License.
1515
*/
1616

17+
import os from 'os';
18+
import path from 'path';
1719
import * as exec from '@actions/exec';
1820

1921
export class Docker {
20-
public static isAvailable(): boolean {
22+
static get configDir(): string {
23+
return process.env.DOCKER_CONFIG || path.join(os.homedir(), '.docker');
24+
}
25+
26+
static get isAvailable(): boolean {
2127
let dockerAvailable = false;
2228
exec
2329
.getExecOutput('docker', undefined, {
@@ -39,7 +45,7 @@ export class Docker {
3945
}
4046

4147
public static async printVersion(standalone?: boolean) {
42-
const noDocker = standalone ?? !Docker.isAvailable();
48+
const noDocker = standalone ?? !Docker.isAvailable;
4349
if (noDocker) {
4450
return;
4551
}
@@ -49,7 +55,7 @@ export class Docker {
4955
}
5056

5157
public static async printInfo(standalone?: boolean) {
52-
const noDocker = standalone ?? !Docker.isAvailable();
58+
const noDocker = standalone ?? !Docker.isAvailable;
5359
if (noDocker) {
5460
return;
5561
}

0 commit comments

Comments
 (0)