Skip to content

Commit 0a09638

Browse files
committed
undock: run
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
1 parent 735c66b commit 0a09638

File tree

2 files changed

+76
-4
lines changed

2 files changed

+76
-4
lines changed

__tests__/undock/undock.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,33 @@
1414
* limitations under the License.
1515
*/
1616

17+
import fs from 'fs';
18+
import os from 'os';
19+
import path from 'path';
1720
import {describe, expect, it, jest, test} from '@jest/globals';
1821
import * as semver from 'semver';
1922

2023
import {Exec} from '../../src/exec';
2124
import {Undock} from '../../src/undock/undock';
2225

26+
const tmpDir = fs.mkdtempSync(path.join(process.env.TEMP || os.tmpdir(), 'undock-undock-'));
27+
28+
describe('run', () => {
29+
it('extracts moby/moby-bin:26.1.5', async () => {
30+
const undock = new Undock();
31+
await expect(
32+
(async () => {
33+
// prettier-ignore
34+
await undock.run({
35+
source: 'moby/moby-bin:26.1.5',
36+
dist: tmpDir,
37+
all: true
38+
});
39+
})()
40+
).resolves.not.toThrow();
41+
}, 100000);
42+
});
43+
2344
describe('isAvailable', () => {
2445
it('checks undock is available', async () => {
2546
const execSpy = jest.spyOn(Exec, 'getExecOutput');

src/undock/undock.ts

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
import os from 'os';
18-
import path from 'path';
1917
import * as core from '@actions/core';
2018
import * as semver from 'semver';
2119

@@ -25,6 +23,20 @@ export interface UndockOpts {
2523
binPath?: string;
2624
}
2725

26+
export interface UndockRunOpts {
27+
source: string;
28+
dist: string;
29+
logLevel?: string;
30+
logCaller?: boolean;
31+
cacheDir?: string;
32+
platform?: string;
33+
all?: boolean;
34+
include?: Array<string>;
35+
insecure?: boolean;
36+
rmDist?: boolean;
37+
wrap?: boolean;
38+
}
39+
2840
export class Undock {
2941
private readonly binPath: string;
3042
private _version: string;
@@ -36,8 +48,47 @@ export class Undock {
3648
this._versionOnce = false;
3749
}
3850

39-
static get cacheDir(): string {
40-
return process.env.UNDOCK_CACHE_DIR || path.join(os.homedir(), '.local', 'share', 'undock', 'cache');
51+
public async run(opts: UndockRunOpts): Promise<void> {
52+
if (!opts.source) {
53+
throw new Error('source is required');
54+
}
55+
if (!opts.dist) {
56+
throw new Error('dist is required');
57+
}
58+
const args: Array<string> = [];
59+
if (opts.logLevel) {
60+
args.push(`--log-level=${opts.logLevel}`);
61+
}
62+
if (opts.logCaller) {
63+
args.push('--log-caller');
64+
}
65+
if (opts.cacheDir) {
66+
args.push(`--cachedir=${opts.cacheDir}`);
67+
}
68+
if (opts.platform) {
69+
args.push(`--platform=${opts.platform}`);
70+
}
71+
if (opts.all) {
72+
args.push('--all');
73+
}
74+
if (opts.include) {
75+
opts.include.forEach(i => {
76+
args.push(`--include=${i}`);
77+
});
78+
}
79+
if (opts.insecure) {
80+
args.push('--insecure');
81+
}
82+
if (opts.rmDist) {
83+
args.push('--rm-dist');
84+
}
85+
if (opts.wrap) {
86+
args.push('--wrap');
87+
}
88+
args.push(opts.source, opts.dist);
89+
await Exec.exec(this.binPath, args, {
90+
failOnStdErr: false
91+
});
4192
}
4293

4394
public async isAvailable(): Promise<boolean> {

0 commit comments

Comments
 (0)