@tomasko/serbox 0.0.0-stage → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -2
- package/bin/serbox.js +58 -0
- package/lib.js +267 -0
- package/package.json +46 -4
- package/skills/serbox/SKILL.md +166 -0
- package/skills/serbox-basic-setup/SKILL.md +121 -0
- package/skills/serbox-basic-setup/scripts/copy.sh +43 -0
- package/skills/serbox-basic-setup/scripts/scan.mjs +68 -0
- package/skills/serbox-move-repo/SKILL.md +99 -0
- package/skills/serbox-move-repo/scripts/deps.sh +38 -0
- package/skills/serbox-move-repo/scripts/move.sh +35 -0
- package/skills/serbox-move-repo/scripts/repo-files.mjs +109 -0
- package/skills/serbox-snapshots/SKILL.md +87 -0
package/README.md
CHANGED
|
@@ -1,3 +1,34 @@
|
|
|
1
|
-
#
|
|
1
|
+
# serbox
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Linux boxes for agents — on your own server.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npx @tomasko/serbox create --name dev
|
|
7
|
+
npx @tomasko/serbox ssh dev
|
|
8
|
+
npx @tomasko/serbox rm dev --yes
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
This package is a small launcher. On first run it downloads the statically
|
|
12
|
+
linked `serbox` binary for your machine (linux-x86_64 or linux-aarch64) from
|
|
13
|
+
GitHub Releases into `~/.cache/serbox`, verifies the published SHA-256, and
|
|
14
|
+
execs it. There is no install script, so it works under `npm ci
|
|
15
|
+
--ignore-scripts`, pnpm and `npx`.
|
|
16
|
+
|
|
17
|
+
Requirements: Linux with a reachable Docker or Podman engine. `serbox doctor`
|
|
18
|
+
checks it. Set `SERBOX_RUNTIME=podman` to use Podman; it is detected
|
|
19
|
+
automatically when Docker is absent.
|
|
20
|
+
|
|
21
|
+
`serbox` needs no account, API key or hosted service: it creates isolated
|
|
22
|
+
Docker boxes on the machine it runs on and gives you `create`, `exec`, `ssh`,
|
|
23
|
+
`push`/`pull`, `suspend`, `snapshot`, `fork`, `port publish`, `secrets` and
|
|
24
|
+
`skills install` around them, with `--json` and documented exit codes for
|
|
25
|
+
agents and scripts. Four agent skills (`serbox`, `serbox-snapshots`,
|
|
26
|
+
`serbox-move-repo`, `serbox-basic-setup`) ship in this package under `skills/`
|
|
27
|
+
and are also embedded in the binary, so installation works offline.
|
|
28
|
+
|
|
29
|
+
Full documentation: https://github.com/tomasky/serbox
|
|
30
|
+
|
|
31
|
+
License: Apache-2.0.
|
|
32
|
+
|
|
33
|
+
Environment overrides: `SERBOX_VERSION`, `SERBOX_BINARY`, `SERBOX_CACHE_DIR`,
|
|
34
|
+
`SERBOX_DOWNLOAD_BASE`, `SERBOX_REPO`, `SERBOX_NO_VERIFY`.
|
package/bin/serbox.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Launcher for the native `serbox` binary.
|
|
3
|
+
//
|
|
4
|
+
// The package ships no install script, so this is where the binary is fetched:
|
|
5
|
+
// on the first run, straight into the user cache. Arguments, stdio, signals and
|
|
6
|
+
// the exit code are all forwarded to the real binary.
|
|
7
|
+
"use strict";
|
|
8
|
+
|
|
9
|
+
const { spawn } = require("child_process");
|
|
10
|
+
const { ensureBinary } = require("../lib.js");
|
|
11
|
+
|
|
12
|
+
const SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP", "SIGQUIT"];
|
|
13
|
+
|
|
14
|
+
async function main() {
|
|
15
|
+
let binary;
|
|
16
|
+
try {
|
|
17
|
+
binary = await ensureBinary({
|
|
18
|
+
log: (line) => process.stderr.write(`${line}\n`),
|
|
19
|
+
});
|
|
20
|
+
} catch (err) {
|
|
21
|
+
process.stderr.write(`serbox: ${err.message}\n`);
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const child = spawn(binary, process.argv.slice(2), { stdio: "inherit" });
|
|
26
|
+
|
|
27
|
+
// Forward signals so Ctrl-C reaches the box-facing CLI rather than killing
|
|
28
|
+
// only the wrapper and orphaning the child.
|
|
29
|
+
for (const signal of SIGNALS) {
|
|
30
|
+
process.on(signal, () => {
|
|
31
|
+
try {
|
|
32
|
+
child.kill(signal);
|
|
33
|
+
} catch {
|
|
34
|
+
/* already gone */
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
child.on("error", (err) => {
|
|
40
|
+
process.stderr.write(`serbox: failed to launch ${binary}: ${err.message}\n`);
|
|
41
|
+
process.exit(1);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
child.on("exit", (code, signal) => {
|
|
45
|
+
if (signal) {
|
|
46
|
+
// Mirror the child's death by signal instead of inventing an exit code.
|
|
47
|
+
process.removeAllListeners(signal);
|
|
48
|
+
process.kill(process.pid, signal);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
process.exit(code === null ? 1 : code);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
main().catch((err) => {
|
|
56
|
+
process.stderr.write(`serbox: ${err && err.stack ? err.stack : err}\n`);
|
|
57
|
+
process.exit(1);
|
|
58
|
+
});
|
package/lib.js
ADDED
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// Shared logic for the npm launcher: work out which prebuilt `serbox` binary
|
|
4
|
+
// belongs on this machine, and fetch it from GitHub Releases on demand.
|
|
5
|
+
//
|
|
6
|
+
// serbox deliberately ships **no install script**. As of npm 12 dependency
|
|
7
|
+
// lifecycle scripts are blocked unless the user opts in, and pnpm 12 fails a
|
|
8
|
+
// *project* install outright with ERR_PNPM_IGNORED_BUILDS when a dependency
|
|
9
|
+
// declares one. Downloading on first run works under every package manager,
|
|
10
|
+
// under `--ignore-scripts`, and under `npx`, so that is what this does.
|
|
11
|
+
//
|
|
12
|
+
// Overrides (all optional):
|
|
13
|
+
// SERBOX_REPO owner/repo (default: tomasky/serbox)
|
|
14
|
+
// SERBOX_VERSION release version (default: this package's version)
|
|
15
|
+
// SERBOX_DOWNLOAD_BASE full base URL (overrides SERBOX_REPO/SERBOX_VERSION)
|
|
16
|
+
// SERBOX_CACHE_DIR where the binary is kept
|
|
17
|
+
// SERBOX_BINARY run this binary and never download
|
|
18
|
+
// SERBOX_FORCE_DOWNLOAD re-download even if the binary is already present
|
|
19
|
+
// SERBOX_SKIP_DOWNLOAD never download; fail if the binary is absent
|
|
20
|
+
// SERBOX_NO_VERIFY skip SHA-256 verification
|
|
21
|
+
|
|
22
|
+
const crypto = require("crypto");
|
|
23
|
+
const fs = require("fs");
|
|
24
|
+
const os = require("os");
|
|
25
|
+
const path = require("path");
|
|
26
|
+
const https = require("https");
|
|
27
|
+
const http = require("http");
|
|
28
|
+
|
|
29
|
+
const pkg = require("./package.json");
|
|
30
|
+
|
|
31
|
+
// Node's `platform-arch` -> the release target name. serbox runs on the server
|
|
32
|
+
// that owns the boxes, which in practice means Linux; a macOS or Windows host
|
|
33
|
+
// should install a Linux VM or use Docker Desktop's Linux engine.
|
|
34
|
+
const TARGETS = {
|
|
35
|
+
"linux-x64": "linux-x86_64",
|
|
36
|
+
"linux-arm64": "linux-aarch64",
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const SUPPORTED = "linux-x86_64 and linux-aarch64";
|
|
40
|
+
|
|
41
|
+
function targetName() {
|
|
42
|
+
return TARGETS[`${process.platform}-${process.arch}`];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function repoSlug() {
|
|
46
|
+
if (process.env.SERBOX_REPO) return process.env.SERBOX_REPO;
|
|
47
|
+
const url =
|
|
48
|
+
typeof pkg.repository === "string"
|
|
49
|
+
? pkg.repository
|
|
50
|
+
: (pkg.repository && pkg.repository.url) || "";
|
|
51
|
+
const m = url.match(/github\.com[/:]([^/]+)\/([^/.]+)/);
|
|
52
|
+
return m ? `${m[1]}/${m[2]}` : "tomasky/serbox";
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function version() {
|
|
56
|
+
return (process.env.SERBOX_VERSION || pkg.version).replace(/^v/, "");
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function assetName(target) {
|
|
60
|
+
return `serbox-${target}`;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Both URLs are tried in order: the pinned version first, then whatever is
|
|
64
|
+
// latest. The fallback keeps the launcher useful when a release was re-cut
|
|
65
|
+
// under a different tag, or when package.json was bumped ahead of the tag.
|
|
66
|
+
function downloadUrls(target) {
|
|
67
|
+
const asset = assetName(target);
|
|
68
|
+
if (process.env.SERBOX_DOWNLOAD_BASE) {
|
|
69
|
+
const base = process.env.SERBOX_DOWNLOAD_BASE.replace(/\/+$/, "");
|
|
70
|
+
return [`${base}/${asset}`];
|
|
71
|
+
}
|
|
72
|
+
const repo = repoSlug();
|
|
73
|
+
return [
|
|
74
|
+
`https://github.com/${repo}/releases/download/v${version()}/${asset}`,
|
|
75
|
+
`https://github.com/${repo}/releases/latest/download/${asset}`,
|
|
76
|
+
];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function cacheDir() {
|
|
80
|
+
if (process.env.SERBOX_CACHE_DIR) return process.env.SERBOX_CACHE_DIR;
|
|
81
|
+
const home = os.homedir();
|
|
82
|
+
const base = process.env.XDG_CACHE_HOME || path.join(home, ".cache");
|
|
83
|
+
return path.join(base, "serbox");
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function binaryPath(target) {
|
|
87
|
+
return path.join(cacheDir(), `serbox-${version()}-${target}`);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function isRunnable(file) {
|
|
91
|
+
try {
|
|
92
|
+
fs.accessSync(file, fs.constants.X_OK);
|
|
93
|
+
return true;
|
|
94
|
+
} catch {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// --- HTTP ------------------------------------------------------------------
|
|
100
|
+
|
|
101
|
+
function fetch(url, redirects) {
|
|
102
|
+
return new Promise((resolve, reject) => {
|
|
103
|
+
if (redirects > 10) {
|
|
104
|
+
reject(new Error("too many redirects"));
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const client = url.startsWith("http:") ? http : https;
|
|
108
|
+
const req = client.get(
|
|
109
|
+
url,
|
|
110
|
+
{ headers: { "user-agent": `serbox-npm/${pkg.version}` } },
|
|
111
|
+
(res) => {
|
|
112
|
+
const { statusCode, headers } = res;
|
|
113
|
+
if (statusCode >= 300 && statusCode < 400 && headers.location) {
|
|
114
|
+
res.resume();
|
|
115
|
+
resolve(fetch(new URL(headers.location, url).toString(), redirects + 1));
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (statusCode !== 200) {
|
|
119
|
+
res.resume();
|
|
120
|
+
const err = new Error(`GET ${url} -> HTTP ${statusCode}`);
|
|
121
|
+
err.statusCode = statusCode;
|
|
122
|
+
reject(err);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
resolve(res);
|
|
126
|
+
}
|
|
127
|
+
);
|
|
128
|
+
req.on("error", reject);
|
|
129
|
+
req.setTimeout(120000, () => req.destroy(new Error(`timed out fetching ${url}`)));
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async function fetchBuffer(url) {
|
|
134
|
+
const res = await fetch(url, 0);
|
|
135
|
+
const chunks = [];
|
|
136
|
+
for await (const chunk of res) chunks.push(chunk);
|
|
137
|
+
return Buffer.concat(chunks);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
async function fetchText(url) {
|
|
141
|
+
return (await fetchBuffer(url)).toString("utf8");
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// --- install ---------------------------------------------------------------
|
|
145
|
+
|
|
146
|
+
// Download to a sibling temp file and rename into place, so a crashed or
|
|
147
|
+
// concurrent run can never leave a half-written binary at `dest`.
|
|
148
|
+
async function downloadTo(url, dest) {
|
|
149
|
+
const res = await fetch(url, 0);
|
|
150
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
151
|
+
const tmp = `${dest}.${process.pid}.${Date.now()}.part`;
|
|
152
|
+
try {
|
|
153
|
+
await new Promise((resolve, reject) => {
|
|
154
|
+
const out = fs.createWriteStream(tmp, { mode: 0o755 });
|
|
155
|
+
res.pipe(out);
|
|
156
|
+
out.on("finish", () => out.close(resolve));
|
|
157
|
+
out.on("error", reject);
|
|
158
|
+
res.on("error", reject);
|
|
159
|
+
});
|
|
160
|
+
const size = fs.statSync(tmp).size;
|
|
161
|
+
if (size === 0) throw new Error(`${url} returned an empty file`);
|
|
162
|
+
fs.chmodSync(tmp, 0o755);
|
|
163
|
+
fs.renameSync(tmp, dest);
|
|
164
|
+
} catch (err) {
|
|
165
|
+
fs.rmSync(tmp, { force: true });
|
|
166
|
+
throw err;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Verify against the `<asset>.sha256` published next to the binary. A missing
|
|
171
|
+
// checksum is a warning, not a failure, so older releases keep working.
|
|
172
|
+
async function verify(dest, url, log) {
|
|
173
|
+
if (process.env.SERBOX_NO_VERIFY) return;
|
|
174
|
+
let published;
|
|
175
|
+
try {
|
|
176
|
+
published = (await fetchText(`${url}.sha256`)).trim();
|
|
177
|
+
} catch {
|
|
178
|
+
log(`serbox: warning: no checksum published for ${path.basename(url)}`);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
const expected = (published.split(/\s+/)[0] || "").toLowerCase();
|
|
182
|
+
if (!/^[0-9a-f]{64}$/.test(expected)) {
|
|
183
|
+
log("serbox: warning: published checksum is not a SHA-256 digest");
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
const actual = crypto.createHash("sha256").update(fs.readFileSync(dest)).digest("hex");
|
|
187
|
+
if (actual !== expected) {
|
|
188
|
+
fs.rmSync(dest, { force: true });
|
|
189
|
+
throw new Error(
|
|
190
|
+
`checksum mismatch for ${path.basename(url)}\n` +
|
|
191
|
+
` expected ${expected}\n actual ${actual}`
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Resolve to a runnable `serbox` binary, downloading it when it is missing.
|
|
198
|
+
*/
|
|
199
|
+
async function ensureBinary({ force = false, log = () => {} } = {}) {
|
|
200
|
+
if (process.env.SERBOX_BINARY) {
|
|
201
|
+
if (!fs.existsSync(process.env.SERBOX_BINARY)) {
|
|
202
|
+
throw new Error(
|
|
203
|
+
`SERBOX_BINARY points at ${process.env.SERBOX_BINARY}, which does not exist`
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
return process.env.SERBOX_BINARY;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const target = targetName();
|
|
210
|
+
if (!target) {
|
|
211
|
+
throw new Error(
|
|
212
|
+
`serbox does not ship a binary for ${process.platform}/${process.arch}; ` +
|
|
213
|
+
`supported: ${SUPPORTED}. Build from source instead: ` +
|
|
214
|
+
`https://github.com/${repoSlug()}#build-from-source`
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const dest = binaryPath(target);
|
|
219
|
+
const wanted = force || process.env.SERBOX_FORCE_DOWNLOAD;
|
|
220
|
+
if (!wanted && isRunnable(dest)) return dest;
|
|
221
|
+
|
|
222
|
+
if (process.env.SERBOX_SKIP_DOWNLOAD) {
|
|
223
|
+
if (isRunnable(dest)) return dest;
|
|
224
|
+
throw new Error(
|
|
225
|
+
`SERBOX_SKIP_DOWNLOAD is set but no serbox binary is installed at ${dest}`
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const urls = downloadUrls(target);
|
|
230
|
+
let lastError;
|
|
231
|
+
for (const url of urls) {
|
|
232
|
+
try {
|
|
233
|
+
log(`serbox: downloading ${url}`);
|
|
234
|
+
await downloadTo(url, dest);
|
|
235
|
+
await verify(dest, url, log);
|
|
236
|
+
log(`serbox: installed ${dest}`);
|
|
237
|
+
return dest;
|
|
238
|
+
} catch (err) {
|
|
239
|
+
lastError = err;
|
|
240
|
+
log(`serbox: ${err.message}`);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
throw new Error(
|
|
245
|
+
`could not download the serbox binary for ${target}.\n` +
|
|
246
|
+
`Tried:\n${urls.map((u) => ` ${u}`).join("\n")}\n` +
|
|
247
|
+
`Last error: ${lastError && lastError.message}\n\n` +
|
|
248
|
+
`Install it another way instead:\n` +
|
|
249
|
+
` curl -LsSf https://raw.githubusercontent.com/${repoSlug()}/main/install.sh | bash\n` +
|
|
250
|
+
`or set SERBOX_DOWNLOAD_BASE to a mirror.`
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
module.exports = {
|
|
255
|
+
pkg,
|
|
256
|
+
TARGETS,
|
|
257
|
+
SUPPORTED,
|
|
258
|
+
targetName,
|
|
259
|
+
repoSlug,
|
|
260
|
+
version,
|
|
261
|
+
assetName,
|
|
262
|
+
downloadUrls,
|
|
263
|
+
cacheDir,
|
|
264
|
+
binaryPath,
|
|
265
|
+
isRunnable,
|
|
266
|
+
ensureBinary,
|
|
267
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tomasko/serbox",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.3",
|
|
4
|
+
"description": "Linux boxes for agents, on your own server: create, exec, copy, snapshot and forward ports into isolated Docker boxes, with no account and no API key.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"bin": {
|
|
7
|
+
"serbox": "bin/serbox.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"bin/serbox.js",
|
|
11
|
+
"lib.js",
|
|
12
|
+
"README.md",
|
|
13
|
+
"skills"
|
|
14
|
+
],
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=18"
|
|
17
|
+
},
|
|
18
|
+
"os": [
|
|
19
|
+
"linux"
|
|
20
|
+
],
|
|
21
|
+
"cpu": [
|
|
22
|
+
"x64",
|
|
23
|
+
"arm64"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"test": "node --test",
|
|
27
|
+
"prepack": "node scripts/copy-skills.js"
|
|
28
|
+
},
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "https://github.com/tomasky/serbox.git"
|
|
32
|
+
},
|
|
33
|
+
"homepage": "https://github.com/tomasky/serbox",
|
|
34
|
+
"bugs": "https://github.com/tomasky/serbox/issues",
|
|
35
|
+
"keywords": [
|
|
36
|
+
"serbox",
|
|
37
|
+
"instabox",
|
|
38
|
+
"sandbox",
|
|
39
|
+
"boxes",
|
|
40
|
+
"docker",
|
|
41
|
+
"agents",
|
|
42
|
+
"disposable",
|
|
43
|
+
"devcontainer",
|
|
44
|
+
"moonbit",
|
|
45
|
+
"cli"
|
|
46
|
+
],
|
|
47
|
+
"preferGlobal": true
|
|
48
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: serbox
|
|
3
|
+
description: Use when the user wants an isolated Linux box on this server with the `serbox` CLI - create, exec or shell into, copy files, run background jobs, publish a port, save or restore a snapshot, pause and resume, set secrets, use a remote server, or delete the box.
|
|
4
|
+
metadata:
|
|
5
|
+
installed-by: serbox
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# serbox CLI
|
|
9
|
+
|
|
10
|
+
`serbox` runs disposable Linux boxes as containers on the machine where it is
|
|
11
|
+
installed. There is no account and no hosted service: `serbox` talks to the
|
|
12
|
+
local Docker or Podman engine, keeps its state under `~/.serbox` (override with
|
|
13
|
+
`SERBOX_HOME`), and works the same on any Linux server. Set
|
|
14
|
+
`SERBOX_RUNTIME=podman` to use Podman; otherwise Docker is preferred and Podman
|
|
15
|
+
is the fallback.
|
|
16
|
+
|
|
17
|
+
A box has a writable root filesystem and a persistent `/data` disk. `HOME` is
|
|
18
|
+
`/data/home`, so files under `/data` survive pause, resume, snapshot and fork.
|
|
19
|
+
Each box is its own container; processes, installed packages and files stay
|
|
20
|
+
inside it. Everything the CLI prints is meant for an agent: add `--json` for a
|
|
21
|
+
machine-readable document.
|
|
22
|
+
|
|
23
|
+
Safety rules to state before acting:
|
|
24
|
+
|
|
25
|
+
- `serbox rm NAME` deletes the container and its `/data`. Save a snapshot
|
|
26
|
+
first if the box matters.
|
|
27
|
+
- `serbox port publish` exposes a container port on this host. Anyone who can
|
|
28
|
+
reach the host and port can use it; use `--private` to bind loopback only.
|
|
29
|
+
- Secrets are plain environment variables inside the box; code running there
|
|
30
|
+
can read them.
|
|
31
|
+
|
|
32
|
+
## Create and inspect
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
serbox create --name work --template alpine # fast, small
|
|
36
|
+
serbox create --name work --template ubuntu --publish 3000 --secrets TOKEN
|
|
37
|
+
serbox ls # state, template, age
|
|
38
|
+
serbox get work --json # one box as JSON
|
|
39
|
+
serbox templates # known image aliases
|
|
40
|
+
serbox doctor # runtime and state checks
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
`create` waits until the box accepts commands unless `--no-wait` is given.
|
|
44
|
+
`--setup-file PATH` runs a script after creation; `--env K=V`, `--secrets NAME`,
|
|
45
|
+
`--publish PORT` and `--auto-suspend 30m` are also accepted. Names are
|
|
46
|
+
lowercase letters, digits and `-`, at most 63 characters.
|
|
47
|
+
|
|
48
|
+
## Run commands
|
|
49
|
+
|
|
50
|
+
```sh
|
|
51
|
+
serbox exec work -- uname -a # exact argv
|
|
52
|
+
serbox exec work -- 'apt-get update && apt-get install -y git' # one string: shell
|
|
53
|
+
serbox exec work --stdin -- 'cat > /data/note' # pipe stdin
|
|
54
|
+
serbox exec work --timeout 120 -- ./build.sh # 1..600 seconds
|
|
55
|
+
serbox exec work --json -- 'echo hi' # stdout, stderr, exitCode
|
|
56
|
+
serbox shell work # interactive shell
|
|
57
|
+
serbox ssh work # same, for muscle memory
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Exit codes are the command's own; 124 means `--timeout` expired, 130 means
|
|
61
|
+
interrupted. Use `--workdir DIR` and `--env K=V` for one command.
|
|
62
|
+
|
|
63
|
+
## Files and secrets
|
|
64
|
+
|
|
65
|
+
```sh
|
|
66
|
+
serbox push work ./src /data/home/src # local -> box
|
|
67
|
+
serbox pull work /data/home/src ./src # box -> local
|
|
68
|
+
serbox files work /data/home # list
|
|
69
|
+
serbox cp work:/data/home/a.txt ./a.txt # either direction
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
`cp` accepts `BOX:/path` on one side and a local path on the other.
|
|
73
|
+
|
|
74
|
+
```sh
|
|
75
|
+
printf '%s' "$TOKEN" | serbox secrets set GITHUB_TOKEN
|
|
76
|
+
serbox secrets ls # names only, never values
|
|
77
|
+
serbox secrets push work # /data/.serbox/secrets.env, mode 0600
|
|
78
|
+
serbox create --name work2 --secrets GITHUB_TOKEN
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Never echo a secret value into logs or commit it. To use a secret in a later
|
|
82
|
+
`exec`, pass `--env NAME` (it reads the stored value) or source
|
|
83
|
+
`/data/.serbox/secrets.env` inside the box.
|
|
84
|
+
|
|
85
|
+
## Background jobs
|
|
86
|
+
|
|
87
|
+
```sh
|
|
88
|
+
serbox exec work --background -- 'make test > /data/test.log 2>&1'
|
|
89
|
+
serbox jobs ls work
|
|
90
|
+
serbox jobs logs work JOB_ID --follow
|
|
91
|
+
serbox jobs wait work JOB_ID --timeout 600
|
|
92
|
+
serbox jobs kill work JOB_ID --signal TERM
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
`--background` prints the job id. Jobs keep running inside the box after the
|
|
96
|
+
CLI exits; `jobs wait` returns the job's exit code.
|
|
97
|
+
|
|
98
|
+
## Ports
|
|
99
|
+
|
|
100
|
+
```sh
|
|
101
|
+
serbox port publish work 3000 # host picks a free port
|
|
102
|
+
serbox port publish work 3000 --host 8080 --private
|
|
103
|
+
serbox port ls
|
|
104
|
+
serbox port unpublish work 3000
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
A forwarder runs on the host and connects to the container address. It stops
|
|
108
|
+
when the box is removed or the port is unpublished.
|
|
109
|
+
|
|
110
|
+
## Pause, snapshot, remove
|
|
111
|
+
|
|
112
|
+
```sh
|
|
113
|
+
serbox suspend work # processes stop, disks stay
|
|
114
|
+
serbox resume work
|
|
115
|
+
serbox stop work # stop the container
|
|
116
|
+
serbox start work
|
|
117
|
+
serbox snapshot save work --name work-ready
|
|
118
|
+
serbox snapshot ls
|
|
119
|
+
serbox fork work --name work2 --count 2
|
|
120
|
+
serbox rename work work-old
|
|
121
|
+
serbox rm work --yes
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
`fork` copies the box's disks; `snapshot restore` copies a snapshot into an
|
|
125
|
+
existing box (its current `/data` is replaced). `--root-only` is not
|
|
126
|
+
implemented: serbox snapshots always include `/data`.
|
|
127
|
+
|
|
128
|
+
See the `serbox-snapshots` skill for the full snapshot workflow, and
|
|
129
|
+
`serbox-move-repo` / `serbox-basic-setup` for moving a repository or dotfiles
|
|
130
|
+
into a box.
|
|
131
|
+
|
|
132
|
+
## Remote servers
|
|
133
|
+
|
|
134
|
+
```sh
|
|
135
|
+
serbox host add prod me@server.example.com --install # installs and tunnels
|
|
136
|
+
serbox host use prod # current server
|
|
137
|
+
serbox create --name work # runs on prod
|
|
138
|
+
serbox exec work -- uptime # through the ssh tunnel
|
|
139
|
+
serbox -H prod ls # one-off override
|
|
140
|
+
serbox host ls
|
|
141
|
+
serbox host current
|
|
142
|
+
serbox host rm prod
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Hosts added with `--address 127.0.0.1:7373 --token T` skip ssh and talk to a
|
|
146
|
+
daemon reached some other way. On the server, `serbox serve` runs the daemon;
|
|
147
|
+
it listens on loopback and keeps its token in `~/.serbox/serve-token`. Rotate it
|
|
148
|
+
with `serbox serve --rotate-token`, and re-authorize a client with
|
|
149
|
+
`serbox host add NAME USER@HOST --force`.
|
|
150
|
+
|
|
151
|
+
`push`, `pull` and `cp` need an ssh-added host: the remote daemon cannot read
|
|
152
|
+
your local disk. Run interactive shells with `serbox shell`; it uses `ssh -t`.
|
|
153
|
+
|
|
154
|
+
## Housekeeping
|
|
155
|
+
|
|
156
|
+
```sh
|
|
157
|
+
serbox usage
|
|
158
|
+
serbox gc --max-age 7d --max-run 8h --dry-run
|
|
159
|
+
serbox logs work --tail 100
|
|
160
|
+
serbox metrics work
|
|
161
|
+
serbox history
|
|
162
|
+
serbox completion bash
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
`gc` reaps boxes with `--delete-after`, runs due setup files and auto-suspends
|
|
166
|
+
idle boxes. `--max-run 0` disables the limit.
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: serbox-basic-setup
|
|
3
|
+
description: Use when the user wants a serbox box set up like their machine - "put my tokens, git config and editor config in the box", "set up my box like my laptop", "move my dotfiles to serbox". Stores credentials as serbox secrets and copies approved git/editor config; moves no repository code (use serbox-move-repo for that).
|
|
4
|
+
metadata:
|
|
5
|
+
installed-by: serbox
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Set up a serbox box like the user's machine
|
|
9
|
+
|
|
10
|
+
This skill has two separate parts. Credentials become serbox **secrets**;
|
|
11
|
+
ordinary configuration files are **copied** into the box. Keeping them separate
|
|
12
|
+
means a token is never written into a dotfile the user might share, and a
|
|
13
|
+
`.vimrc` is never mistaken for a secret.
|
|
14
|
+
|
|
15
|
+
Nothing here invents values. The scripts list names and sizes only; the user
|
|
16
|
+
approves what moves, and secret values are read with a hidden prompt (or piped
|
|
17
|
+
from the user's own command) and never printed.
|
|
18
|
+
|
|
19
|
+
Paths assume this skill is installed at `~/.agents/skills/serbox-basic-setup`;
|
|
20
|
+
adjust `S` if needed.
|
|
21
|
+
|
|
22
|
+
## 1. Inventory (read-only)
|
|
23
|
+
|
|
24
|
+
```sh
|
|
25
|
+
set -euo pipefail
|
|
26
|
+
S="$HOME/.agents/skills/serbox-basic-setup/scripts"
|
|
27
|
+
BOX="${BOX:-work}"
|
|
28
|
+
node "$S/scan.mjs" --json
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
The report contains:
|
|
32
|
+
|
|
33
|
+
- `files`: known git and editor config that exists, with `path`, `size` and
|
|
34
|
+
`symlink` (symlinks are reported but never copied).
|
|
35
|
+
- `env`: **names** of environment variables that look like credentials
|
|
36
|
+
(`*TOKEN*`, `*KEY*`, `*SECRET*`, `*PASSWORD*`, ...). No values.
|
|
37
|
+
- `suggested`: one line per group.
|
|
38
|
+
|
|
39
|
+
Show the user the names and let them choose. Do not read or echo the values.
|
|
40
|
+
|
|
41
|
+
## 2. Store credentials as secrets
|
|
42
|
+
|
|
43
|
+
Prefer a hidden prompt; the value never appears in shell history or logs:
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
read -r -s -p "Value for GITHUB_TOKEN: " VALUE; echo
|
|
47
|
+
printf '%s' "$VALUE" | serbox secrets set GITHUB_TOKEN
|
|
48
|
+
unset VALUE
|
|
49
|
+
serbox secrets ls # names only
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
If the user already has the value in an environment variable, pipe it without
|
|
53
|
+
printing it:
|
|
54
|
+
|
|
55
|
+
```sh
|
|
56
|
+
printf '%s' "${GITHUB_TOKEN:?not set}" | serbox secrets set GITHUB_TOKEN
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Apply secrets to boxes:
|
|
60
|
+
|
|
61
|
+
```sh
|
|
62
|
+
serbox create --name "$BOX" --secrets GITHUB_TOKEN,OPENAI_API_KEY
|
|
63
|
+
serbox secrets push "$BOX" # /data/.serbox/secrets.env, mode 0600
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
A box only receives a secret at `create` time when it is named in `--secrets`,
|
|
67
|
+
or later through `secrets push`. Adding a secret to the store does not change a
|
|
68
|
+
box that is already running. To use the pushed file:
|
|
69
|
+
|
|
70
|
+
```sh
|
|
71
|
+
serbox exec "$BOX" -- 'set -a; . /data/.serbox/secrets.env; set +a; env | grep -c TOKEN'
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
The last command prints a count, not values.
|
|
75
|
+
|
|
76
|
+
## 3. Copy config files
|
|
77
|
+
|
|
78
|
+
Start with the files the user approved:
|
|
79
|
+
|
|
80
|
+
```sh
|
|
81
|
+
bash "$S/copy.sh" "$BOX" --dry-run \
|
|
82
|
+
.gitconfig .config/git/config .vimrc .tmux.conf .bash_aliases
|
|
83
|
+
bash "$S/copy.sh" "$BOX" \
|
|
84
|
+
.gitconfig .config/git/config .vimrc .tmux.conf .bash_aliases
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
`copy.sh` refuses symlinks, creates parent directories, copies through
|
|
88
|
+
`serbox push` and sets mode `0600` on the copied files. Without a file list it
|
|
89
|
+
copies the existing defaults from the scan. It does not copy directories
|
|
90
|
+
wholesale: nvim plugin checkouts and caches are deliberately excluded.
|
|
91
|
+
|
|
92
|
+
Verify:
|
|
93
|
+
|
|
94
|
+
```sh
|
|
95
|
+
serbox exec "$BOX" -- 'git config --global user.name; git config --global user.email'
|
|
96
|
+
serbox exec "$BOX" -- 'test -f /data/home/.vimrc && echo vimrc-ok'
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## 4. Tell the user what still needs a manual step
|
|
100
|
+
|
|
101
|
+
- Git push/pull needs an SSH key or token inside the box. A `.gitconfig` alone
|
|
102
|
+
does not authenticate. For HTTPS, a credential helper or a token in the
|
|
103
|
+
remote URL is required; for SSH, generate a key in the box and add it to the
|
|
104
|
+
user's account. Never copy the host's private keys unless the user explicitly
|
|
105
|
+
asks and understands the risk.
|
|
106
|
+
- Secrets in the environment are visible to every process in the box. A
|
|
107
|
+
compromised dependency can read them.
|
|
108
|
+
- `serbox rm BOX` destroys the box's `/data`; snapshots saved earlier remain.
|
|
109
|
+
- Config copied now is a snapshot in time. The local machine and the box do not
|
|
110
|
+
stay in sync.
|
|
111
|
+
|
|
112
|
+
## Security rules
|
|
113
|
+
|
|
114
|
+
- Never print a secret value, a credential-bearing config file, or the output of
|
|
115
|
+
`env`/`printenv` that may contain secrets.
|
|
116
|
+
- Do not copy `.ssh` private keys, cloud credential files (`.aws/credentials`,
|
|
117
|
+
`.config/gcloud/...`), browser profiles or keychains by default. Name them to
|
|
118
|
+
the user and require explicit approval; prefer creating fresh credentials in
|
|
119
|
+
the box.
|
|
120
|
+
- Do not paste tokens into a command line where `ps` can see them. Use stdin as
|
|
121
|
+
shown above.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Copy approved config files into a serbox box.
|
|
3
|
+
# usage: copy.sh BOX [--dry-run] [FILE...] (paths are relative to $HOME)
|
|
4
|
+
set -euo pipefail
|
|
5
|
+
box="${1:?usage: copy.sh BOX [--dry-run] [FILE...]}"
|
|
6
|
+
shift
|
|
7
|
+
dry=0
|
|
8
|
+
files=()
|
|
9
|
+
for arg in "$@"; do
|
|
10
|
+
case "$arg" in
|
|
11
|
+
--dry-run) dry=1 ;;
|
|
12
|
+
-h|--help) sed -n '2,3p' "$0"; exit 0 ;;
|
|
13
|
+
-*) echo "copy.sh: unknown option $arg" >&2; exit 2 ;;
|
|
14
|
+
*) files+=("$arg") ;;
|
|
15
|
+
esac
|
|
16
|
+
done
|
|
17
|
+
if [ ${#files[@]} -eq 0 ]; then
|
|
18
|
+
files=(.gitconfig .config/git/config .vimrc .tmux.conf .bash_aliases .zshrc)
|
|
19
|
+
fi
|
|
20
|
+
|
|
21
|
+
for rel in "${files[@]}"; do
|
|
22
|
+
case "$rel" in
|
|
23
|
+
/*|*..*) echo "copy.sh: unsafe path $rel" >&2; exit 2 ;;
|
|
24
|
+
esac
|
|
25
|
+
src="$HOME/$rel"
|
|
26
|
+
if [ -L "$src" ]; then
|
|
27
|
+
echo "skip $rel (symlink)" >&2
|
|
28
|
+
continue
|
|
29
|
+
fi
|
|
30
|
+
if [ ! -f "$src" ]; then
|
|
31
|
+
echo "skip $rel (not a regular file)" >&2
|
|
32
|
+
continue
|
|
33
|
+
fi
|
|
34
|
+
dest="/data/home/$rel"
|
|
35
|
+
if [ "$dry" = 1 ]; then
|
|
36
|
+
echo "would copy $rel -> $box:$dest"
|
|
37
|
+
continue
|
|
38
|
+
fi
|
|
39
|
+
serbox exec "$box" -- "mkdir -p '$(dirname "$dest")'"
|
|
40
|
+
serbox push "$box" "$src" "$dest" >/dev/null
|
|
41
|
+
serbox exec "$box" -- "chmod 600 '$dest'"
|
|
42
|
+
echo "copied $rel"
|
|
43
|
+
done
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Read-only inventory for serbox-basic-setup. Names and sizes only.
|
|
3
|
+
import { existsSync, lstatSync } from 'node:fs';
|
|
4
|
+
import { homedir } from 'node:os';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
|
|
7
|
+
const DEFAULT_FILES = [
|
|
8
|
+
'.gitconfig',
|
|
9
|
+
'.config/git/config',
|
|
10
|
+
'.gitignore_global',
|
|
11
|
+
'.vimrc',
|
|
12
|
+
'.config/nvim/init.vim',
|
|
13
|
+
'.config/nvim/init.lua',
|
|
14
|
+
'.tmux.conf',
|
|
15
|
+
'.bashrc',
|
|
16
|
+
'.bash_aliases',
|
|
17
|
+
'.zshrc',
|
|
18
|
+
'.inputrc',
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
const CREDENTIAL = /(TOKEN|SECRET|PASSWORD|PASSWD|API[_-]?KEY|ACCESS[_-]?KEY|PRIVATE[_-]?KEY|CREDENTIAL)/i;
|
|
22
|
+
|
|
23
|
+
const args = process.argv.slice(2);
|
|
24
|
+
if (args.includes('-h') || args.includes('--help')) {
|
|
25
|
+
process.stdout.write('usage: scan.mjs [--json]\n');
|
|
26
|
+
process.exit(0);
|
|
27
|
+
}
|
|
28
|
+
if (args.some((a) => a !== '--json')) {
|
|
29
|
+
process.stderr.write('scan.mjs: unknown argument\n');
|
|
30
|
+
process.exit(2);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const home = homedir();
|
|
34
|
+
const files = [];
|
|
35
|
+
for (const rel of DEFAULT_FILES) {
|
|
36
|
+
const full = join(home, rel);
|
|
37
|
+
if (!existsSync(full)) continue;
|
|
38
|
+
let stat;
|
|
39
|
+
try {
|
|
40
|
+
stat = lstatSync(full);
|
|
41
|
+
} catch {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
files.push({
|
|
45
|
+
path: rel,
|
|
46
|
+
size: stat.isSymbolicLink() ? 0 : stat.size,
|
|
47
|
+
symlink: stat.isSymbolicLink(),
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const env = Object.keys(process.env)
|
|
52
|
+
.filter((name) => CREDENTIAL.test(name))
|
|
53
|
+
.sort();
|
|
54
|
+
|
|
55
|
+
const report = {
|
|
56
|
+
home,
|
|
57
|
+
files,
|
|
58
|
+
env,
|
|
59
|
+
suggested: [
|
|
60
|
+
files.length
|
|
61
|
+
? `copy ${files.filter((f) => !f.symlink).length} config file(s) with copy.sh`
|
|
62
|
+
: 'no known config files found',
|
|
63
|
+
env.length
|
|
64
|
+
? `store ${env.length} credential name(s) with serbox secrets set NAME`
|
|
65
|
+
: 'no credential-like environment variables found',
|
|
66
|
+
],
|
|
67
|
+
};
|
|
68
|
+
process.stdout.write(JSON.stringify(report, null, 2) + '\n');
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: serbox-move-repo
|
|
3
|
+
description: Use when the user wants to move the repository they are working in into a serbox box - "move this repo to a box", "continue this work in the box", "copy my project into serbox". Copies the checkout, its worktrees, uncommitted and stashed work, then installs dependencies inside the box.
|
|
4
|
+
metadata:
|
|
5
|
+
installed-by: serbox
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Move a local repository into a serbox box
|
|
9
|
+
|
|
10
|
+
This moves the git checkout of the current directory into one box and leaves
|
|
11
|
+
the local copy untouched. After it finishes the box has the same HEAD, index,
|
|
12
|
+
branches, stashes and worktrees, plus untracked files that git does not ignore.
|
|
13
|
+
Conversation history from agent tools is **not** copied; this skill only moves
|
|
14
|
+
the repository.
|
|
15
|
+
|
|
16
|
+
Paths in the examples assume this skill is installed at
|
|
17
|
+
`~/.agents/skills/serbox-move-repo` (or `~/.claude/skills/...`); adjust `S` if
|
|
18
|
+
yours is elsewhere.
|
|
19
|
+
|
|
20
|
+
Prerequisites: `git`, `tar`, `node` (for the file plan) and a working `serbox`
|
|
21
|
+
box. Run the steps in one shell session so `S`, `ROOT`, `BOX` and `DEST` stay
|
|
22
|
+
set.
|
|
23
|
+
|
|
24
|
+
## 1. Pick the box and destination
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
set -euo pipefail
|
|
28
|
+
S="$HOME/.agents/skills/serbox-move-repo/scripts"
|
|
29
|
+
ROOT="$(git rev-parse --show-toplevel)"
|
|
30
|
+
BOX="${BOX:-work}"
|
|
31
|
+
DEST="${DEST:-/data/home/$(basename "$ROOT")}"
|
|
32
|
+
serbox get "$BOX" >/dev/null || serbox create --name "$BOX" --template alpine
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
If the box does not exist, create it with the template the project needs
|
|
36
|
+
(`ubuntu`, `node`, `python`, ...; see `serbox templates`). A wrong template
|
|
37
|
+
means missing runtimes later.
|
|
38
|
+
|
|
39
|
+
## 2. See the plan
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
node "$S/repo-files.mjs" --json "$ROOT"
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
The plan lists the files that will move and the size. Build output and
|
|
46
|
+
dependency directories (`node_modules`, `target`, `dist`, `.venv`, caches, ...)
|
|
47
|
+
are skipped even when they are untracked; **tracked** files are always kept so
|
|
48
|
+
`git status` matches. Use `--keep NAME` to include an excluded directory by
|
|
49
|
+
literal name (for example a source tree that really lives in `build/`).
|
|
50
|
+
|
|
51
|
+
Before moving, tell the user:
|
|
52
|
+
|
|
53
|
+
- Git push and pull will not work in the box until credentials are configured
|
|
54
|
+
there; environment secrets and git config are separate steps (see the
|
|
55
|
+
`serbox-basic-setup` skill).
|
|
56
|
+
- Copying `.git/config` copies any remote URL, including an embedded token.
|
|
57
|
+
- Untracked `.env` files that git ignores are **not** copied. Move their values
|
|
58
|
+
with `serbox secrets set`, never by printing them.
|
|
59
|
+
|
|
60
|
+
## 3. Copy the repository and its git data
|
|
61
|
+
|
|
62
|
+
```sh
|
|
63
|
+
node "$S/repo-files.mjs" --list0 "$ROOT" > /tmp/serbox-move.list
|
|
64
|
+
tar -C "$ROOT" --null -cf /tmp/serbox-move.tar -T /tmp/serbox-move.list
|
|
65
|
+
tar -C "$ROOT" -rf /tmp/serbox-move.tar .git
|
|
66
|
+
serbox push "$BOX" /tmp/serbox-move.tar /tmp/serbox-move.tar
|
|
67
|
+
serbox exec "$BOX" -- sh -c "mkdir -p '$DEST' && tar -xf /tmp/serbox-move.tar -C '$DEST' && rm /tmp/serbox-move.tar"
|
|
68
|
+
rm -f /tmp/serbox-move.list /tmp/serbox-move.tar
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
The second `tar -rf` adds `.git` (all branches, stashes, index and worktree
|
|
72
|
+
metadata) while the file list stays manageable. If the user does not want git
|
|
73
|
+
history in the box, omit that line and add `--no-git` when running
|
|
74
|
+
`move.sh` below.
|
|
75
|
+
|
|
76
|
+
## 4. Verify and install dependencies
|
|
77
|
+
|
|
78
|
+
```sh
|
|
79
|
+
serbox exec "$BOX" --workdir "$DEST" -- 'git status --short; git log -1 --oneline'
|
|
80
|
+
bash "$S/deps.sh" "$BOX" "$DEST"
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
`deps.sh` detects `package.json`, lockfiles, `Cargo.toml`, `go.mod`,
|
|
84
|
+
`requirements.txt`, `pyproject.toml` and `Gemfile`, and runs the matching
|
|
85
|
+
install command with the tool already present in the box. It does not install
|
|
86
|
+
missing runtimes; if a tool is absent, tell the user which template or package
|
|
87
|
+
to add.
|
|
88
|
+
|
|
89
|
+
## Shortcut
|
|
90
|
+
|
|
91
|
+
`move.sh` wraps steps 3 and 4:
|
|
92
|
+
|
|
93
|
+
```sh
|
|
94
|
+
bash "$S/move.sh" "$ROOT" "$BOX" # keeps .git, installs deps
|
|
95
|
+
bash "$S/move.sh" "$ROOT" "$BOX" --no-git # code only
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
The box and the local checkout are independent after the move. Nothing keeps
|
|
99
|
+
them in sync; later changes need another `push` or a git remote.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Install a moved project's dependencies inside a serbox box.
|
|
3
|
+
# usage: deps.sh BOX DIR
|
|
4
|
+
set -euo pipefail
|
|
5
|
+
box="${1:?usage: deps.sh BOX DIR}"
|
|
6
|
+
dir="${2:?usage: deps.sh BOX DIR}"
|
|
7
|
+
run() { serbox exec "$box" --workdir "$dir" -- "$@"; }
|
|
8
|
+
have() { serbox exec "$box" -- "command -v '$1' >/dev/null 2>&1"; }
|
|
9
|
+
|
|
10
|
+
if serbox exec "$box" -- "test -f '$dir/package.json'"; then
|
|
11
|
+
if serbox exec "$box" -- "test -f '$dir/pnpm-lock.yaml'"; then
|
|
12
|
+
have pnpm && run pnpm install --frozen-lockfile || echo "note: pnpm is not installed in the box"
|
|
13
|
+
elif serbox exec "$box" -- "test -f '$dir/yarn.lock'"; then
|
|
14
|
+
have yarn && run yarn install --frozen-lockfile || echo "note: yarn is not installed in the box"
|
|
15
|
+
elif serbox exec "$box" -- "test -f '$dir/package-lock.json'"; then
|
|
16
|
+
have npm && run npm ci || echo "note: npm is not installed in the box"
|
|
17
|
+
else
|
|
18
|
+
have npm && run npm install || echo "note: npm is not installed in the box"
|
|
19
|
+
fi
|
|
20
|
+
fi
|
|
21
|
+
|
|
22
|
+
if serbox exec "$box" -- "test -f '$dir/Cargo.toml'"; then
|
|
23
|
+
have cargo && run cargo fetch || echo "note: cargo is not installed in the box"
|
|
24
|
+
fi
|
|
25
|
+
if serbox exec "$box" -- "test -f '$dir/go.mod'"; then
|
|
26
|
+
have go && run go mod download || echo "note: go is not installed in the box"
|
|
27
|
+
fi
|
|
28
|
+
if serbox exec "$box" -- "test -f '$dir/requirements.txt'"; then
|
|
29
|
+
have python3 && run python3 -m pip install -r requirements.txt ||
|
|
30
|
+
echo "note: python3/pip is not installed in the box"
|
|
31
|
+
fi
|
|
32
|
+
if serbox exec "$box" -- "test -f '$dir/pyproject.toml'"; then
|
|
33
|
+
have python3 && run python3 -m pip install -e . ||
|
|
34
|
+
echo "note: python3/pip is not installed in the box"
|
|
35
|
+
fi
|
|
36
|
+
if serbox exec "$box" -- "test -f '$dir/Gemfile'"; then
|
|
37
|
+
have bundle && run bundle install || echo "note: bundler is not installed in the box"
|
|
38
|
+
fi
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Copy a git checkout into a serbox box (shortcut for the steps in SKILL.md).
|
|
3
|
+
# usage: move.sh REPO BOX [--dest PATH] [--no-git]
|
|
4
|
+
set -euo pipefail
|
|
5
|
+
root="${1:?usage: move.sh REPO BOX [--dest PATH] [--no-git]}"
|
|
6
|
+
box="${2:?usage: move.sh REPO BOX [--dest PATH] [--no-git]}"
|
|
7
|
+
shift 2
|
|
8
|
+
dest=""
|
|
9
|
+
git=1
|
|
10
|
+
while [ $# -gt 0 ]; do
|
|
11
|
+
case "$1" in
|
|
12
|
+
--dest) dest="${2:?--dest needs a path}"; shift 2 ;;
|
|
13
|
+
--no-git) git=0; shift ;;
|
|
14
|
+
-h|--help) sed -n '2,3p' "$0"; exit 0 ;;
|
|
15
|
+
*) echo "move.sh: unknown argument $1" >&2; exit 2 ;;
|
|
16
|
+
esac
|
|
17
|
+
done
|
|
18
|
+
S="$(cd "$(dirname "$0")" && pwd)"
|
|
19
|
+
root="$(git -C "$root" rev-parse --show-toplevel)"
|
|
20
|
+
[ -n "$dest" ] || dest="/data/home/$(basename "$root")"
|
|
21
|
+
work="$(mktemp -d)"
|
|
22
|
+
trap 'rm -rf "$work"' EXIT
|
|
23
|
+
|
|
24
|
+
node "$S/repo-files.mjs" --list0 "$root" > "$work/files"
|
|
25
|
+
tar -C "$root" --null -cf "$work/repo.tar" -T "$work/files"
|
|
26
|
+
if [ "$git" = 1 ]; then
|
|
27
|
+
tar -C "$root" -rf "$work/repo.tar" .git
|
|
28
|
+
fi
|
|
29
|
+
serbox push "$box" "$work/repo.tar" /tmp/serbox-move.tar >/dev/null
|
|
30
|
+
serbox exec "$box" -- sh -c "mkdir -p '$dest' && tar -xf /tmp/serbox-move.tar -C '$dest' && rm /tmp/serbox-move.tar"
|
|
31
|
+
if [ "$git" = 1 ]; then
|
|
32
|
+
serbox exec "$box" --workdir "$dest" -- 'git status --short'
|
|
33
|
+
fi
|
|
34
|
+
bash "$S/deps.sh" "$box" "$dest"
|
|
35
|
+
echo "moved $root to $box:$dest"
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Plan which files of a git checkout move into a serbox box.
|
|
3
|
+
// Prints names and sizes only; never reads file contents.
|
|
4
|
+
import { spawnSync } from 'node:child_process';
|
|
5
|
+
import { existsSync, statSync } from 'node:fs';
|
|
6
|
+
import { join, resolve } from 'node:path';
|
|
7
|
+
|
|
8
|
+
const EXCLUDED_DIRS = new Set([
|
|
9
|
+
'node_modules', 'target', 'dist', 'build', 'out', '.next', '.nuxt',
|
|
10
|
+
'.svelte-kit', '.turbo', '.cache', 'coverage', '__pycache__', '.venv',
|
|
11
|
+
'venv', '.tox', '.mypy_cache', '.pytest_cache', '.gradle', '.idea',
|
|
12
|
+
'.vscode', 'bazel-bin', 'bazel-out', 'bazel-testlogs', '.dart_tool',
|
|
13
|
+
'.terraform', '.serverless', '.parcel-cache', '.angular', '.expo',
|
|
14
|
+
]);
|
|
15
|
+
|
|
16
|
+
function usage(message) {
|
|
17
|
+
if (message) process.stderr.write(`repo-files: ${message}\n`);
|
|
18
|
+
process.stderr.write('usage: repo-files.mjs [--json|--list0] [--keep NAME] [ROOT]\n');
|
|
19
|
+
process.exit(2);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const argv = process.argv.slice(2);
|
|
23
|
+
let mode = 'json';
|
|
24
|
+
let keep = new Set();
|
|
25
|
+
let rootArg = '';
|
|
26
|
+
for (let i = 0; i < argv.length; i++) {
|
|
27
|
+
const a = argv[i];
|
|
28
|
+
if (a === '--json') mode = 'json';
|
|
29
|
+
else if (a === '--list0') mode = 'list0';
|
|
30
|
+
else if (a === '--keep') {
|
|
31
|
+
if (i + 1 >= argv.length) usage('--keep needs a name');
|
|
32
|
+
keep.add(argv[++i]);
|
|
33
|
+
} else if (a === '-h' || a === '--help') usage();
|
|
34
|
+
else if (a.startsWith('-')) usage(`unknown option ${a}`);
|
|
35
|
+
else if (!rootArg) rootArg = a;
|
|
36
|
+
else usage(`unexpected argument ${a}`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const cwd = resolve(rootArg || '.');
|
|
40
|
+
const root = spawnSync('git', ['-C', cwd, 'rev-parse', '--show-toplevel'], {
|
|
41
|
+
encoding: 'utf8',
|
|
42
|
+
});
|
|
43
|
+
if (root.status !== 0) usage(`${cwd} is not inside a git checkout`);
|
|
44
|
+
const rootDir = root.stdout.trim();
|
|
45
|
+
|
|
46
|
+
const listed = spawnSync(
|
|
47
|
+
'git',
|
|
48
|
+
['-C', rootDir, 'ls-files', '-z', '--cached', '--others', '--exclude-standard'],
|
|
49
|
+
{ encoding: 'buffer', maxBuffer: 1024 * 1024 * 512 },
|
|
50
|
+
);
|
|
51
|
+
if (listed.status !== 0) {
|
|
52
|
+
process.stderr.write(listed.stderr?.toString() || 'git ls-files failed\n');
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const parts = listed.stdout.toString('utf8').split('\0').filter(Boolean);
|
|
57
|
+
const tracked = new Set(
|
|
58
|
+
spawnSync('git', ['-C', rootDir, 'ls-files', '-z', '--cached'], {
|
|
59
|
+
encoding: 'buffer',
|
|
60
|
+
maxBuffer: 1024 * 1024 * 512,
|
|
61
|
+
}).stdout.toString('utf8').split('\0').filter(Boolean),
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
function excluded(rel) {
|
|
65
|
+
const segments = rel.split('/');
|
|
66
|
+
for (const segment of segments) {
|
|
67
|
+
if (EXCLUDED_DIRS.has(segment)) return !keep.has(segment);
|
|
68
|
+
if (/\.egg-info$/.test(segment) || /^bazel-/.test(segment)) {
|
|
69
|
+
return !keep.has(segment);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const base = segments[segments.length - 1];
|
|
73
|
+
if (/\.(o|so|pyc|pyo|class|dylib|dll|exe|a)$/.test(base)) {
|
|
74
|
+
return !keep.has(base);
|
|
75
|
+
}
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const files = [];
|
|
80
|
+
let bytes = 0;
|
|
81
|
+
for (const rel of parts) {
|
|
82
|
+
if (!tracked.has(rel) && excluded(rel)) continue;
|
|
83
|
+
const full = join(rootDir, rel);
|
|
84
|
+
if (!existsSync(full)) continue;
|
|
85
|
+
let size = 0;
|
|
86
|
+
try {
|
|
87
|
+
size = statSync(full).size;
|
|
88
|
+
} catch {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
files.push({ path: rel, size, tracked: tracked.has(rel) });
|
|
92
|
+
bytes += size;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (mode === 'list0') {
|
|
96
|
+
process.stdout.write(files.map((f) => f.path).join('\0') + '\0');
|
|
97
|
+
} else {
|
|
98
|
+
const skipped = parts.length - files.length;
|
|
99
|
+
process.stdout.write(
|
|
100
|
+
JSON.stringify({
|
|
101
|
+
root: rootDir,
|
|
102
|
+
total: files.length,
|
|
103
|
+
bytes,
|
|
104
|
+
skipped,
|
|
105
|
+
excludedDirs: [...EXCLUDED_DIRS].sort(),
|
|
106
|
+
files,
|
|
107
|
+
}, null, 2) + '\n',
|
|
108
|
+
);
|
|
109
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: serbox-snapshots
|
|
3
|
+
description: Use when the user wants to save a serbox box's state and load it later - "save a snapshot", "checkpoint this box", "restore from a snapshot", "start a new box from my setup", "clone this box". Covers serbox snapshot save/ls/restore/rm/import, fork and create from a saved image.
|
|
4
|
+
metadata:
|
|
5
|
+
installed-by: serbox
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# serbox snapshots: save, restore, fork
|
|
9
|
+
|
|
10
|
+
A snapshot is a Docker image made from a box with `docker commit`. It contains
|
|
11
|
+
the box's whole filesystem: system files, installed packages and `/data`
|
|
12
|
+
(including `HOME`). It does **not** contain running processes, memory, open
|
|
13
|
+
connections or host-side port forwards. A box restored from a snapshot is a
|
|
14
|
+
power-cut copy: files are exactly as they were, processes are not running.
|
|
15
|
+
|
|
16
|
+
Snapshots stay on the machine, need no registry and no account. They are listed
|
|
17
|
+
under `~/.serbox/snapshots` (or `SERBOX_HOME`) and stored as local Docker
|
|
18
|
+
images tagged `serbox-snapshot/<name>:latest`.
|
|
19
|
+
|
|
20
|
+
## Save
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
serbox snapshot save work --name work-ready --description "deps installed"
|
|
24
|
+
serbox snapshot save work # name: work-<timestamp>
|
|
25
|
+
serbox snapshot ls
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
- A running box is committed live. The command waits for Docker to finish, so
|
|
29
|
+
when it returns the snapshot is ready. Stop the box only when a program must
|
|
30
|
+
flush its data first (a database mid-write); `docker commit` also works on a
|
|
31
|
+
stopped box.
|
|
32
|
+
- Names are 1 to 80 characters from `a-z`, `A-Z`, `0-9`, `.`, `_` and `-`, must
|
|
33
|
+
start with a letter or digit, and cannot start with `sn_` or `im_`. They must
|
|
34
|
+
be unique on the machine.
|
|
35
|
+
- A snapshot can contain credentials that applications wrote to disk (git
|
|
36
|
+
credentials, cloud CLI state, `.netrc`, shell history). Treat a snapshot as
|
|
37
|
+
sensitive: do not publish or share the machine's images without review.
|
|
38
|
+
|
|
39
|
+
## Restore and load
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
serbox snapshot restore work --snapshot work-ready --yes # in place
|
|
43
|
+
serbox create --name work2 --snapshot work-ready # a new box
|
|
44
|
+
serbox fork work --name work2 --count 2 # copies of a box
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
`snapshot restore` replaces the box's container with the snapshot image. The
|
|
48
|
+
box keeps its name, `--env` values, secret names and published ports, but every
|
|
49
|
+
file changed since the snapshot is lost. Without `--snapshot` it uses the most
|
|
50
|
+
recent snapshot whose source is that box.
|
|
51
|
+
|
|
52
|
+
`create --snapshot NAME` creates a new box from a snapshot without touching the
|
|
53
|
+
source. `fork BOX` commits the current state under a temporary tag and creates
|
|
54
|
+
`BOX-copy` boxes from it; the temporary image is not listed as a snapshot.
|
|
55
|
+
|
|
56
|
+
Snapshots are per-machine. To move one to another host, save the image, copy
|
|
57
|
+
it, load it there, then record it as a snapshot:
|
|
58
|
+
|
|
59
|
+
```sh
|
|
60
|
+
docker save serbox-snapshot/work-ready:latest -o work-ready.tar
|
|
61
|
+
# copy work-ready.tar to the other host, then:
|
|
62
|
+
docker load -i work-ready.tar
|
|
63
|
+
serbox snapshot import serbox-snapshot/work-ready:latest --name work-ready
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
`snapshot import IMAGE --name NAME` records an image reference that is already
|
|
67
|
+
present locally or that Docker can pull; `--name` is required.
|
|
68
|
+
|
|
69
|
+
## Remove
|
|
70
|
+
|
|
71
|
+
```sh
|
|
72
|
+
serbox snapshot rm work-ready --yes
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
This deletes the snapshot record and its Docker image. Boxes already created
|
|
76
|
+
from it are unaffected. Removing a box never removes its snapshots; remove
|
|
77
|
+
those explicitly when they are no longer needed.
|
|
78
|
+
|
|
79
|
+
## Safety
|
|
80
|
+
|
|
81
|
+
- Deleting a snapshot is irreversible. Confirm the name with `snapshot ls`
|
|
82
|
+
before running `rm`.
|
|
83
|
+
- A snapshot of a box with secrets in its environment does not store the
|
|
84
|
+
environment, but files the box wrote (`.env`, tokens in config files) are
|
|
85
|
+
included. Rotate credentials before sharing an image.
|
|
86
|
+
- Published ports are host configuration, not part of the snapshot; a new box
|
|
87
|
+
needs its own `port publish`.
|