Merge pull request #31 from crazy-max/buildx-install
buildx: install method
This commit is contained in:
@@ -88,6 +88,14 @@ describe('certsDir', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('install', () => {
|
||||||
|
it('acquires buildx v0.9.1', async () => {
|
||||||
|
const buildx = new Buildx({context: new Context()});
|
||||||
|
const buildxBin = await buildx.install('v0.9.1', tmpDir);
|
||||||
|
expect(fs.existsSync(buildxBin)).toBe(true);
|
||||||
|
}, 100000);
|
||||||
|
});
|
||||||
|
|
||||||
describe('isAvailable', () => {
|
describe('isAvailable', () => {
|
||||||
it('docker cli', async () => {
|
it('docker cli', async () => {
|
||||||
const execSpy = jest.spyOn(exec, 'getExecOutput');
|
const execSpy = jest.spyOn(exec, 'getExecOutput');
|
||||||
|
|||||||
@@ -14,26 +14,31 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {describe, expect, it, jest, test, beforeEach} from '@jest/globals';
|
import {describe, expect, it, jest, test, beforeEach, afterEach} from '@jest/globals';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
import * as rimraf from 'rimraf';
|
||||||
import osm = require('os');
|
import osm = require('os');
|
||||||
|
|
||||||
import {Install} from '../../src/buildx/install';
|
import {Install} from '../../src/buildx/install';
|
||||||
|
|
||||||
|
// prettier-ignore
|
||||||
|
const tmpDir = path.join(process.env.TEMP || '/tmp', 'buildx-jest').split(path.sep).join(path.posix.sep);
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
afterEach(function () {
|
||||||
|
rimraf.sync(tmpDir);
|
||||||
|
});
|
||||||
|
|
||||||
describe('install', () => {
|
describe('install', () => {
|
||||||
// prettier-ignore
|
|
||||||
const tmpDir = path.join(process.env.TEMP || '/tmp', 'buildx-install-jest').split(path.sep).join(path.posix.sep);
|
|
||||||
|
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
test.each([
|
test.each([
|
||||||
['v0.4.1', false],
|
['v0.9.1', false],
|
||||||
['latest', false],
|
['latest', false],
|
||||||
['v0.4.1', true],
|
['v0.9.1', true],
|
||||||
['latest', true]
|
['latest', true]
|
||||||
])(
|
])(
|
||||||
'acquires %p of buildx (standalone: %p)', async (version, standalone) => {
|
'acquires %p of buildx (standalone: %p)', async (version, standalone) => {
|
||||||
|
|||||||
@@ -34,16 +34,16 @@ export interface BuildxOpts {
|
|||||||
export class Buildx {
|
export class Buildx {
|
||||||
private readonly context: Context;
|
private readonly context: Context;
|
||||||
private _version: string | undefined;
|
private _version: string | undefined;
|
||||||
|
private _install: Install;
|
||||||
|
|
||||||
public readonly inputs: Inputs;
|
public readonly inputs: Inputs;
|
||||||
public readonly install: Install;
|
|
||||||
public readonly standalone: boolean;
|
public readonly standalone: boolean;
|
||||||
|
|
||||||
constructor(opts: BuildxOpts) {
|
constructor(opts: BuildxOpts) {
|
||||||
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.standalone = opts?.standalone ?? !Docker.isAvailable;
|
this.standalone = opts?.standalone ?? !Docker.isAvailable;
|
||||||
|
this._install = new Install({standalone: opts.standalone});
|
||||||
}
|
}
|
||||||
|
|
||||||
static get configDir(): string {
|
static get configDir(): string {
|
||||||
@@ -61,6 +61,10 @@ export class Buildx {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async install(version: string, dest: string): Promise<string> {
|
||||||
|
return await this._install.install(version, dest);
|
||||||
|
}
|
||||||
|
|
||||||
public async isAvailable(): Promise<boolean> {
|
public async isAvailable(): Promise<boolean> {
|
||||||
const cmd = this.getCommand([]);
|
const cmd = this.getCommand([]);
|
||||||
return await exec
|
return await exec
|
||||||
|
|||||||
Reference in New Issue
Block a user