Skip to content

Commit 932176e

Browse files
committed
docs: added requires in README.md
2 parents f6158e7 + c738936 commit 932176e

File tree

8 files changed

+107
-16
lines changed

8 files changed

+107
-16
lines changed

README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,65 @@
22

33
Node wrapper for nerdctl
44

5+
# Requires
6+
7+
## macOS
8+
9+
```shell
10+
# Install Homebrew
11+
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
12+
13+
# Install Lima
14+
brew install lima
15+
```
16+
17+
## Windows
18+
19+
```shell
20+
# Installing WSL GuestOS on PowerShell
21+
wsl --install -d Ubuntu-20.04
22+
23+
# Set user and password
24+
# Keep up to date
25+
sudo apt update && sudo apt upgrade -y
26+
27+
# Add distrod to the GuestOS
28+
curl -L -O "https://raw.githubusercontent.com/nullpo-head/wsl-distrod/main/install.sh"
29+
chmod +x install.sh
30+
sudo ./install.sh install
31+
32+
# Enable systemd
33+
sudo /opt/distrod/bin/distrod enable
34+
# Enable systemd and let it start as Windows starts
35+
sudo /opt/distrod/bin/distrod enable --start-on-windows-boot
36+
37+
# Restart WSL
38+
exit
39+
wsl -t Ubuntu-20.04
40+
wsl -d Ubuntu-20.04
41+
pgrep system -a
42+
43+
# Install additional required packages
44+
sudo apt install -y uidmap fuse-overlayfs
45+
46+
# Allow systemctl to run as rootless and put it in runtime path
47+
sudo loginctl enable-linger $(id -un)
48+
ls /run/user/$(id -u)
49+
export XDG_RUNTIME_DIR=/run/user/$(id -u)
50+
51+
# Install Nerdctl and Containerd
52+
cd ~/
53+
mkdir .local
54+
cd .local/
55+
wget https://github.com/containerd/nerdctl/releases/download/v0.15.0/nerdctl-full-0.15.0-linux-amd64.tar.gz
56+
tar xfz nerdctl-full-0.15.0-linux-amd64.tar.gz
57+
cd ~/
58+
# Run the installer through the path of the bin directory
59+
export PATH=$HOME/.local/bin:$PATH
60+
containerd-rootless-setuptool.sh install
61+
pgrep contain -a
62+
```
63+
564
# Install
665

766
```shell
@@ -14,6 +73,10 @@ yarn add nerdctl
1473
import { factory } from "nerdctl";
1574

1675
const engine = factory();
76+
77+
await engine.initVM();
78+
await engine.startVM();
79+
1780
const IMAGE = "hello-world";
1881

1982
await engine.pullImage(IMAGE);

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

src/index.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { ChildProcess, exec } from "child_process";
2-
31
import BaseBackend from "@/vms/base";
42
import LimaBackend from "@/vms/lima";
53
import WslBackend from "@/vms/wsl";
@@ -25,13 +23,17 @@ export function factory(
2523

2624
async function test() {
2725
const vm = factory("wsl -u vmenv");
28-
const images = await vm.getImages();
29-
console.log(images);
30-
await vm.pullImage("hello-world");
31-
32-
const container = await vm.run('hello-world', { detach: true });
33-
34-
vm.
26+
console.log(await vm.getImages());
27+
const child = await vm.pullImage("hello-world");
28+
await new Promise((resolve, reject) => {
29+
child.stderr?.on("data", (data) => {
30+
console.log(data);
31+
});
32+
child.stdout?.on("close", () => {
33+
resolve(true);
34+
});
35+
});
36+
console.log(await vm.getImages());
3537
}
3638

3739
test();

src/types/container.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export interface StopCommandFlags extends GlobalFlags {
6969
time?: string;
7070
}
7171

72-
export interface RmCommandFlags extends GlobalFlags {
72+
export interface RemoveCommandFlags extends GlobalFlags {
7373
force?: boolean;
7474
volumes?: boolean;
7575
}

src/types/images.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { GlobalFlags } from "./global";
2+
13
export interface ImageResult {
24
CreatedAt: string;
35
CreatedSince: string;
@@ -9,3 +11,8 @@ export interface ImageResult {
911
BlobSize: string;
1012
Platform: string;
1113
}
14+
15+
export interface RemoveImageCommandFlags extends GlobalFlags {
16+
async?: boolean;
17+
force?: boolean;
18+
}

src/vms/base.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { Architecture, ExecResult } from "@/types";
22
import { ExecOptions, ShellString, exec } from "shelljs";
3+
import { ImageResult, RemoveImageCommandFlags } from "@/types/images";
34
import {
45
LogsCommandFlags,
5-
RmCommandFlags,
6+
RemoveCommandFlags,
67
RunCommandFlags,
78
StopCommandFlags,
89
} from "@/types/container";
910

1011
import { ChildProcess } from "child_process";
1112
import { GlobalFlags } from "@/types/global";
12-
import { ImageResult } from "@/types/images";
1313
import { LoginCommandFlags } from "@/types/registry";
1414
import { paramCase } from "change-case";
1515
import { platform } from "@/utils";
@@ -90,6 +90,12 @@ export default abstract class BaseBackend {
9090

9191
return (await this.exec(command, { async: false })) as ShellString;
9292
}
93+
94+
async logout(server?: string): Promise<ShellString> {
95+
const command = `${this.container} logout ${server}`;
96+
97+
return (await this.exec(command, { async: false })) as ShellString;
98+
}
9399
//#endregion
94100

95101
//#region containers
@@ -113,7 +119,7 @@ export default abstract class BaseBackend {
113119

114120
async remove(
115121
container: string | string[],
116-
flags?: RmCommandFlags
122+
flags?: RemoveCommandFlags
117123
): Promise<ShellString> {
118124
const containers = Array.isArray(container)
119125
? container.join(" ")
@@ -159,5 +165,17 @@ export default abstract class BaseBackend {
159165
});
160166
});
161167
}
168+
169+
async removeImage(
170+
image: string | string[],
171+
flags?: RemoveImageCommandFlags
172+
): Promise<ShellString> {
173+
const images = Array.isArray(image) ? image.join(" ") : image;
174+
175+
return (await this.exec(
176+
`${this.container} rmi ${this.mergeFlags(flags)} ${images}`,
177+
{ async: false }
178+
)) as ShellString;
179+
}
162180
//#endregion
163181
}

src/vms/lima.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import BaseBackend from "./base";
22
import { ChildProcess } from "child_process";
33
import { LimaListResult } from "@/types/lima";
4+
import { isM1 } from "@/utils";
45
import { which } from "shelljs";
56

67
export default class LimaBackend extends BaseBackend {
78
async initVM(): Promise<boolean> {
89
if (!which("brew")) return false;
910
if (!which(this.vm)) {
10-
const child = (await this.exec(`brew install lima`)) as ChildProcess;
11+
const command = `${isM1 ? `arch -arm64 ` : ""}brew install lima`;
12+
const child = (await this.exec(command)) as ChildProcess;
1113
await new Promise((resolve, reject) => {
1214
child?.stdout?.on("data", (data) => {
1315
console.log(data);

src/vms/wsl.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export default class WslBackend extends BaseBackend {
1414

1515
async initVM(): Promise<boolean> {
1616
if (!which("wsl")) return false;
17-
if (!which(this.runtime)) return false;
1817
return true;
1918
}
2019

0 commit comments

Comments
 (0)