@muhkoo/cli 0.15.0-alpha.13 → 0.15.0-alpha.14
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 +14 -6
- package/package.json +2 -2
- package/src/commands/deploy.js +146 -4
- package/src/commands/vfs.js +9 -8
- package/src/lib/mount.js +3 -0
package/README.md
CHANGED
|
@@ -39,6 +39,13 @@ app is provisioned every command runs with no extra flags. `deploy` publishes to
|
|
|
39
39
|
app's **test** environment; once it looks right on the test URL, `promote` copies that
|
|
40
40
|
release onto **production**, in place.
|
|
41
41
|
|
|
42
|
+
Once the release is live, `deploy` also copies the project into your filesystem at
|
|
43
|
+
`/apps/<slug>`, where the IDE opens it. It is the copy `muhkoo vfs import . --path
|
|
44
|
+
/apps/<slug>` makes (see [Syncing a directory](#syncing-a-directory)), and it needs you
|
|
45
|
+
signed in to the same environment with this machine paired, or a terminal to pair it
|
|
46
|
+
in. Without them, as in CI, `deploy` says why in one line and skips the copy. A failed
|
|
47
|
+
copy is a warning, not a failed deploy. `--no-vfs` skips it.
|
|
48
|
+
|
|
42
49
|
## Sign in
|
|
43
50
|
|
|
44
51
|
```bash
|
|
@@ -120,7 +127,7 @@ Run `muhkoo <command> --help` for details. A few highlights:
|
|
|
120
127
|
muhkoo apps ls # list your apps
|
|
121
128
|
muhkoo provision --spec app.json --dry-run # preview API calls
|
|
122
129
|
muhkoo provision --spec app.json --enable # enable agents/functions on channels
|
|
123
|
-
muhkoo deploy # publish dist/ to the test env
|
|
130
|
+
muhkoo deploy # publish dist/ to the test env, copy the project to /apps/<slug>
|
|
124
131
|
muhkoo promote # promote test → production, in place
|
|
125
132
|
muhkoo hosting status <appId> # releases + current pointer
|
|
126
133
|
muhkoo hosting rollback <appId> --release <id> # instant rollback
|
|
@@ -181,11 +188,12 @@ and it cannot reach this disk except through these checks:
|
|
|
181
188
|
- **Some paths never sync, in either direction.** No flag and no ignore rule
|
|
182
189
|
changes that: `.git`, `.ssh`, `.muhkoo`, `node_modules`, `.husky`, editor and
|
|
183
190
|
agent directories (`.vscode`, `.idea`, `.config`, `.claude`, `.cursor`,
|
|
184
|
-
`.zed`, `.fleet`), and credential and shell start-up files
|
|
185
|
-
`.
|
|
186
|
-
and the rest). Each one either holds
|
|
187
|
-
|
|
188
|
-
|
|
191
|
+
`.zed`, `.fleet`), and credential and shell start-up files
|
|
192
|
+
(`.muhkoo-app.json`, `.envrc`, `.npmrc`, `.netrc`, `.gitconfig`, `.profile`,
|
|
193
|
+
`.bashrc`, `.zshrc`, `.zshenv` and the rest). Each one either holds
|
|
194
|
+
credentials (`.muhkoo-app.json` holds an app's secret keys) or can run code
|
|
195
|
+
without an execute bit. Names are compared the way a case-folding volume
|
|
196
|
+
would compare them, so `Node_Modules`, `.GIT` and `GIT~1` are refused too.
|
|
189
197
|
- **Never your home directory.** Both commands refuse the filesystem root, your
|
|
190
198
|
home directory, and anything that contains it. There is no override.
|
|
191
199
|
- **One write boundary.** Every write and delete on disk checks each part of
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@muhkoo/cli",
|
|
3
|
-
"version": "0.15.0-alpha.
|
|
3
|
+
"version": "0.15.0-alpha.14",
|
|
4
4
|
"description": "Command-line interface for the Muhkoo platform — provision backends, deploy apps, and manage agents, functions, databases, and domains.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"release": "npm publish --tag alpha && npm dist-tag add @muhkoo/cli@$npm_package_version latest"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@muhkoo/connect": "0.15.0-alpha.
|
|
46
|
+
"@muhkoo/connect": "0.15.0-alpha.14",
|
|
47
47
|
"snarkjs": "^0.7.0"
|
|
48
48
|
},
|
|
49
49
|
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e",
|
package/src/commands/deploy.js
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
* each file uploads by its sha256 (only changed files transfer), then a release
|
|
4
4
|
* is committed (an atomic pointer flip; instant + rollback-able).
|
|
5
5
|
*
|
|
6
|
+
* Once the release is live, it copies the project into the deployer's
|
|
7
|
+
* filesystem at /apps/<slug>, where the IDE opens it (`copyToFilesystem`).
|
|
8
|
+
* `--no-vfs` skips that.
|
|
9
|
+
*
|
|
6
10
|
* Auth accepts EITHER an app secret key (--key / $MUHKOO_DEPLOY_KEY) or your
|
|
7
11
|
* developer session (`muhkoo login`). The app id and key are read from
|
|
8
12
|
* .muhkoo-app.json when present, so a provisioned app deploys with no flags.
|
|
@@ -10,19 +14,35 @@
|
|
|
10
14
|
|
|
11
15
|
import { readFile, readdir, stat, access } from "node:fs/promises";
|
|
12
16
|
import { createHash } from "node:crypto";
|
|
17
|
+
import { spawn } from "node:child_process";
|
|
18
|
+
import { fileURLToPath } from "node:url";
|
|
13
19
|
import { join, relative, sep } from "node:path";
|
|
14
20
|
import { resolveBase, loadConfig, resolveToken } from "../lib/config.js";
|
|
15
|
-
import {
|
|
21
|
+
import { resolveBaseUrl } from "../lib/bases.js";
|
|
22
|
+
import { skCall, devCall, ensure } from "../lib/http.js";
|
|
16
23
|
import { firstOf } from "../lib/args.js";
|
|
17
|
-
import { step, ok, info, die, redact } from "../lib/ui.js";
|
|
24
|
+
import { step, ok, info, warn, die, redact } from "../lib/ui.js";
|
|
18
25
|
|
|
19
26
|
export const help = `muhkoo deploy — deploy a built client to Muhkoo hosting
|
|
20
27
|
|
|
21
28
|
Usage:
|
|
22
|
-
muhkoo deploy [--app <appId>] [--key <mk_*_sk_*>] [--dist dist] [--base <env|url>]
|
|
29
|
+
muhkoo deploy [--app <appId>] [--key <mk_*_sk_*>] [--dist dist] [--base <env|url>] [--no-vfs]
|
|
23
30
|
|
|
24
31
|
Defaults: --app and --key fall back to .muhkoo-app.json, then $MUHKOO_APP_ID /
|
|
25
|
-
$MUHKOO_DEPLOY_KEY. With no app secret key, your developer session is used
|
|
32
|
+
$MUHKOO_DEPLOY_KEY. With no app secret key, your developer session is used.
|
|
33
|
+
|
|
34
|
+
Once the release is live, deploy copies the folder you ran it from into your
|
|
35
|
+
filesystem at /apps/<slug>, where the IDE opens it. It is the copy
|
|
36
|
+
\`muhkoo vfs import . --path /apps/<slug>\` makes, under the same ignore rules
|
|
37
|
+
(see \`muhkoo vfs --help\`): only files changed here upload, and it never
|
|
38
|
+
deletes. It needs you signed in to the same environment (\`muhkoo login\`) and
|
|
39
|
+
this machine paired, or a terminal to pair it in; without them it says why and
|
|
40
|
+
skips. A failed copy is a warning, because the deploy has already succeeded.
|
|
41
|
+
Storage for the copy is billed to the deployed app, using its publishable key
|
|
42
|
+
from .muhkoo-app.json, or else to the app you write your filesystem as
|
|
43
|
+
(\`muhkoo vfs use-app\`).
|
|
44
|
+
|
|
45
|
+
--no-vfs deploy only; skip the copy`;
|
|
26
46
|
|
|
27
47
|
async function readRecord() {
|
|
28
48
|
try {
|
|
@@ -98,4 +118,126 @@ export default async function deploy(args) {
|
|
|
98
118
|
info(` release: ${rel.body.releaseId}`);
|
|
99
119
|
info(` size: ${(rel.body.bytes / 1024).toFixed(0)} KiB across ${rel.body.files} files`);
|
|
100
120
|
info(` live at: ${rel.body.url}`);
|
|
121
|
+
|
|
122
|
+
if (!args["no-vfs"]) await copyToFilesystem({ args, cfg, record, baseUrl, appId });
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Copy the project into the deployer's filesystem at /apps/<slug>, where the
|
|
127
|
+
* portal's "Open in IDE" looks for it, by running `muhkoo vfs import` on the
|
|
128
|
+
* folder deploy ran from.
|
|
129
|
+
*
|
|
130
|
+
* Best effort by design. The site is already live when this runs, so every
|
|
131
|
+
* reason not to copy is one line, and a failed copy is a warning, never a
|
|
132
|
+
* failed deploy.
|
|
133
|
+
*
|
|
134
|
+
* Import runs in a child process, not in this one, because its failure paths
|
|
135
|
+
* `die()`, which exits the process: an expired session or a revoked pairing
|
|
136
|
+
* would otherwise turn a deploy that succeeded into exit 1.
|
|
137
|
+
*/
|
|
138
|
+
export async function copyToFilesystem(ctx, { run = runImport } = {}) {
|
|
139
|
+
const plan = await planCopy(ctx);
|
|
140
|
+
if (plan.skip) return info("", plan.skip);
|
|
141
|
+
info("");
|
|
142
|
+
step(`Copying the project to ${plan.root} in your filesystem (--no-vfs skips this)…`);
|
|
143
|
+
if (plan.note) info(` ${plan.note}`);
|
|
144
|
+
const code = await run(plan);
|
|
145
|
+
if (code !== 0) {
|
|
146
|
+
warn(
|
|
147
|
+
`The site is live, but copying the project to ${plan.root} failed (see above).`,
|
|
148
|
+
`Retry with: muhkoo vfs import . --path ${plan.root}`,
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Whether and how to copy: `{ skip }`, the line to print instead, or
|
|
155
|
+
* `{ dir, root, base, token, key, note? }` for `runImport`.
|
|
156
|
+
*
|
|
157
|
+
* Everything that can be checked without unlocking is checked here, so a
|
|
158
|
+
* deploy from CI (an app key and no login), from a login to the other
|
|
159
|
+
* environment, or from a machine that cannot pair without a terminal says so
|
|
160
|
+
* in one line instead of starting an import that can only fail.
|
|
161
|
+
*/
|
|
162
|
+
export async function planCopy({
|
|
163
|
+
args,
|
|
164
|
+
cfg,
|
|
165
|
+
record,
|
|
166
|
+
baseUrl,
|
|
167
|
+
appId,
|
|
168
|
+
dir = process.cwd(),
|
|
169
|
+
env = process.env,
|
|
170
|
+
interactive = Boolean(process.stdin.isTTY),
|
|
171
|
+
}) {
|
|
172
|
+
const notCopied = "so the project was not copied to your filesystem";
|
|
173
|
+
|
|
174
|
+
// The session the import runs on. One passed explicitly is taken to be for
|
|
175
|
+
// the base being deployed to; the stored one belongs to the base `muhkoo
|
|
176
|
+
// login` signed in at, and there is only ever one.
|
|
177
|
+
const explicit = firstOf(args.token, env.MUHKOO_DEV_TOKEN);
|
|
178
|
+
const token = firstOf(explicit, cfg.token);
|
|
179
|
+
if (!token) return { skip: `Not signed in, ${notCopied}. Run \`muhkoo login\` and deploy again to copy it.` };
|
|
180
|
+
if (!explicit) {
|
|
181
|
+
const signedInAt = resolveBaseUrl(cfg.base);
|
|
182
|
+
if (trimSlash(signedInAt) !== trimSlash(baseUrl)) {
|
|
183
|
+
return { skip: `Signed in to ${signedInAt}, not ${baseUrl}, ${notCopied}.` };
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// The app's own slug, from the server: the IDE reads /apps/<slug>, whatever
|
|
188
|
+
// the folder is called (muhkoo.com deploys from a folder named `website`).
|
|
189
|
+
// A record for this same app stands in when the lookup fails.
|
|
190
|
+
const sameApp = Boolean(record) && record.appId === appId;
|
|
191
|
+
const found = await devCall({ baseUrl, token }, "GET", `/api/apps/${appId}`).catch(() => null);
|
|
192
|
+
const slug = (found?.ok && found.body?.slug) || (sameApp && record.slug) || null;
|
|
193
|
+
if (!slug) {
|
|
194
|
+
return { skip: `Could not look up the app's slug${found ? ` (${found.status})` : ""}, ${notCopied}.` };
|
|
195
|
+
}
|
|
196
|
+
const root = `/apps/${slug}`;
|
|
197
|
+
|
|
198
|
+
// Unlocking needs MUHKOO_SEED, this machine's pairing, or a terminal to
|
|
199
|
+
// sign in and pair from.
|
|
200
|
+
const paired = Boolean(cfg.deviceFactorId && cfg.deviceKey && cfg.username);
|
|
201
|
+
if (!env.MUHKOO_SEED && !paired && !interactive) {
|
|
202
|
+
return {
|
|
203
|
+
skip: `This machine is not paired, ${notCopied}. Run \`muhkoo vfs import . --path ${root}\` once in a terminal to pair it.`,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Bill the copy to the deployed app when this machine holds a key for it,
|
|
208
|
+
// or else to the app the filesystem is written as.
|
|
209
|
+
const pk = (keyEnv) => record?.keys?.find((k) => k.type === "pk" && k.env === keyEnv)?.plaintext;
|
|
210
|
+
const own = (sameApp && (pk("live") || pk("test"))) || cfg.vfsApps?.[slug];
|
|
211
|
+
if (own) return { dir, root, base: baseUrl, token, key: own };
|
|
212
|
+
const fallback = cfg.vfsApp && cfg.vfsApps?.[cfg.vfsApp];
|
|
213
|
+
if (fallback) {
|
|
214
|
+
return {
|
|
215
|
+
dir, root, base: baseUrl, token, key: fallback,
|
|
216
|
+
note: `Storage for the copy is billed to ${cfg.vfsApp}, the app you write your filesystem as.`,
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
return {
|
|
220
|
+
skip:
|
|
221
|
+
`No key for ${slug} on this machine, ${notCopied}. Deploy from the folder with its ` +
|
|
222
|
+
`.muhkoo-app.json, or run \`muhkoo vfs use-app ${slug} --key <appKey>\` once.`,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** Run `muhkoo vfs import <dir> --path <root>` as a child process; resolves to its exit code. */
|
|
227
|
+
function runImport({ dir, root, base, token, key }) {
|
|
228
|
+
const bin = fileURLToPath(new URL("../../bin/muhkoo.js", import.meta.url));
|
|
229
|
+
return new Promise((done) => {
|
|
230
|
+
const child = spawn(process.execPath, [bin, "vfs", "import", dir, "--path", root, "--base", base], {
|
|
231
|
+
stdio: "inherit",
|
|
232
|
+
// The session checked above and the key to bill. Passed in the
|
|
233
|
+
// environment rather than argv, so neither shows in the process list.
|
|
234
|
+
env: { ...process.env, MUHKOO_DEV_TOKEN: token, MUHKOO_APP_KEY: key },
|
|
235
|
+
});
|
|
236
|
+
child.on("error", () => done(1));
|
|
237
|
+
child.on("exit", (code) => done(code ?? 1));
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function trimSlash(url) {
|
|
242
|
+
return String(url).replace(/\/+$/, "");
|
|
101
243
|
}
|
package/src/commands/vfs.js
CHANGED
|
@@ -90,14 +90,15 @@ rules is left alone — neither synced nor deleted — and named.
|
|
|
90
90
|
|
|
91
91
|
Some paths never sync in either direction, whatever the rules say: .git,
|
|
92
92
|
.ssh, node_modules, .muhkoo, editor and agent config (.vscode, .idea, .claude,
|
|
93
|
-
.cursor, .zed, .fleet), .husky, and shell and credential files
|
|
94
|
-
.netrc, .zshrc, .zshenv, …). Neither import nor
|
|
95
|
-
directory, or on anything that contains it. One
|
|
96
|
-
2 GiB or 10,000 files, and reads at most as much
|
|
97
|
-
once in another pass; what it has read before it
|
|
98
|
-
leaves the disk 5% of its space free, at least
|
|
99
|
-
judged by the bytes that arrive, not the sizes
|
|
100
|
-
Ignore files are held to these limits like any other
|
|
93
|
+
.cursor, .zed, .fleet), .husky, and shell and credential files
|
|
94
|
+
(.muhkoo-app.json, .npmrc, .netrc, .zshrc, .zshenv, …). Neither import nor
|
|
95
|
+
mount will run on your home directory, or on anything that contains it. One
|
|
96
|
+
pass of mount pulls at most 2 GiB or 10,000 files, and reads at most as much
|
|
97
|
+
to compare, carrying on at once in another pass; what it has read before it
|
|
98
|
+
does not read again. A pull leaves the disk 5% of its space free, at least
|
|
99
|
+
1 GiB and at most 10 GiB — judged by the bytes that arrive, not the sizes
|
|
100
|
+
your filesystem reports. Ignore files are held to these limits like any other
|
|
101
|
+
file.
|
|
101
102
|
|
|
102
103
|
Reading your files is free. WRITING stores bytes, which are metered to an
|
|
103
104
|
app — so put, rm, cp, mv and restore need an app signed in first.
|
package/src/lib/mount.js
CHANGED
|
@@ -323,6 +323,9 @@ const REFUSED_DIRS = new Set([
|
|
|
323
323
|
".husky", ".claude", ".cursor", ".zed", ".fleet",
|
|
324
324
|
]);
|
|
325
325
|
const REFUSED_FILES = new Set([
|
|
326
|
+
// `.muhkoo-app.json` is what `muhkoo provision` writes: the app id and its
|
|
327
|
+
// secret keys. `muhkoo deploy` imports the folder holding it.
|
|
328
|
+
".muhkoo-app.json",
|
|
326
329
|
".envrc", ".npmrc", ".netrc", ".gitconfig", ".pam_environment", ".xprofile",
|
|
327
330
|
".profile", ".bashrc", ".bash_profile", ".bash_login", ".bash_logout",
|
|
328
331
|
".zshrc", ".zshenv", ".zprofile", ".zlogin", ".zlogout", ".kshrc",
|