Skip to content

Commit e37968d

Browse files
committed
feat: downloadVMImages
1 parent 5bea1b0 commit e37968d

File tree

5 files changed

+23
-8
lines changed

5 files changed

+23
-8
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nerdctl",
3-
"version": "0.4.2",
3+
"version": "0.4.3",
44
"main": "dist/index.js",
55
"types": "dist/index.d.ts",
66
"description": "Node wrapper for nerdctl",

src/types/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,8 @@ export interface ChildResultType {
66
code: number;
77
signal?: string;
88
}
9+
10+
export interface VMImage {
11+
location: string;
12+
arch: string;
13+
}

src/vms/base.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ChildResultType, VMImage } from "@/types";
12
import { ImageResult, RemoveImageCommandFlags } from "@/types/images";
23
import {
34
RemoveCommandFlags,
@@ -6,7 +7,6 @@ import {
67
} from "@/types/container";
78

89
import { APP_NAME } from "@/constants/app";
9-
import { ChildResultType } from "@/types";
1010
import { EventEmitter } from "events";
1111
import { GlobalFlags } from "@/types/global";
1212
import { Log } from "@/utils/logging";
@@ -84,5 +84,7 @@ export default abstract class BaseBackend extends EventEmitter {
8484
//#region VMs
8585
abstract checkVM(): Promise<boolean>;
8686
abstract initVM(): Promise<boolean>;
87+
abstract downloadVM(): Promise<boolean>;
88+
abstract downloadVMImages(): Promise<VMImage[]>;
8789
//#endregion
8890
}

src/vms/lima.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as childProcess from "@/utils/childProcess";
22
import * as events from "@/constants/events";
33

44
import ChildProcess, { spawn } from "child_process";
5+
import { ChildResultType, VMImage } from "@/types";
56
import { ImageResult, RemoveImageCommandFlags } from "@/types/images";
67
import { LIMA_REPO, LIMA_VERSION } from "@/constants/lima";
78
import { LimaConfiguration, LimaListResult } from "@/types/lima";
@@ -14,7 +15,6 @@ import { getVMArch, isM1, platform } from "@/utils";
1415

1516
import { APP_NAME } from "@/constants/app";
1617
import BaseBackend from "./base";
17-
import { ChildResultType } from "@/types";
1818
import { download } from "@/utils/download";
1919
import fs from "fs";
2020
import merge from "lodash/merge";
@@ -109,11 +109,11 @@ export default class LimaBackend extends BaseBackend {
109109
if (!!(await this.status)) {
110110
await this.lima("start", this.instance);
111111
} else {
112-
await this.downloadLima();
112+
await this.downloadVM();
113113

114114
const config: LimaConfiguration = merge({
115115
arch: null,
116-
images: await this.downloadLimaImages(),
116+
images: await this.downloadVMImages(),
117117
cpus: 2,
118118
memory: 2 * 1024 * 1024 * 1024,
119119
mounts: [
@@ -163,7 +163,7 @@ export default class LimaBackend extends BaseBackend {
163163
return true;
164164
}
165165

166-
async downloadLima(): Promise<boolean> {
166+
async downloadVM(): Promise<boolean> {
167167
const platformName = platform === "darwin" ? "macos" : "linux";
168168
const archName = isM1 ? "-aarch64" : "";
169169

@@ -195,7 +195,7 @@ export default class LimaBackend extends BaseBackend {
195195
});
196196
}
197197

198-
async downloadLimaImages(): Promise<{ location: string; arch: string }[]> {
198+
async downloadVMImages(): Promise<VMImage[]> {
199199
const arch = getVMArch();
200200
const archName = arch === "x86_64" ? "amd64" : "arm64";
201201

src/vms/wsl.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ChildResultType, VMImage } from "@/types";
12
import { ImageResult, RemoveImageCommandFlags } from "@/types/images";
23
import {
34
RemoveCommandFlags,
@@ -6,7 +7,6 @@ import {
67
} from "@/types/container";
78

89
import BaseBackend from "./base";
9-
import { ChildResultType } from "@/types";
1010

1111
export default class WslBackend extends BaseBackend {
1212
run(image: string, flags?: RunCommandFlags): Promise<ChildResultType> {
@@ -44,4 +44,12 @@ export default class WslBackend extends BaseBackend {
4444
async initVM(): Promise<boolean> {
4545
return true;
4646
}
47+
48+
async downloadVM(): Promise<boolean> {
49+
return true;
50+
}
51+
52+
async downloadVMImages(): Promise<VMImage[]> {
53+
return [];
54+
}
4755
}

0 commit comments

Comments
 (0)