Skip to content

Commit cc5f82e

Browse files
committed
feat: added vm events
1 parent eacf31b commit cc5f82e

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ vm.on(events.IMAGE_PULL_END, (data) => {
2828
console.log(data);
2929
});
3030

31+
vm.on(events.CONTAINER_RUN_OUTPUT, (data) => {
32+
console.log(data);
33+
});
34+
3135
await vm.pullImage(IMAGE);
3236

3337
const images = await vm.getImages();

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

src/constants/events.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ export const VM_INIT_END = Symbol("VM_INIT_END");
55
export const IMAGE_PULL_START = Symbol("IMAGE_PULL_START");
66
export const IMAGE_PULL_OUTPUT = Symbol("IMAGE_PULL_OUTPUT");
77
export const IMAGE_PULL_END = Symbol("IMAGE_PULL_END");
8+
9+
export const CONTAINER_RUN_OUTPUT = Symbol("CONTAINER_RUN_OUTPUT");

src/vms/lima.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ export default class LimaBackend extends BaseBackend {
113113
if ("pull" === command) {
114114
this.emit(events.IMAGE_PULL_OUTPUT, dataString);
115115
}
116+
if ("run" === command) {
117+
this.emit(events.CONTAINER_RUN_OUTPUT, dataString);
118+
}
116119
});
117120
child.stderr?.on("data", (data: Buffer) => {
118121
let dataString = data.toString();
@@ -121,6 +124,9 @@ export default class LimaBackend extends BaseBackend {
121124
if ("pull" === command) {
122125
this.emit(events.IMAGE_PULL_OUTPUT, dataString);
123126
}
127+
if ("run" === command) {
128+
this.emit(events.CONTAINER_RUN_OUTPUT, dataString);
129+
}
124130
});
125131
child.on("exit", (code, signal) => {
126132
if (result.stderr) {
@@ -242,6 +248,11 @@ export default class LimaBackend extends BaseBackend {
242248
const limaDir = path.join(resourcesDir, "lima");
243249
const tarPath = path.join(resourcesDir, `lima-${LIMA_VERSION}.tgz`);
244250

251+
this.emit(
252+
events.VM_INIT_OUTPUT,
253+
`Downloading virtual machine from: ${url}`
254+
);
255+
245256
await download(url, tarPath);
246257
await fs.promises.mkdir(limaDir, { recursive: true });
247258

@@ -250,6 +261,8 @@ export default class LimaBackend extends BaseBackend {
250261
stdio: "inherit",
251262
});
252263

264+
this.emit(events.VM_INIT_OUTPUT, "Extracting virtual machine files");
265+
253266
await new Promise((resolve, reject) => {
254267
child.on("exit", (code, signal) => {
255268
if (code === 0) {
@@ -260,6 +273,8 @@ export default class LimaBackend extends BaseBackend {
260273
});
261274
});
262275

276+
this.emit(events.VM_INIT_OUTPUT, "Starting virtual machine");
277+
263278
await this.lima("start", "--tty=false", this.instance);
264279

265280
this.emit(events.VM_INIT_END);

0 commit comments

Comments
 (0)