Skip to content

Commit 0314441

Browse files
committed
refactor: default instance name
1 parent e37968d commit 0314441

File tree

5 files changed

+30
-23
lines changed

5 files changed

+30
-23
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
*~
99
\#*
1010
.env
11-
/resources/
11+
/res/

.npmignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ src/
66
/docs/
77
.husky/
88
.env
9-
/resources/
9+
/res/

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

src/vms/base.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { paramCase } from "change-case";
1616
export default abstract class BaseBackend extends EventEmitter {
1717
protected readonly log: Log;
1818
protected readonly path: string;
19-
protected readonly instance: string = "default";
19+
protected readonly instance: string = "0";
2020
protected readonly container: string = "nerdctl";
2121

2222
constructor(path: string) {
@@ -26,7 +26,7 @@ export default abstract class BaseBackend extends EventEmitter {
2626
}
2727

2828
protected get resourcePath() {
29-
return join(this.path, "resources");
29+
return join(this.path, "res");
3030
}
3131

3232
//#region commons

src/vms/lima.ts

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,29 @@ export default class LimaBackend extends BaseBackend {
111111
} else {
112112
await this.downloadVM();
113113

114+
const resourcesDir = path.join(this.resourcePath, platform);
115+
const tarPath = path.join(resourcesDir, `lima-${LIMA_VERSION}.tgz`);
116+
const limaDir = path.join(resourcesDir, "lima");
117+
118+
await fs.promises.mkdir(limaDir, { recursive: true });
119+
120+
this.emit(events.VM_INIT_OUTPUT, "Extracting virtual machine files");
121+
122+
const child = ChildProcess.spawn("/usr/bin/tar", ["-xf", tarPath], {
123+
cwd: limaDir,
124+
stdio: "inherit",
125+
});
126+
127+
await new Promise((resolve, reject) => {
128+
child.on("exit", (code, signal) => {
129+
if (code === 0) {
130+
resolve(true);
131+
} else {
132+
reject(new Error(`Lima extract failed with ${code || signal}`));
133+
}
134+
});
135+
});
136+
114137
const config: LimaConfiguration = merge({
115138
arch: null,
116139
images: await this.downloadVMImages(),
@@ -169,30 +192,14 @@ export default class LimaBackend extends BaseBackend {
169192

170193
const url = `${LIMA_REPO}/${LIMA_VERSION}/lima-and-qemu.${platformName}${archName}.tar.gz`;
171194
const resourcesDir = path.join(this.resourcePath, platform);
172-
const limaDir = path.join(resourcesDir, "lima");
195+
173196
const tarPath = path.join(resourcesDir, `lima-${LIMA_VERSION}.tgz`);
174197

175198
this.emit(events.VM_INIT_OUTPUT, `Downloading virtual machine`);
176199

177200
await download(url, tarPath);
178-
await fs.promises.mkdir(limaDir, { recursive: true });
179201

180-
this.emit(events.VM_INIT_OUTPUT, "Extracting virtual machine files");
181-
182-
const child = ChildProcess.spawn("/usr/bin/tar", ["-xf", tarPath], {
183-
cwd: limaDir,
184-
stdio: "inherit",
185-
});
186-
187-
return await new Promise((resolve, reject) => {
188-
child.on("exit", (code, signal) => {
189-
if (code === 0) {
190-
resolve(true);
191-
} else {
192-
reject(new Error(`Lima extract failed with ${code || signal}`));
193-
}
194-
});
195-
});
202+
return true;
196203
}
197204

198205
async downloadVMImages(): Promise<VMImage[]> {

0 commit comments

Comments
 (0)