From 5e365b5a488036bc04f4812ea53448bff5d71eee Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Fri, 10 Feb 2023 11:31:34 +0100 Subject: [PATCH] buildx: configDir Signed-off-by: CrazyMax --- __tests__/buildx/buildx.test.ts | 22 ++++++++++++++++++++++ src/buildx/buildx.ts | 5 +++++ 2 files changed, 27 insertions(+) diff --git a/__tests__/buildx/buildx.test.ts b/__tests__/buildx/buildx.test.ts index c3abad0..835b44b 100644 --- a/__tests__/buildx/buildx.test.ts +++ b/__tests__/buildx/buildx.test.ts @@ -46,6 +46,28 @@ afterEach(() => { rimraf.sync(tmpDir); }); +describe('configDir', () => { + const originalEnv = process.env; + beforeEach(() => { + jest.resetModules(); + process.env = { + ...originalEnv, + BUILDX_CONFIG: '/var/docker/buildx', + DOCKER_CONFIG: '/var/docker/config' + }; + }); + afterEach(() => { + process.env = originalEnv; + }); + it('returns default', async () => { + process.env.BUILDX_CONFIG = ''; + expect(Buildx.configDir).toEqual(path.join('/var/docker/config', 'buildx')); + }); + it('returns from env', async () => { + expect(Buildx.configDir).toEqual('/var/docker/buildx'); + }); +}); + describe('isAvailable', () => { it('docker cli', async () => { const execSpy = jest.spyOn(exec, 'getExecOutput'); diff --git a/src/buildx/buildx.ts b/src/buildx/buildx.ts index a46cdf4..30b47c0 100644 --- a/src/buildx/buildx.ts +++ b/src/buildx/buildx.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import path from 'path'; import * as exec from '@actions/exec'; import * as semver from 'semver'; @@ -42,6 +43,10 @@ export class Buildx { this.standalone = opts?.standalone ?? !Docker.isAvailable; } + static get configDir(): string { + return process.env.BUILDX_CONFIG || path.join(Docker.configDir, 'buildx'); + } + public getCommand(args: Array) { return { command: this.standalone ? 'buildx' : 'docker',