Skip to content

Commit bd9ef98

Browse files
committed
fix: duplicate instance creation
1 parent 4c49bef commit bd9ef98

File tree

3 files changed

+41
-35
lines changed

3 files changed

+41
-35
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.3.3",
3+
"version": "0.3.4",
44
"main": "dist/index.js",
55
"types": "dist/index.d.ts",
66
"description": "Node wrapper for nerdctl",

src/index.ts

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,36 +20,37 @@ export function factory(path: string = process.cwd()): BaseBackend {
2020
}
2121
}
2222

23-
// if (process.env.NODE_ENV === "development") {
24-
// async function test() {
25-
// const IMAGE_NAME = "hello-world";
26-
// const CONTAINER_NAME = "hello";
27-
28-
// const vm = factory();
29-
// if (!(await vm.checkVM())) {
30-
// await vm.initVM();
31-
// }
32-
33-
// vm.on(events.IMAGE_PULL_START, () => {});
34-
// vm.on(events.IMAGE_PULL_OUTPUT, (data) => {
35-
// console.log(data);
36-
// });
37-
// vm.on(events.IMAGE_PULL_END, (data) => {
38-
// console.log(data);
39-
// });
40-
// vm.on(events.CONTAINER_RUN_OUTPUT, (data) => {
41-
// console.log(data);
42-
// });
43-
44-
// await vm.pullImage(IMAGE_NAME);
45-
46-
// const images = await vm.getImages();
47-
// console.log(images);
48-
49-
// await vm.run(IMAGE_NAME, { name: CONTAINER_NAME });
50-
// await vm.stop(CONTAINER_NAME);
51-
// await vm.remove(CONTAINER_NAME);
52-
// }
53-
54-
// test();
55-
// }
23+
if (process.env.NODE_ENV === "development") {
24+
async function test() {
25+
const IMAGE_NAME = "hello-world";
26+
const CONTAINER_NAME = "hello";
27+
28+
const vm = factory();
29+
30+
if (!(await vm.checkVM())) {
31+
await vm.initVM();
32+
}
33+
34+
vm.on(events.IMAGE_PULL_START, () => {});
35+
vm.on(events.IMAGE_PULL_OUTPUT, (data) => {
36+
console.log(data);
37+
});
38+
vm.on(events.IMAGE_PULL_END, (data) => {
39+
console.log(data);
40+
});
41+
vm.on(events.CONTAINER_RUN_OUTPUT, (data) => {
42+
console.log(data);
43+
});
44+
45+
await vm.pullImage(IMAGE_NAME);
46+
47+
const images = await vm.getImages();
48+
console.log(images);
49+
50+
await vm.run(IMAGE_NAME, { name: CONTAINER_NAME });
51+
await vm.stop(CONTAINER_NAME);
52+
await vm.remove(CONTAINER_NAME);
53+
}
54+
55+
test();
56+
}

src/vms/lima.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ export default class LimaBackend extends BaseBackend {
279279
async checkVM(): Promise<boolean> {
280280
try {
281281
await fs.promises.access(this.limactl, fs.constants.X_OK);
282-
return (await this.status)!.status === "Running";
282+
return (await this.status)!.name === "Running";
283283
} catch (ex: any) {
284284
return false;
285285
}
@@ -288,6 +288,11 @@ export default class LimaBackend extends BaseBackend {
288288
async initVM(): Promise<boolean> {
289289
this.emit(events.VM_INIT_START);
290290

291+
if (!!(await this.status)) {
292+
await this.lima("start", "--tty=false", this.instance);
293+
return true;
294+
}
295+
291296
const platformName = platform === "darwin" ? "macos" : "linux";
292297
const archName = isM1 ? "-aarch64" : "";
293298

0 commit comments

Comments
 (0)