poad 2.76.4 → 2.78.0
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 +49 -0
- package/global/cli.js +1 -0
- package/global/doctor.js +41 -0
- package/global/init.js +6 -0
- package/global/start.js +4 -0
- package/package.json +4 -1
- package/project/deploy.js +13 -1
- package/project/link.js +2 -0
- package/project/logs.js +2 -0
- package/project/ref/push.js +42 -29
- package/test/doctor.test.js +159 -0
- package/test/graphql.test.js +25 -0
- package/test/project-sync.test.js +116 -13
- package/test/push-progress.test.js +181 -0
- package/test/storage-tus.test.js +7 -1
- package/utils/cloud/api.js +39 -3
- package/utils/cloud/deploy-memo.js +46 -0
- package/utils/doctor.js +368 -0
- package/utils/graphql.js +41 -0
- package/utils/help-details.js +18 -0
- package/utils/logline.js +4 -2
- package/utils/progress.js +198 -0
- package/utils/project-sync/pg.js +106 -3
- package/utils/project-sync/plan.js +102 -11
- package/utils/project-sync/run.js +146 -47
- package/utils/reference-store.js +20 -26
- package/utils/seed/run.js +57 -11
- package/utils/storage-sync.js +28 -6
- package/utils/storage.js +18 -2
package/utils/doctor.js
ADDED
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
// poad doctor : ce poste peut-il faire tourner poad ? Un contrôle par ligne, ✔ / ⚠ / ✕, avec quoi faire et un lien.
|
|
2
|
+
//
|
|
3
|
+
// système macOS et Linux (priorité), Windows en bêta (dit, jamais bloquant)
|
|
4
|
+
// Node.js au moins la version de "engines" (package.json)
|
|
5
|
+
// Docker installé, démarré (le cas le plus fréquent : installé mais pas lancé), version du démon,
|
|
6
|
+
// architecture, place libre de son stockage, mémoire de la VM (macOS, Windows) ;
|
|
7
|
+
// Linux : Docker Engine (sans Desktop), droits sur le socket (groupe docker), systemd,
|
|
8
|
+
// host-gateway (Docker 20.10+), place lue sur le disque de /var/lib/docker
|
|
9
|
+
// Windows : Docker Desktop avec WSL2
|
|
10
|
+
// git présent (Mac neuf : le premier appel propose les outils de ligne de commande d'Apple)
|
|
11
|
+
// réseau Docker Hub, permalink (raw.githubusercontent.com), poad.io ; délais courts
|
|
12
|
+
// projet poad/config.toml lisible, image de l'engine présente, ports libres, liaison poad.io (lien et
|
|
13
|
+
// session valides ; le jeton n'est jamais montré)
|
|
14
|
+
// CLI version, et la dernière publiée
|
|
15
|
+
//
|
|
16
|
+
// Bloquant (code de sortie 1) : Node trop vieux, Docker absent / arrêté / inaccessible, git absent,
|
|
17
|
+
// config.toml illisible. Le reste avertit. preflight() : les seuls contrôles bloquants, pour poad init,
|
|
18
|
+
// start et link (moins d'une seconde quand tout va bien).
|
|
19
|
+
//
|
|
20
|
+
// Tout passe par sys (exec, fetch, fs, platform…) : les tests simulent Docker absent, arrêté, Node trop vieux…
|
|
21
|
+
'use strict';
|
|
22
|
+
const fs = require('fs');
|
|
23
|
+
const os = require('os');
|
|
24
|
+
const path = require('path');
|
|
25
|
+
|
|
26
|
+
const LINKS = {
|
|
27
|
+
node: 'https://nodejs.org/en/download',
|
|
28
|
+
docker_mac: 'https://docs.docker.com/desktop/setup/install/mac-install/',
|
|
29
|
+
docker_linux: 'https://docs.docker.com/engine/install/',
|
|
30
|
+
docker_linux_group: 'https://docs.docker.com/engine/install/linux-postinstall/',
|
|
31
|
+
docker_windows: 'https://docs.docker.com/desktop/setup/install/windows-install/',
|
|
32
|
+
docker_wsl: 'https://docs.docker.com/desktop/features/wsl/',
|
|
33
|
+
docker_resources: 'https://docs.docker.com/desktop/settings-and-maintenance/settings/#resources',
|
|
34
|
+
git: 'https://git-scm.com/downloads',
|
|
35
|
+
install: 'https://github.com/poadio/cli#prerequisites',
|
|
36
|
+
};
|
|
37
|
+
const GiB = 1024 ** 3;
|
|
38
|
+
const DISK_WARN = 10 * GiB;
|
|
39
|
+
const MEM_WARN = 4 * GiB;
|
|
40
|
+
|
|
41
|
+
/** Version « 20.11.1 » ≥ « 20.0.0 » ? Pure. */
|
|
42
|
+
function atLeast(v, min) {
|
|
43
|
+
const a = String(v || '').replace(/^v/, '').split(/[.+-]/).map((x) => parseInt(x, 10) || 0);
|
|
44
|
+
const b = String(min || '').replace(/^[^\d]*/, '').split('.').map((x) => parseInt(x, 10) || 0);
|
|
45
|
+
for (let i = 0; i < 3; i++) if ((a[i] || 0) !== (b[i] || 0)) return (a[i] || 0) > (b[i] || 0);
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const minNode = () => String((require('../package.json').engines || {}).node || '>=20.0.0').replace(/^>=\s*/, '');
|
|
50
|
+
|
|
51
|
+
/** Système réel : tout ce que les contrôles demandent au poste */
|
|
52
|
+
function realSys() {
|
|
53
|
+
const { spawn } = require('child_process');
|
|
54
|
+
return {
|
|
55
|
+
platform: process.platform,
|
|
56
|
+
arch: process.arch,
|
|
57
|
+
node: process.versions.node,
|
|
58
|
+
env: process.env,
|
|
59
|
+
getuid: process.getuid ? () => process.getuid() : null,
|
|
60
|
+
/** { code, stdout, stderr } ; code -1 : commande introuvable (ENOENT) ; -2 : délai dépassé */
|
|
61
|
+
exec(cmd, args, { timeout = 5000 } = {}) {
|
|
62
|
+
return new Promise((resolve) => {
|
|
63
|
+
let out = '';
|
|
64
|
+
let err = '';
|
|
65
|
+
let done = false;
|
|
66
|
+
let child;
|
|
67
|
+
try {
|
|
68
|
+
child = spawn(cmd, args, { stdio: ['ignore', 'pipe', 'pipe'], windowsHide: true });
|
|
69
|
+
} catch (e) {
|
|
70
|
+
return resolve({ code: -1, stdout: '', stderr: e.message });
|
|
71
|
+
}
|
|
72
|
+
const timer = setTimeout(() => {
|
|
73
|
+
if (done) return;
|
|
74
|
+
done = true;
|
|
75
|
+
child.kill('SIGKILL');
|
|
76
|
+
resolve({ code: -2, stdout: out, stderr: 'timeout' });
|
|
77
|
+
}, timeout);
|
|
78
|
+
child.stdout.on('data', (d) => (out += d));
|
|
79
|
+
child.stderr.on('data', (d) => (err += d));
|
|
80
|
+
child.on('error', (e) => {
|
|
81
|
+
if (done) return;
|
|
82
|
+
done = true;
|
|
83
|
+
clearTimeout(timer);
|
|
84
|
+
resolve({ code: e.code === 'ENOENT' ? -1 : -3, stdout: '', stderr: e.message });
|
|
85
|
+
});
|
|
86
|
+
child.on('close', (code) => {
|
|
87
|
+
if (done) return;
|
|
88
|
+
done = true;
|
|
89
|
+
clearTimeout(timer);
|
|
90
|
+
resolve({ code, stdout: out, stderr: err });
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
},
|
|
94
|
+
/** Joignable ? { ok, status, ms, error } (une réponse HTTP, même 401, veut dire joignable) */
|
|
95
|
+
async reach(url, { timeout = 4000 } = {}) {
|
|
96
|
+
const t0 = Date.now();
|
|
97
|
+
try {
|
|
98
|
+
const res = await fetch(url, { method: 'GET', redirect: 'manual', signal: AbortSignal.timeout(timeout), headers: { 'user-agent': `poad-cli/${require('../package.json').version} (doctor)` } });
|
|
99
|
+
await res.body?.cancel().catch(() => {});
|
|
100
|
+
return { ok: true, status: res.status, ms: Date.now() - t0 };
|
|
101
|
+
} catch (e) {
|
|
102
|
+
return { ok: false, error: e && e.name === 'TimeoutError' ? `no answer within ${timeout / 1000} s` : (e && e.cause && e.cause.code) || (e && e.message) || String(e), ms: Date.now() - t0 };
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
async json(url, { timeout = 4000 } = {}) {
|
|
106
|
+
const res = await fetch(url, { signal: AbortSignal.timeout(timeout), headers: { accept: 'application/json' } });
|
|
107
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
108
|
+
return res.json();
|
|
109
|
+
},
|
|
110
|
+
statfs(p) {
|
|
111
|
+
const st = fs.statfsSync(p);
|
|
112
|
+
return { free: st.bavail * st.bsize, size: st.blocks * st.bsize };
|
|
113
|
+
},
|
|
114
|
+
exists: (p) => fs.existsSync(p),
|
|
115
|
+
readFile: (p) => fs.readFileSync(p, 'utf8'),
|
|
116
|
+
/** Port libre sur ce poste ? */
|
|
117
|
+
portFree(port) {
|
|
118
|
+
return new Promise((resolve) => {
|
|
119
|
+
const srv = require('net').createServer();
|
|
120
|
+
srv.once('error', () => resolve(false));
|
|
121
|
+
srv.once('listening', () => srv.close(() => resolve(true)));
|
|
122
|
+
srv.listen(port, '0.0.0.0');
|
|
123
|
+
});
|
|
124
|
+
},
|
|
125
|
+
home: os.homedir(),
|
|
126
|
+
cwd: () => process.cwd(),
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const ok = (id, label, detail, extra = {}) => ({ id, status: 'ok', label, detail, ...extra });
|
|
131
|
+
const warn = (id, label, detail, fix, link, extra = {}) => ({ id, status: 'warn', label, detail, fix, link, ...extra });
|
|
132
|
+
const fail = (id, label, detail, fix, link, extra = {}) => ({ id, status: 'fail', label, detail, fix, link, blocking: true, ...extra });
|
|
133
|
+
|
|
134
|
+
const size = (n) => (n >= GiB ? `${(n / GiB).toFixed(1)} GB` : `${Math.round(n / 1024 ** 2)} MB`);
|
|
135
|
+
|
|
136
|
+
// --- Contrôles -------------------------------------------------------------------------------------------
|
|
137
|
+
|
|
138
|
+
function checkSystem(sys) {
|
|
139
|
+
const name = { darwin: 'macOS', linux: 'Linux', win32: 'Windows' }[sys.platform] || sys.platform;
|
|
140
|
+
if (sys.platform === 'win32') return warn('system', 'system', `Windows (${sys.arch}): supported in beta`, 'macOS and Linux are the main platforms; on Windows, Docker Desktop with WSL2 is needed. Tell us what breaks.', LINKS.install);
|
|
141
|
+
if (!['darwin', 'linux'].includes(sys.platform)) return warn('system', 'system', `${name} (${sys.arch}): not supported`, 'poad runs on macOS and Linux (Windows in beta).', LINKS.install);
|
|
142
|
+
return ok('system', 'system', `${name} (${sys.arch})`);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function checkNode(sys) {
|
|
146
|
+
const min = minNode();
|
|
147
|
+
if (atLeast(sys.node, min)) return ok('node', 'Node.js', `${sys.node} (${min} or later needed)`);
|
|
148
|
+
return fail('node', 'Node.js', `${sys.node}: too old, ${min} or later needed`, `Install Node.js ${min.split('.')[0]} or later (nvm install ${min.split('.')[0]}, or the installer), then "npm i -g poad" again.`, LINKS.node);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const dockerLink = (sys) => (sys.platform === 'darwin' ? LINKS.docker_mac : sys.platform === 'win32' ? LINKS.docker_windows : LINKS.docker_linux);
|
|
152
|
+
|
|
153
|
+
/** Docker : installé, démarré, accessible ; rend { checks, info } (info : docker info, ou null) */
|
|
154
|
+
async function checkDocker(sys, { quick = false } = {}) {
|
|
155
|
+
const checks = [];
|
|
156
|
+
const v = await sys.exec('docker', ['--version'], { timeout: 3000 });
|
|
157
|
+
if (v.code === -1) {
|
|
158
|
+
const how = sys.platform === 'linux' ? 'Install Docker Engine (Docker Desktop is not needed): curl -fsSL https://get.docker.com | sh, then sudo usermod -aG docker $USER and log in again.' : 'Install Docker Desktop, then start it.';
|
|
159
|
+
checks.push(fail('docker', 'Docker', 'not installed (no "docker" command)', how, dockerLink(sys)));
|
|
160
|
+
return { checks, info: null };
|
|
161
|
+
}
|
|
162
|
+
const client = (/version ([\w.+-]+)/i.exec(v.stdout) || [])[1] || '?';
|
|
163
|
+
const r = await sys.exec('docker', ['info', '--format', '{{json .}}'], { timeout: quick ? 4000 : 8000 });
|
|
164
|
+
let info = null;
|
|
165
|
+
try {
|
|
166
|
+
info = r.code === 0 ? JSON.parse(r.stdout.trim()) : null;
|
|
167
|
+
} catch {}
|
|
168
|
+
// docker info rend 0 avec ServerErrors quand le démon ne répond pas (Docker récent)
|
|
169
|
+
const errText = `${r.stderr || ''} ${info && Array.isArray(info.ServerErrors) ? info.ServerErrors.join(' ') : ''}`;
|
|
170
|
+
if (!info || !info.ServerVersion) {
|
|
171
|
+
if (/permission denied/i.test(errText)) {
|
|
172
|
+
checks.push(fail('docker_running', 'Docker access', `the Docker socket refuses this user (${(sys.env.USER || 'you')})`, 'Add yourself to the docker group: sudo usermod -aG docker $USER, then log out and in again (or: newgrp docker).', LINKS.docker_linux_group));
|
|
173
|
+
} else if (r.code === -2) {
|
|
174
|
+
checks.push(fail('docker_running', 'Docker running', 'the Docker daemon does not answer (no answer within a few seconds)', sys.platform === 'linux' ? 'Restart it: sudo systemctl restart docker' : 'Restart Docker Desktop (menu bar icon → Restart).', dockerLink(sys)));
|
|
175
|
+
} else {
|
|
176
|
+
const fix = sys.platform === 'darwin' ? 'Start Docker Desktop: open -a Docker (wait for the whale icon to stop moving), then run the command again.' : sys.platform === 'win32' ? 'Start Docker Desktop from the Start menu, then run the command again.' : 'Start the daemon: sudo systemctl start docker (and sudo systemctl enable docker to start it at boot).';
|
|
177
|
+
checks.push(fail('docker_running', 'Docker running', `installed (${client}) but not started`, fix, dockerLink(sys)));
|
|
178
|
+
}
|
|
179
|
+
return { checks, info: null };
|
|
180
|
+
}
|
|
181
|
+
const desktop = /docker desktop/i.test(String(info.OperatingSystem || ''));
|
|
182
|
+
checks.push(ok('docker_running', 'Docker running', `${desktop ? 'Docker Desktop' : 'Docker Engine'} ${info.ServerVersion}, ${info.Architecture || info.OSType || '?'}${info.OperatingSystem && !desktop ? ` (${info.OperatingSystem})` : ''}`));
|
|
183
|
+
if (quick) return { checks, info };
|
|
184
|
+
// host-gateway (host.docker.internal sur Linux) : Docker 20.10 ou plus
|
|
185
|
+
if (!atLeast(info.ServerVersion, '20.10.0')) checks.push(fail('docker_version', 'Docker version', `${info.ServerVersion}: too old, 20.10 or later needed (host-gateway)`, sys.platform === 'linux' ? 'Upgrade Docker Engine from the Docker repository (the distribution package is often old).' : 'Update Docker Desktop.', dockerLink(sys)));
|
|
186
|
+
// Architecture : l'image de l'engine existe en amd64 et arm64
|
|
187
|
+
const arch = String(info.Architecture || '');
|
|
188
|
+
if (arch && !/x86_64|amd64|aarch64|arm64/i.test(arch)) checks.push(warn('docker_arch', 'Docker architecture', `${arch}: the engine image is built for amd64 and arm64 only`, null, LINKS.install));
|
|
189
|
+
if (sys.platform === 'win32') {
|
|
190
|
+
const wsl = /wsl|microsoft/i.test(`${info.KernelVersion || ''} ${info.OperatingSystem || ''}`);
|
|
191
|
+
checks.push(wsl ? ok('docker_wsl', 'WSL2', 'Docker Desktop runs on WSL2') : warn('docker_wsl', 'WSL2', 'Docker Desktop does not seem to use WSL2', 'Docker Desktop → Settings → General → "Use the WSL 2 based engine".', LINKS.docker_wsl));
|
|
192
|
+
}
|
|
193
|
+
if (sys.platform === 'linux' && desktop) checks.push(warn('docker_engine', 'Docker Engine', 'Docker Desktop for Linux: it works, but Docker Engine alone is lighter and what poad is tested with', null, LINKS.docker_linux));
|
|
194
|
+
if (sys.platform === 'linux' && !desktop) {
|
|
195
|
+
const sd = await sys.exec('systemctl', ['is-enabled', 'docker'], { timeout: 2000 });
|
|
196
|
+
if (sd.code !== -1 && sd.stdout.trim() && sd.stdout.trim() !== 'enabled') checks.push(warn('docker_boot', 'Docker at boot', `the docker service is ${sd.stdout.trim()}: it will not start by itself after a reboot`, 'sudo systemctl enable docker', LINKS.docker_linux_group));
|
|
197
|
+
}
|
|
198
|
+
// Mémoire de la VM (macOS, Windows)
|
|
199
|
+
const mem = Number(info.MemTotal) || 0;
|
|
200
|
+
if (sys.platform !== 'linux' && mem) {
|
|
201
|
+
if (mem < MEM_WARN) checks.push(warn('docker_memory', 'Docker memory', `${size(mem)} given to the Docker VM: 4 GB or more is advised (engine, database, functions)`, 'Docker Desktop → Settings → Resources → Memory.', LINKS.docker_resources));
|
|
202
|
+
else checks.push(ok('docker_memory', 'Docker memory', `${size(mem)} given to the Docker VM`));
|
|
203
|
+
}
|
|
204
|
+
checks.push(await checkDockerDisk(sys, info));
|
|
205
|
+
return { checks, info };
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** Place libre du stockage de Docker : Linux, le disque de DockerRootDir ; macOS / Windows, le disque du poste (le disque de la VM y grandit) */
|
|
209
|
+
async function checkDockerDisk(sys, info) {
|
|
210
|
+
const candidates = sys.platform === 'linux' ? [info.DockerRootDir || '/var/lib/docker', '/var/lib', '/'] : [path.join(sys.home, 'Library', 'Containers', 'com.docker.docker'), sys.home];
|
|
211
|
+
for (const p of candidates) {
|
|
212
|
+
let st;
|
|
213
|
+
try {
|
|
214
|
+
st = sys.statfs(p);
|
|
215
|
+
} catch {
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
const where = sys.platform === 'linux' ? `disk of ${info.DockerRootDir || '/var/lib/docker'}` : 'disk of this machine (the Docker VM disk grows on it)';
|
|
219
|
+
if (st.free < DISK_WARN) return warn('docker_disk', 'Docker disk', `${size(st.free)} free on the ${where}: 10 GB or more is advised`, 'Free some room: poad clean, then docker system prune (unused images and containers).', LINKS.install, { free: st.free });
|
|
220
|
+
return ok('docker_disk', 'Docker disk', `${size(st.free)} free on the ${where}`, { free: st.free });
|
|
221
|
+
}
|
|
222
|
+
return warn('docker_disk', 'Docker disk', 'free room unknown (not readable)', null, null);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
async function checkGit(sys) {
|
|
226
|
+
// Mac neuf : /usr/bin/git existe mais n'est qu'un renvoi vers les outils de ligne de commande d'Apple
|
|
227
|
+
if (sys.platform === 'darwin') {
|
|
228
|
+
const x = await sys.exec('xcode-select', ['-p'], { timeout: 2000 });
|
|
229
|
+
if (x.code !== 0) return warn('git', 'git', 'the Apple command line tools are not installed: the first "git" call opens a window to install them', 'Install them now: xcode-select --install', LINKS.git);
|
|
230
|
+
}
|
|
231
|
+
const g = await sys.exec('git', ['--version'], { timeout: 3000 });
|
|
232
|
+
if (g.code !== 0) return fail('git', 'git', 'not installed', sys.platform === 'linux' ? 'Install it: sudo apt install git (Debian, Ubuntu), sudo dnf install git (Fedora)…' : sys.platform === 'win32' ? 'Install Git for Windows.' : 'Install it: xcode-select --install', LINKS.git);
|
|
233
|
+
return ok('git', 'git', g.stdout.trim().replace(/^git version /, ''));
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
async function checkNetwork(sys) {
|
|
237
|
+
const api = (() => {
|
|
238
|
+
try {
|
|
239
|
+
return require('./cloud/api').apiBase(sys.env);
|
|
240
|
+
} catch {
|
|
241
|
+
return 'https://poad.io/_poad/cloud';
|
|
242
|
+
}
|
|
243
|
+
})();
|
|
244
|
+
const targets = [
|
|
245
|
+
['net_dockerhub', 'Docker Hub', 'https://registry-1.docker.io/v2/', 'engine images are pulled from there'],
|
|
246
|
+
['net_permalink', 'permalink', 'https://raw.githubusercontent.com/poadio/permalink/refs/heads/main/poad.json', 'versions proposed by the CLI'],
|
|
247
|
+
['net_poadio', 'poad.io', `${api}/v1/health`, 'hosted projects, poad push / pull'],
|
|
248
|
+
];
|
|
249
|
+
const res = await Promise.all(targets.map(([, , url]) => sys.reach(url, { timeout: 4000 })));
|
|
250
|
+
return targets.map(([id, label, url, why], i) => {
|
|
251
|
+
const r = res[i];
|
|
252
|
+
const host = new URL(url).host;
|
|
253
|
+
return r.ok ? ok(id, `network: ${label}`, `${host} answers (${r.ms} ms)`) : warn(id, `network: ${label}`, `${host} not reachable (${r.error}): ${why}`, 'Check the connection, a proxy (HTTPS_PROXY) or a firewall.', null);
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/** Le dossier poad du projet courant : config lisible, image présente, ports, liaison poad.io */
|
|
258
|
+
async function checkProject(sys, root, { info } = {}) {
|
|
259
|
+
const checks = [];
|
|
260
|
+
let config;
|
|
261
|
+
try {
|
|
262
|
+
config = require('toml').parse(sys.readFile(root));
|
|
263
|
+
} catch (e) {
|
|
264
|
+
checks.push(fail('project_config', 'poad/config.toml', `not readable: ${String(e.message).split('\n')[0]}`, 'Fix the line named above (TOML syntax), or restore it from git: git checkout poad/config.toml', LINKS.install));
|
|
265
|
+
return checks;
|
|
266
|
+
}
|
|
267
|
+
checks.push(ok('project_config', 'poad/config.toml', `${config.project_id || '?'}, engine ${config.engine || '?'}`));
|
|
268
|
+
const container = config.project_uuid;
|
|
269
|
+
let running = false;
|
|
270
|
+
if (info && container) {
|
|
271
|
+
const ps = await sys.exec('docker', ['ps', '--filter', `name=^${container}$`, '--format', '{{.Names}}'], { timeout: 4000 });
|
|
272
|
+
running = ps.code === 0 && ps.stdout.trim() === container;
|
|
273
|
+
}
|
|
274
|
+
if (info && config.engine) {
|
|
275
|
+
const img = `poadio/engine:${config.engine}`;
|
|
276
|
+
const r = await sys.exec('docker', ['image', 'inspect', '--format', '{{.Id}}', img], { timeout: 4000 });
|
|
277
|
+
checks.push(r.code === 0 ? ok('project_image', 'engine image', `${img} present`) : warn('project_image', 'engine image', `${img} not on this machine: poad start pulls it (about 1 GB)`, null, null));
|
|
278
|
+
}
|
|
279
|
+
// Ports : seulement quand le projet ne tourne pas (sinon ils sont à lui)
|
|
280
|
+
if (!running) {
|
|
281
|
+
const ports = [];
|
|
282
|
+
for (const [k, v] of Object.entries(config)) if (v && typeof v === 'object' && Number.isInteger(v.port) && v.port > 0) ports.push([k, v.port]);
|
|
283
|
+
const busy = [];
|
|
284
|
+
for (const [k, p] of ports) if (!(await sys.portFree(p))) busy.push(`${p} (${k})`);
|
|
285
|
+
checks.push(busy.length ? warn('project_ports', 'ports', `used by something else: ${busy.join(', ')}`, 'poad start takes a free port instead and writes it in poad/config.toml; or stop what uses them.', null) : ok('project_ports', 'ports', ports.length ? `${ports.map(([, p]) => p).join(', ')} free` : 'none configured'));
|
|
286
|
+
} else checks.push(ok('project_ports', 'ports', 'the project runs: its ports are its own'));
|
|
287
|
+
// Liaison poad.io : le lien, et une session valide (le jeton n'est jamais montré)
|
|
288
|
+
const id = config.cloud && config.cloud.project;
|
|
289
|
+
if (id) {
|
|
290
|
+
const api = require('./cloud/api');
|
|
291
|
+
let t = null;
|
|
292
|
+
try {
|
|
293
|
+
t = api.currentToken(sys.env);
|
|
294
|
+
} catch {}
|
|
295
|
+
if (!t) checks.push(warn('project_link', 'poad.io link', `linked to ${id}, but no session on this machine`, 'poad login', null));
|
|
296
|
+
else {
|
|
297
|
+
try {
|
|
298
|
+
await (sys.cloudCall || api.call)('GET', `v1/projects/${api.enc(id)}`, { what: 'project', timeout: 5000, env: sys.env });
|
|
299
|
+
checks.push(ok('project_link', 'poad.io link', `${id}, session valid${t.source === 'env' ? ' (POAD_ACCESS_TOKEN)' : ''}`));
|
|
300
|
+
} catch (e) {
|
|
301
|
+
checks.push(warn('project_link', 'poad.io link', `${id}: ${e.status === 401 ? 'session expired or revoked' : e.status === 404 ? 'project not found for this account' : e.message}`, e.status === 401 ? 'poad login' : e.status === 404 ? 'poad link <id> (poad cloud projects lists yours)' : null, null));
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
} else checks.push(ok('project_link', 'poad.io link', 'not linked (poad link <id> to push to poad.io)'));
|
|
305
|
+
return { checks, running, container, config };
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
async function checkCli(sys) {
|
|
309
|
+
const current = require('../package.json').version;
|
|
310
|
+
try {
|
|
311
|
+
const latest = (await (sys.npmLatest ? sys.npmLatest() : sys.json('https://registry.npmjs.org/poad/latest', { timeout: 4000 }))).version;
|
|
312
|
+
if (latest && atLeast(current, latest)) return ok('cli', 'poad CLI', `${current} (latest)`);
|
|
313
|
+
return warn('cli', 'poad CLI', `${current}, ${latest} is out`, `npm i -g poad@${latest}`, 'https://www.npmjs.com/package/poad');
|
|
314
|
+
} catch (e) {
|
|
315
|
+
return ok('cli', 'poad CLI', `${current} (latest version not checked: ${e.message})`);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/** Tous les contrôles ; root : poad/config.toml du dossier courant, ou null */
|
|
320
|
+
async function run(sys = realSys(), { root = null, network = true } = {}) {
|
|
321
|
+
const checks = [checkSystem(sys), checkNode(sys)];
|
|
322
|
+
const [d, git, net, cli] = await Promise.all([checkDocker(sys), checkGit(sys), network ? checkNetwork(sys) : [], network ? checkCli(sys) : null]);
|
|
323
|
+
checks.push(...d.checks, git, ...net);
|
|
324
|
+
let project = null;
|
|
325
|
+
if (root) {
|
|
326
|
+
const p = await checkProject(sys, root, { info: d.info });
|
|
327
|
+
project = Array.isArray(p) ? { checks: p } : p;
|
|
328
|
+
checks.push(...project.checks);
|
|
329
|
+
}
|
|
330
|
+
if (cli) checks.push(cli);
|
|
331
|
+
return { checks, ok: !checks.some((c) => c.status === 'fail'), project };
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/** Contrôles bloquants seulement (poad init, start, link) : Node, Docker démarré, git ; rapide */
|
|
335
|
+
async function preflight(sys = realSys(), { docker = true, git = true } = {}) {
|
|
336
|
+
const checks = [checkNode(sys)];
|
|
337
|
+
const [d, g] = await Promise.all([docker ? checkDocker(sys, { quick: true }) : { checks: [] }, git ? checkGit(sys) : null]);
|
|
338
|
+
checks.push(...d.checks);
|
|
339
|
+
if (g) checks.push(g);
|
|
340
|
+
return { checks, ok: !checks.some((c) => c.status === 'fail'), failed: checks.filter((c) => c.status === 'fail') };
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/** Lignes d'affichage d'un contrôle. Pure. */
|
|
344
|
+
function lines(c, chalk) {
|
|
345
|
+
const mark = c.status === 'ok' ? chalk.greenBright('✔') : c.status === 'warn' ? chalk.yellowBright('⚠') : chalk.redBright('✕');
|
|
346
|
+
const out = [`${mark} ${chalk.bold(c.label)} ${c.status === 'fail' ? chalk.redBright(c.detail) : c.detail}`];
|
|
347
|
+
if (c.fix) out.push(` ${chalk.grey('→')} ${c.fix}`);
|
|
348
|
+
if (c.link && c.status !== 'ok') out.push(` ${chalk.grey(c.link)}`);
|
|
349
|
+
return out;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Avant poad init / start / link : les contrôles bloquants ; un ✕ arrête la commande avec un message clair.
|
|
354
|
+
* Rend true si tout va bien. POAD_SKIP_PREFLIGHT=1 : rien (tests, CI particulière).
|
|
355
|
+
*/
|
|
356
|
+
async function guard(what, { docker = true, git = true, sys } = {}) {
|
|
357
|
+
if (process.env.POAD_SKIP_PREFLIGHT === '1') return true;
|
|
358
|
+
const r = await preflight(sys || realSys(), { docker, git });
|
|
359
|
+
if (r.ok) return true;
|
|
360
|
+
const chalk = require('chalk-v2');
|
|
361
|
+
console.error(chalk.redBright(`poad ${what} cannot run on this machine yet:`));
|
|
362
|
+
for (const c of r.failed) for (const l of lines(c, chalk)) console.error(` ${l}`);
|
|
363
|
+
console.error(chalk.grey(' "poad doctor" checks everything (network, disk, project…).'));
|
|
364
|
+
process.exitCode = 1;
|
|
365
|
+
return false;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
module.exports = { run, preflight, guard, lines, atLeast, minNode, realSys, checkDocker, checkGit, checkNode, checkSystem, checkNetwork, checkProject, checkCli, LINKS };
|
package/utils/graphql.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// GraphQL du projet (/graphql/v1, engine 0.79.0+) : réglages de poad/config.toml passés en variables
|
|
2
|
+
// d'environnement par `poad start`. Les mêmes en local et sur poad.io (où l'engine lit lui-même config.toml).
|
|
3
|
+
//
|
|
4
|
+
// [graphql]
|
|
5
|
+
// enabled = true /graphql/v1 servi
|
|
6
|
+
// introspection = "dev" "dev" : ouverte en développement, réservée à service_role en production ;
|
|
7
|
+
// "on" : pour tous ; "off" : pour personne
|
|
8
|
+
// max_depth = 16 niveaux de champs imbriqués au plus
|
|
9
|
+
// max_rows = 1000 lignes par page au plus (first, last), le plafond de /rest/v1
|
|
10
|
+
// max_query_size = 65536 taille du texte d'une requête, en octets (ou "64KB")
|
|
11
|
+
// max_fields = 2000 champs au plus dans une requête
|
|
12
|
+
//
|
|
13
|
+
// En local, poad/config.toml n'est pas monté dans l'engine : le service data ne lit que ces variables. Une valeur
|
|
14
|
+
// illisible est passée telle quelle : l'engine garde son défaut et le dit au journal (poad logs data).
|
|
15
|
+
|
|
16
|
+
const KEYS = {
|
|
17
|
+
enabled: 'POAD_GRAPHQL_ENABLED',
|
|
18
|
+
introspection: 'POAD_GRAPHQL_INTROSPECTION',
|
|
19
|
+
max_depth: 'POAD_GRAPHQL_MAX_DEPTH',
|
|
20
|
+
max_rows: 'POAD_GRAPHQL_MAX_ROWS',
|
|
21
|
+
max_query_size: 'POAD_GRAPHQL_MAX_QUERY_SIZE',
|
|
22
|
+
max_fields: 'POAD_GRAPHQL_MAX_FIELDS',
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/** Section écrite par poad init : les défauts de l'engine, versionnés avec le projet */
|
|
26
|
+
const DEFAULTS = { enabled: true, introspection: 'dev', max_depth: 16, max_rows: 1000 };
|
|
27
|
+
|
|
28
|
+
/** Variables de l'engine : une par réglage présent (booléen, nombre ou texte sur une ligne) */
|
|
29
|
+
const engineEnv = (config) => {
|
|
30
|
+
const section = config && config.graphql && typeof config.graphql === 'object' ? config.graphql : {};
|
|
31
|
+
const out = [];
|
|
32
|
+
for (const [key, name] of Object.entries(KEYS)) {
|
|
33
|
+
const v = section[key];
|
|
34
|
+
if (typeof v === 'boolean') out.push(`${name}=${v ? 1 : 0}`);
|
|
35
|
+
else if (typeof v === 'number' && Number.isFinite(v)) out.push(`${name}=${v}`);
|
|
36
|
+
else if (typeof v === 'string' && v.trim() && !/[\r\n]/.test(v)) out.push(`${name}=${v.trim()}`);
|
|
37
|
+
}
|
|
38
|
+
return out;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
module.exports = { engineEnv, DEFAULTS, KEYS };
|
package/utils/help-details.js
CHANGED
|
@@ -120,6 +120,7 @@ const sheets = {
|
|
|
120
120
|
['upload=<id>', 'a chunked storage upload (storage 0.6+): started, interrupted, resumed, finished, cancelled or abandoned'],
|
|
121
121
|
['bucket=<id>', 'the lines about a storage bucket: uploads, upload rules, objects read by a flow step or that started a flow (engine 0.70.1+)'],
|
|
122
122
|
['object=<path>', 'an object of a bucket: read by a flow step (GET …/object), or that started a flow (engine 0.70.1+)'],
|
|
123
|
+
['operation=<name>', 'a GraphQL operation (engine 0.79.0+): its requests to /graphql/v1, with role, query or mutation, duration and error; anonymous for an unnamed one'],
|
|
123
124
|
['trigger=<kind>', 'runs started by a kind of trigger: webhook, client, cron, storage (engine 0.70.1+), database (engine 0.71.0+)'],
|
|
124
125
|
['limit=100', 'number of lines, from 1 to 10000'],
|
|
125
126
|
['-f, --follow', 'follow live'],
|
|
@@ -427,6 +428,23 @@ Object.assign(sheets, {
|
|
|
427
428
|
text: ['Forget the poad.io session of this machine (~/.poad/credentials.json). The token is not revoked by the CLI: revoke it on poad.io (account, CLI sessions) if it may have leaked.'],
|
|
428
429
|
options: [JSON_OPT],
|
|
429
430
|
},
|
|
431
|
+
doctor: {
|
|
432
|
+
usage: ['poad doctor [--json] [--offline]'],
|
|
433
|
+
text: [
|
|
434
|
+
'Check this machine for poad, one line per check (✔ fine, ⚠ warning, ✕ blocking), each problem with what to do and a link: the system (macOS and Linux; Windows in beta), Node.js, Docker (installed, started, daemon version, architecture, free room of its storage, memory of its VM on macOS and Windows), git, the network (Docker Hub, the permalink on raw.githubusercontent.com, poad.io) and the CLI version.',
|
|
435
|
+
'Linux: Docker Engine is enough (no Docker Desktop); your user must be allowed on the Docker socket (docker group), the daemon run (systemd), Docker be 20.10 or later (host-gateway); the free room is read on the disk of /var/lib/docker. Windows: Docker Desktop with WSL2, and git.',
|
|
436
|
+
'In a project folder, also: poad/config.toml readable, the engine image of the project on this machine, its ports free (when it is stopped), and its poad.io link with a valid session. The session token is never shown.',
|
|
437
|
+
],
|
|
438
|
+
options: [
|
|
439
|
+
['--json', 'the checks as JSON: { ok, platform, checks: [{ id, status: ok|warn|fail, label, detail, fix, link }] }'],
|
|
440
|
+
['--offline', 'skip the network checks and the latest CLI version'],
|
|
441
|
+
],
|
|
442
|
+
notes: [
|
|
443
|
+
'poad init, poad start and poad link run the blocking checks first (Node.js, git; Docker started for init and start), in less than a second, and stop with the same message instead of an obscure error.',
|
|
444
|
+
'Prerequisites of poad: Node.js, Docker and git. psql is not needed (the engine has its own).',
|
|
445
|
+
'Exit codes: 0 ready (warnings allowed), 1 at least one blocking problem, 2 usage.',
|
|
446
|
+
],
|
|
447
|
+
},
|
|
430
448
|
whoami: { usage: ['poad whoami [--json]'], text: ['The poad.io account of the session, and where the session comes from (poad login or POAD_ACCESS_TOKEN).'], options: [JSON_OPT], notes: [EXIT_NOTE] },
|
|
431
449
|
cloud: {
|
|
432
450
|
usage: ['poad cloud <subcommand> [--json]'],
|
package/utils/logline.js
CHANGED
|
@@ -5,8 +5,8 @@ const LEVELS = ['debug', 'info', 'warn', 'error', 'fatal'];
|
|
|
5
5
|
|
|
6
6
|
// Options de filtre → attribut de la ligne (attrs). Mêmes noms et même sens
|
|
7
7
|
// que les paramètres de /logs/v1 (services/logs/src/api.ts de l'infra).
|
|
8
|
-
const ATTR_OPTIONS = { flow: 'flow', step: 'step', function: 'function', tool: 'tool', outcome: 'outcome', provider: 'provider', model: 'model', event: 'event', table: 'table', channel: 'channel', front: 'front', page: 'page', source: 'source_name', upload: 'upload_id', bucket: 'bucket', object: 'object', trigger: 'trigger_kind', connection: 'connection', action: 'action', type: 'connection_type', host: 'host', user: 'user_id', device: 'device', transform: 'model' };
|
|
9
|
-
const EXAMPLES = { flow: 'demo-flux', step: 'appel', function: 'demo-stats', tool: 'select_rows', outcome: 'refused', provider: 'anthropic', model: 'claude-opus-5-5', event: 'ai_default_model_changed', table: 'notes', channel: 'notes', front: 'k3x9q2m7a1bc', page: 'accueil', source: 'communes', upload: '0b8e8f7e-1b2c-4d5e-8f90-123456789abc', bucket: 'documents', object: 'releves/mars.csv', trigger: 'storage', connection: 'sncf', action: 'create_task', type: 'todoist', host: 'api.sncf.com', user: '4dbcaf19-7549-4c48-a3ad-f6bc173d3c48', device: 'alice-tel', transform: 'ventes_par_mois' };
|
|
8
|
+
const ATTR_OPTIONS = { flow: 'flow', step: 'step', function: 'function', tool: 'tool', outcome: 'outcome', provider: 'provider', model: 'model', event: 'event', table: 'table', channel: 'channel', front: 'front', page: 'page', source: 'source_name', upload: 'upload_id', bucket: 'bucket', object: 'object', trigger: 'trigger_kind', connection: 'connection', action: 'action', type: 'connection_type', host: 'host', user: 'user_id', device: 'device', transform: 'model', operation: 'operation' };
|
|
9
|
+
const EXAMPLES = { flow: 'demo-flux', step: 'appel', function: 'demo-stats', tool: 'select_rows', outcome: 'refused', provider: 'anthropic', model: 'claude-opus-5-5', event: 'ai_default_model_changed', table: 'notes', channel: 'notes', front: 'k3x9q2m7a1bc', page: 'accueil', source: 'communes', upload: '0b8e8f7e-1b2c-4d5e-8f90-123456789abc', bucket: 'documents', object: 'releves/mars.csv', trigger: 'storage', connection: 'sncf', action: 'create_task', type: 'todoist', host: 'api.sncf.com', user: '4dbcaf19-7549-4c48-a3ad-f6bc173d3c48', device: 'alice-tel', transform: 'ventes_par_mois', operation: 'ListeNotes' };
|
|
10
10
|
// Identifiant d'exécution (UUID) entier, ou son début : 8 caractères au moins
|
|
11
11
|
const RUN_RE = /^[0-9a-f-]{8,36}$/;
|
|
12
12
|
|
|
@@ -236,6 +236,8 @@ const formatLine = (r, chalk) => {
|
|
|
236
236
|
// La durée d'une requête lente de Postgres est déjà dans son message, celle d'un appel MCP aussi
|
|
237
237
|
if (a.duration_ms !== undefined && r.service !== 'postgres' && !(mcp && mcp.ms)) extra.push(`${a.duration_ms} ms`);
|
|
238
238
|
if (a.role) extra.push(a.role);
|
|
239
|
+
// GraphQL (engine 0.79.0+) : l'opération et son type
|
|
240
|
+
if (a.operation) extra.push(chalk.cyan(`${a.operation_type || 'graphql'} ${a.operation}`));
|
|
239
241
|
if (r.service === 'meta' && /^mcp_token_/.test(a.event || '')) extra.push(...tokenChange(a, chalk));
|
|
240
242
|
if (a.error_code || a.error) extra.push(chalk.yellow([a.error_code, a.error].filter(Boolean).join(': ')));
|
|
241
243
|
if (a.err && a.err.message) extra.push(chalk.redBright(a.err.message));
|