poad 2.49.1 → 2.51.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/global/start.js +13 -2
- package/package.json +1 -1
- package/project/cli.js +3 -1
- package/project/env/clone.js +30 -0
- package/project/env/create.js +16 -5
- package/project/env/sync.js +2 -0
- package/project/logs.js +2 -0
- package/test/cloud.test.js +29 -1
- package/test/fronts.test.js +173 -0
- package/utils/cloud/cli.js +5 -3
- package/utils/cloud/clone.js +28 -0
- package/utils/fronts.js +213 -0
- package/utils/help-details.js +4 -2
- package/utils/logline.js +2 -2
- package/utils/report.js +12 -0
- package/utils/tomlfile.js +3 -2
package/global/start.js
CHANGED
|
@@ -44,7 +44,7 @@ module.exports = async (args = {}) => {
|
|
|
44
44
|
require('../utils/console-services').write(root);
|
|
45
45
|
if (targets.length) await require('./run')({ services: targets.map((s) => s.id), quiet: true });
|
|
46
46
|
console.log(' ');
|
|
47
|
-
await require('../utils/report').printReport(root, require('../utils/config').loadConfig(root));
|
|
47
|
+
await require('../utils/report').printReport(root, require('../utils/config').loadConfig(root), { justStarted: true });
|
|
48
48
|
};
|
|
49
49
|
|
|
50
50
|
// --quiet : rien à dire ni à faire si le projet tourne déjà (bun start du front)
|
|
@@ -95,13 +95,21 @@ module.exports = async (args = {}) => {
|
|
|
95
95
|
await logs.ensureGelfPort(root, config);
|
|
96
96
|
if (mailpit) await mail.stopMailpit(docker, config);
|
|
97
97
|
const { reassignBusyPorts, describeMoves } = require('../utils/ports');
|
|
98
|
+
// Fronts (engine 0.46.0+) : un port par front, et une réserve pour ceux que la
|
|
99
|
+
// console crée pendant que le projet tourne (un port ne s'ajoute pas à un conteneur lancé)
|
|
100
|
+
const fronts = require('../utils/fronts');
|
|
101
|
+
const withFronts = fronts.supportsFronts(config);
|
|
102
|
+
if (withFronts) await fronts.ensureSpare(root, config);
|
|
98
103
|
const moved = await reassignBusyPorts(root, config, [
|
|
99
104
|
{ section: 'db', key: 'port', label: 'Database' },
|
|
100
105
|
{ section: 'web', key: 'port', label: 'API' },
|
|
101
106
|
...(mailpit ? [{ section: 'mail', key: 'port', label: 'Mailpit' }] : []),
|
|
102
107
|
{ section: 'logs', key: 'gelf_port', label: 'Logs collector', udp: true },
|
|
108
|
+
...(withFronts ? fronts.busyEntries(config) : []),
|
|
103
109
|
]);
|
|
110
|
+
if (withFronts) fronts.foldMoved(config);
|
|
104
111
|
describeMoves(moved).forEach((line) => console.log(chalk.yellowBright(` ${line}`)));
|
|
112
|
+
const frontPorts = withFronts ? fronts.bindings(config) : { exposed: {}, bindings: {} };
|
|
105
113
|
|
|
106
114
|
const progress = ora('Starting containers').start();
|
|
107
115
|
try {
|
|
@@ -144,14 +152,17 @@ module.exports = async (args = {}) => {
|
|
|
144
152
|
...gateway.engineEnv(config),
|
|
145
153
|
// Socle IA : [ai] de poad/config.toml (engine 0.30.0+ ; un engine plus ancien les ignore)
|
|
146
154
|
...aiSettings.env,
|
|
155
|
+
// Fronts : port de chacun, réserve, nom du projet (page « En construction »)
|
|
156
|
+
...(withFronts ? fronts.engineEnv(config) : []),
|
|
147
157
|
],
|
|
148
|
-
ExposedPorts: { '5432/tcp': {}, '8000/tcp': {}, ...gelf.exposed },
|
|
158
|
+
ExposedPorts: { '5432/tcp': {}, '8000/tcp': {}, ...gelf.exposed, ...frontPorts.exposed },
|
|
149
159
|
HostConfig: {
|
|
150
160
|
NetworkMode: net.NetworkMode,
|
|
151
161
|
PortBindings: {
|
|
152
162
|
'5432/tcp': [{ HostIp: require('../utils/ports').hostIp(config), HostPort: config.db.port.toString() }],
|
|
153
163
|
'8000/tcp': [{ HostIp: require('../utils/ports').hostIp(config), HostPort: config.web.port.toString() }],
|
|
154
164
|
...gelf.bindings,
|
|
165
|
+
...frontPorts.bindings,
|
|
155
166
|
},
|
|
156
167
|
// poad/migrations monté : la console y écrit les migrations qu'elle crée.
|
|
157
168
|
// poad/auth et poad/storage : manifestes versionnés des réglages d'auth et des buckets.
|
package/package.json
CHANGED
package/project/cli.js
CHANGED
|
@@ -28,7 +28,9 @@ module.exports = {
|
|
|
28
28
|
env: {
|
|
29
29
|
description: 'Environments (branches) of the linked poad.io project: main is production',
|
|
30
30
|
ls: 'Environments of the project; the default of poad deploy is the current git branch if it exists there, else main',
|
|
31
|
-
create: 'Create an environment: env create <name> [--kind persistent|preview]',
|
|
31
|
+
create: 'Create an environment, a clone of production by default: env create <name> [--kind persistent|preview] [--empty] [--with-data] [--credential <name>=production|custom]',
|
|
32
|
+
clone: 'Reclone an environment from production (everything but the data; --with-data: all of it): env clone <name> [--with-data] [--credential <name>=production|custom]',
|
|
33
|
+
sync: 'Old name of env clone',
|
|
32
34
|
rm: 'Remove an environment, its database and files (confirmation, --yes); never main',
|
|
33
35
|
},
|
|
34
36
|
deploy: 'Send poad/ (migrations, functions, flows, api, auth, storage…, never a secret) to poad.io: deploy [--env <name>] [--dry-run] [--yes]',
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// poad env clone <nom> [--with-data] [--credential <nom>=production|custom]… [--yes] [--project <id>] [--json]
|
|
2
|
+
// POST v1/projects/:id/branches/:nom/clone { with_data, credentials } : recloner un
|
|
3
|
+
// environnement depuis la production. Ce qu'il a en propre est remplacé (ses
|
|
4
|
+
// données seulement avec --with-data, alias --copy-data). La production n'est que lue.
|
|
5
|
+
module.exports = (args, raw) =>
|
|
6
|
+
require('../../utils/cloud/cli').run(raw, { values: ['project', 'credential'], multi: ['credential'], flags: ['copy-data', 'with-data'] }, async ({ opts, positionals, out }) => {
|
|
7
|
+
const api = require('../../utils/cloud/api');
|
|
8
|
+
const cli = require('../../utils/cloud/cli');
|
|
9
|
+
const clone = require('../../utils/cloud/clone');
|
|
10
|
+
const { chalk } = out;
|
|
11
|
+
if (positionals.length !== 1) throw api.usageError('Usage: poad env clone <name> [--with-data] [--credential <name>=production|custom]');
|
|
12
|
+
const name = cli.checkBranch(positionals[0]);
|
|
13
|
+
if (name === 'main') throw api.usageError('main is production: it is the source, never the target');
|
|
14
|
+
const withData = Boolean(opts['with-data'] || opts['copy-data']);
|
|
15
|
+
const credentials = clone.credentialChoices(opts.credential);
|
|
16
|
+
const { id } = cli.targetProject(opts);
|
|
17
|
+
await cli.confirm(
|
|
18
|
+
`Reclone ${name} from production (${clone.SUMMARY}${withData ? ', and all its data' : ''})? What ${name} has of its own is replaced.`,
|
|
19
|
+
{ yes: opts.yes, json: out.json },
|
|
20
|
+
);
|
|
21
|
+
const r = await api.call('POST', `v1/projects/${api.enc(id)}/branches/${api.enc(name)}/clone`, {
|
|
22
|
+
body: { with_data: withData, ...(Object.keys(credentials).length ? { credentials } : {}) },
|
|
23
|
+
what: `clone of production into ${name}`,
|
|
24
|
+
timeout: 60000,
|
|
25
|
+
});
|
|
26
|
+
const kept = (r && Array.isArray(r.credentials_with_values) && r.credentials_with_values) || [];
|
|
27
|
+
out.log(`${chalk.greenBright('✔')} Clone of production into ${chalk.bold(name)} started${withData ? ' (with the data)' : ''}: "poad env ls" to follow.`);
|
|
28
|
+
if (kept.length) out.log(chalk.grey(` Credentials with the production value (same external accounts): ${kept.join(', ')}.`));
|
|
29
|
+
out.result({ id, name, with_data: withData, credentials_with_values: kept });
|
|
30
|
+
});
|
package/project/env/create.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
// poad env create <nom> [--kind persistent|preview] [--project <id>] [--json]
|
|
2
|
-
// POST v1/projects/:id/branches { name, kind }
|
|
1
|
+
// poad env create <nom> [--kind persistent|preview] [--empty] [--with-data] [--credential <nom>=production|custom]… [--project <id>] [--json]
|
|
2
|
+
// POST v1/projects/:id/branches { name, kind, clone, with_data, credentials }
|
|
3
|
+
// Par défaut, un clone de la production (comme la console) : tout sauf les
|
|
4
|
+
// données ; --with-data (alias --copy-data) : avec toutes les données (tables,
|
|
5
|
+
// utilisateurs, fichiers) ; --empty : un environnement vide. --credential :
|
|
6
|
+
// un choix par credential (sans lui : le défaut de poad.io).
|
|
3
7
|
module.exports = (args, raw) =>
|
|
4
|
-
require('../../utils/cloud/cli').run(raw, { values: ['project', 'kind'] }, async ({ opts, positionals, out }) => {
|
|
8
|
+
require('../../utils/cloud/cli').run(raw, { values: ['project', 'kind', 'credential'], multi: ['credential'], flags: ['copy-data', 'with-data', 'empty', 'clone'] }, async ({ opts, positionals, out }) => {
|
|
5
9
|
const api = require('../../utils/cloud/api');
|
|
6
10
|
const cli = require('../../utils/cloud/cli');
|
|
7
11
|
const branches = require('../../utils/cloud/branches');
|
|
@@ -11,9 +15,16 @@ module.exports = (args, raw) =>
|
|
|
11
15
|
const kind = opts.kind || 'persistent';
|
|
12
16
|
if (!['persistent', 'preview'].includes(kind)) throw api.usageError('--kind is persistent or preview');
|
|
13
17
|
const { id } = cli.targetProject(opts);
|
|
14
|
-
|
|
18
|
+
if (opts.empty && (opts.clone || opts['with-data'] || opts['copy-data'] || opts.credential)) throw api.usageError('--empty creates an empty environment: no --clone, --with-data nor --credential');
|
|
19
|
+
const clone = !opts.empty;
|
|
20
|
+
const withData = clone && Boolean(opts['with-data'] || opts['copy-data']);
|
|
21
|
+
const credentials = clone ? require('../../utils/cloud/clone').credentialChoices(opts.credential) : {};
|
|
22
|
+
const body = clone ? { name, kind, clone: true, ...(withData ? { with_data: true } : {}), ...(Object.keys(credentials).length ? { credentials } : {}) } : { name, kind, clone: false };
|
|
23
|
+
const data = await api.call('POST', `v1/projects/${api.enc(id)}/branches`, { body, what: `environment ${name}`, timeout: 60000 });
|
|
15
24
|
const b = branches.normalize(data.branch || data) || { name, kind };
|
|
16
25
|
out.log(`${chalk.greenBright('✔')} Environment ${chalk.bold(b.name)} created on ${id} ${chalk.grey(`(${b.kind || kind}${b.status ? `, ${b.status}` : ''})`)}.`);
|
|
26
|
+
if (clone) out.log(chalk.grey(` Production clone: ${require('../../utils/cloud/clone').SUMMARY}${withData ? ', and all its data (tables, users, files)' : ', no data'}; "poad env ls" to follow.`));
|
|
27
|
+
else out.log(chalk.grey(' Empty: its first "poad deploy --env" applies the migrations, then poad/seed.sql.'));
|
|
17
28
|
out.log(chalk.grey(` "poad deploy --env ${b.name}" deploys to it (also by default from the git branch ${b.name}).`));
|
|
18
|
-
out.result(b);
|
|
29
|
+
out.result({ ...b, clone, with_data: withData, credentials });
|
|
19
30
|
});
|
package/project/logs.js
CHANGED
|
@@ -27,6 +27,8 @@
|
|
|
27
27
|
// poad logs data event=realtime_change les changements livrés (realtime_subscribed,
|
|
28
28
|
// realtime_unsubscribed, realtime_joined, realtime_left,
|
|
29
29
|
// realtime_closed, realtime_error, realtime_change_summary)
|
|
30
|
+
// poad logs app front=<id> un front dessiné dans poad (engine 0.46+) : le serveur du moteur
|
|
31
|
+
// et le navigateur (source=server|browser) ; page=<id> pour une page
|
|
30
32
|
// poad logs limit=500 nombre de lignes (100 par défaut)
|
|
31
33
|
// poad logs -f | --follow suivi en direct
|
|
32
34
|
// poad logs --json une ligne JSON par entrée (pour jq)
|
package/test/cloud.test.js
CHANGED
|
@@ -95,6 +95,7 @@ function fakeCloud(t, behaviour = {}) {
|
|
|
95
95
|
state.branches[id] = state.branches[id].filter((b) => b.name !== branch);
|
|
96
96
|
return send(res, 200, { removed: branch });
|
|
97
97
|
}
|
|
98
|
+
if (req.method === 'POST' && (m[2] === '/clone' || m[2] === '/sync')) return send(res, 200, { name: branch, status: 'active', status_detail: 'copie depuis la production : measure', credentials_with_values: ['claude'] });
|
|
98
99
|
if (req.method === 'POST' && m[2] === '/deploy') {
|
|
99
100
|
const dry = req.headers['x-poad-dry-run'] === '1';
|
|
100
101
|
if (behaviour.async) {
|
|
@@ -399,9 +400,36 @@ test('env ls / create / rm : confirmation, --yes, main jamais supprimé', async
|
|
|
399
400
|
|
|
400
401
|
const c = await poad(box, cloud.api, ['env', 'create', 'feature/x', '--kind', 'preview', '--json']);
|
|
401
402
|
assert.strictEqual(c.status, 0, c.all);
|
|
402
|
-
|
|
403
|
+
// Par défaut, un clone de la production (comme la console), sans les données
|
|
404
|
+
assert.deepStrictEqual(JSON.parse(cloud.requests.at(-1).body), { name: 'feature/x', kind: 'preview', clone: true });
|
|
403
405
|
const badKind = await poad(box, cloud.api, ['env', 'create', 'y', '--kind', 'forever']);
|
|
404
406
|
assert.strictEqual(badKind.status, 2);
|
|
407
|
+
// --with-data (alias --copy-data) et un choix par credential (répétable, ou séparé par des virgules)
|
|
408
|
+
const withData = await poad(box, cloud.api, ['env', 'create', 'recette', '--with-data', '--credential', 'smtp-prod=custom', '--credential', 'claude=production', '--json']);
|
|
409
|
+
assert.strictEqual(withData.status, 0, withData.all);
|
|
410
|
+
assert.deepStrictEqual(JSON.parse(cloud.requests.at(-1).body), { name: 'recette', kind: 'persistent', clone: true, with_data: true, credentials: { 'smtp-prod': 'custom', claude: 'production' } });
|
|
411
|
+
const legacy = await poad(box, cloud.api, ['env', 'create', 'qa', '--copy-data', '--json']);
|
|
412
|
+
assert.deepStrictEqual(JSON.parse(cloud.requests.at(-1).body), { name: 'qa', kind: 'persistent', clone: true, with_data: true }, legacy.all);
|
|
413
|
+
// --empty : vide ; incompatible avec les options du clone
|
|
414
|
+
const empty = await poad(box, cloud.api, ['env', 'create', 'vide', '--empty', '--json']);
|
|
415
|
+
assert.strictEqual(empty.status, 0, empty.all);
|
|
416
|
+
assert.deepStrictEqual(JSON.parse(cloud.requests.at(-1).body), { name: 'vide', kind: 'persistent', clone: false });
|
|
417
|
+
assert.strictEqual((await poad(box, cloud.api, ['env', 'create', 'x', '--empty', '--with-data'])).status, 2);
|
|
418
|
+
assert.strictEqual((await poad(box, cloud.api, ['env', 'create', 'x', '--credential', 'smtp=copie'])).status, 2);
|
|
419
|
+
|
|
420
|
+
// Recloner depuis la production : confirmation, --yes, jamais main ; sync reste un alias
|
|
421
|
+
const syncNoYes = await poad(box, cloud.api, ['env', 'clone', 'dev']);
|
|
422
|
+
assert.strictEqual(syncNoYes.status, 4);
|
|
423
|
+
assert.ok(!cloud.requests.some((q) => q.route.endsWith('/clone')));
|
|
424
|
+
const sync = await poad(box, cloud.api, ['env', 'clone', 'dev', '--with-data', '--credential', 'claude=production', '--yes', '--json']);
|
|
425
|
+
assert.strictEqual(sync.status, 0, sync.all);
|
|
426
|
+
assert.strictEqual(cloud.requests.at(-1).route, `v1/projects/${PID}/branches/dev/clone`);
|
|
427
|
+
assert.deepStrictEqual(JSON.parse(cloud.requests.at(-1).body), { with_data: true, credentials: { claude: 'production' } });
|
|
428
|
+
const alias = await poad(box, cloud.api, ['env', 'sync', 'dev', '--yes', '--json']);
|
|
429
|
+
assert.strictEqual(alias.status, 0, alias.all);
|
|
430
|
+
assert.deepStrictEqual(JSON.parse(cloud.requests.at(-1).body), { with_data: false });
|
|
431
|
+
const syncMain = await poad(box, cloud.api, ['env', 'sync', 'main', '--yes']);
|
|
432
|
+
assert.strictEqual(syncMain.status, 2);
|
|
405
433
|
|
|
406
434
|
const noYes = await poad(box, cloud.api, ['env', 'rm', 'feature/x']);
|
|
407
435
|
assert.strictEqual(noYes.status, 4);
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
// Fronts dessinés dans poad : un port par front dans poad/config.toml, réserve,
|
|
2
|
+
// variables et ports de l'engine, suivi des fronts créés depuis la console.
|
|
3
|
+
const { test } = require('node:test');
|
|
4
|
+
const assert = require('node:assert');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const os = require('os');
|
|
7
|
+
const path = require('path');
|
|
8
|
+
const toml = require('toml');
|
|
9
|
+
const fronts = require('../utils/fronts');
|
|
10
|
+
const { setInText, removeSectionInText } = require('../utils/tomlfile');
|
|
11
|
+
const { attrConditions } = require('../utils/logline');
|
|
12
|
+
|
|
13
|
+
const A = 'k3x9q2m7a1bc';
|
|
14
|
+
const B = 'zq8w7e6r5t4y';
|
|
15
|
+
|
|
16
|
+
const project = (text) => {
|
|
17
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'poad-fronts-'));
|
|
18
|
+
const file = path.join(dir, 'config.toml');
|
|
19
|
+
fs.writeFileSync(file, text);
|
|
20
|
+
return file;
|
|
21
|
+
};
|
|
22
|
+
const parse = (file) => toml.parse(fs.readFileSync(file, 'utf-8'));
|
|
23
|
+
const BASE = 'project_id = "bdtheque"\nengine = "0.46.0"\n\n[db]\nport = 15432\n\n[web]\nport = 18000\n';
|
|
24
|
+
|
|
25
|
+
test('tomlfile : tableau sur une ligne, section imbriquée, retrait', () => {
|
|
26
|
+
let text = setInText(BASE, 'fronts', { spare_ports: [41001, 41002] });
|
|
27
|
+
text = setInText(text, `fronts.${A}`, { port: 41003 });
|
|
28
|
+
const c = toml.parse(text);
|
|
29
|
+
assert.deepStrictEqual(c.fronts.spare_ports, [41001, 41002]);
|
|
30
|
+
assert.strictEqual(c.fronts[A].port, 41003);
|
|
31
|
+
// La réserve se réécrit sans toucher à la section du front qui suit
|
|
32
|
+
text = setInText(text, 'fronts', { spare_ports: [41002] });
|
|
33
|
+
assert.match(text, /spare_ports = \[41002\]/);
|
|
34
|
+
assert.strictEqual(toml.parse(text).fronts[A].port, 41003);
|
|
35
|
+
text = removeSectionInText(text, `fronts.${A}`);
|
|
36
|
+
assert.strictEqual(toml.parse(text).fronts[A], undefined);
|
|
37
|
+
assert.strictEqual(toml.parse(text).web.port, 18000);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test('read : identifiants valides seulement, réserve sans doublon ni port de front', () => {
|
|
41
|
+
const s = fronts.read({ fronts: { spare_ports: [41001, 41001, 41003, 'x'], [A]: { port: 41003 }, 'Pas-un-id': { port: 41005 }, [B]: { port: 0 } } });
|
|
42
|
+
assert.deepStrictEqual(s.fronts, [{ id: A, port: 41003 }]);
|
|
43
|
+
assert.deepStrictEqual(s.spare, [41001]);
|
|
44
|
+
assert.deepStrictEqual(fronts.read({}), { fronts: [], spare: [] });
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('ensureSpare : deux ports libres, jamais un port du projet, écrits dans config.toml', async () => {
|
|
48
|
+
const file = project(BASE);
|
|
49
|
+
const config = parse(file);
|
|
50
|
+
const offered = [18000, 15432, 41001, 41001, 41002];
|
|
51
|
+
const added = await fronts.ensureSpare(file, config, { findFreePorts: async () => [offered.shift()], isPortFree: async () => true });
|
|
52
|
+
assert.deepStrictEqual(added, [41001, 41002]);
|
|
53
|
+
assert.deepStrictEqual(parse(file).fronts.spare_ports, [41001, 41002]);
|
|
54
|
+
assert.deepStrictEqual(config.fronts.spare_ports, [41001, 41002]);
|
|
55
|
+
// Déjà complète : rien d'ajouté ; un port de réserve pris ailleurs est remplacé
|
|
56
|
+
assert.deepStrictEqual(await fronts.ensureSpare(file, config, { findFreePorts: async () => [41009], isPortFree: async () => true }), []);
|
|
57
|
+
const again = await fronts.ensureSpare(file, config, { findFreePorts: async () => [41009], isPortFree: async (p) => p !== 41001 });
|
|
58
|
+
assert.deepStrictEqual(again, [41009]);
|
|
59
|
+
assert.deepStrictEqual(parse(file).fronts.spare_ports, [41002, 41009]);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test('busyEntries et foldMoved : un port de front déplacé revient dans config.fronts', () => {
|
|
63
|
+
const config = { fronts: { spare_ports: [], [A]: { port: 41003 } } };
|
|
64
|
+
const entries = fronts.busyEntries(config);
|
|
65
|
+
assert.deepStrictEqual(entries, [{ section: `fronts.${A}`, key: 'port', label: `Front ${A}` }]);
|
|
66
|
+
config[`fronts.${A}`] = { port: 42000 }; // ce que fait reassignBusyPorts
|
|
67
|
+
fronts.foldMoved(config);
|
|
68
|
+
assert.strictEqual(config.fronts[A].port, 42000);
|
|
69
|
+
assert.strictEqual(config[`fronts.${A}`], undefined);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('engineEnv et bindings : tous les ports vers 8100/tcp, même interface que les autres', () => {
|
|
73
|
+
const config = { project_id: 'bdtheque', web: { port: 18000 }, fronts: { spare_ports: [41001, 41002], [A]: { port: 41003 } } };
|
|
74
|
+
assert.deepStrictEqual(fronts.engineEnv(config), [`POAD_FRONT_PORTS=${A}=41003`, 'POAD_FRONT_SPARE_PORTS=41001,41002', 'POAD_PROJECT_NAME=bdtheque']);
|
|
75
|
+
const b = fronts.bindings(config);
|
|
76
|
+
assert.deepStrictEqual(b.exposed, { '8100/tcp': {} });
|
|
77
|
+
assert.deepStrictEqual(b.bindings['8100/tcp'], [
|
|
78
|
+
{ HostIp: '127.0.0.1', HostPort: '41003' },
|
|
79
|
+
{ HostIp: '127.0.0.1', HostPort: '41001' },
|
|
80
|
+
{ HostIp: '127.0.0.1', HostPort: '41002' },
|
|
81
|
+
]);
|
|
82
|
+
assert.strictEqual(fronts.bindings({ ...config, web: { port: 18000, expose: true } }).bindings['8100/tcp'][0].HostIp, '0.0.0.0');
|
|
83
|
+
assert.deepStrictEqual(fronts.bindings({}), { exposed: {}, bindings: {} });
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test('supportsFronts : engine 0.46.0 et plus (0.45.0 publiée sans les fronts)', () => {
|
|
87
|
+
assert.strictEqual(fronts.supportsFronts({ engine: '0.44.2' }), false);
|
|
88
|
+
assert.strictEqual(fronts.supportsFronts({ engine: '0.45.0' }), false);
|
|
89
|
+
assert.strictEqual(fronts.supportsFronts({ engine: '0.46.0' }), true);
|
|
90
|
+
assert.strictEqual(fronts.supportsFronts({ engine: '1.0.0' }), true);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const fakeFetch = (body, status = 200) => {
|
|
94
|
+
const calls = [];
|
|
95
|
+
const fn = async (url, init) => {
|
|
96
|
+
calls.push({ url, init });
|
|
97
|
+
return { ok: status < 400, status, json: async () => body };
|
|
98
|
+
};
|
|
99
|
+
fn.calls = calls;
|
|
100
|
+
return fn;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
test('sync : un front créé depuis la console prend sa section, son port quitte la réserve ; un front supprimé part', async () => {
|
|
104
|
+
const file = project(`${BASE}\n[fronts]\nspare_ports = [41001, 41002]\n\n[fronts.${B}]\nport = 41000\n`);
|
|
105
|
+
const config = { ...parse(file), auth: { service: 'svc' } };
|
|
106
|
+
const fetchFn = fakeFetch([
|
|
107
|
+
{ id: A, name: 'Gestion', address: 'http://localhost:41001', port_pending: false },
|
|
108
|
+
{ id: 'abcdefghijkl', name: 'Sans port', address: null, port_pending: true },
|
|
109
|
+
]);
|
|
110
|
+
const out = await fronts.sync(file, config, fetchFn);
|
|
111
|
+
assert.strictEqual(fetchFn.calls[0].url, 'http://localhost:18000/meta/v1/fronts');
|
|
112
|
+
assert.strictEqual(fetchFn.calls[0].init.headers.authorization, 'Bearer svc');
|
|
113
|
+
const c = parse(file);
|
|
114
|
+
assert.strictEqual(c.fronts[A].port, 41001);
|
|
115
|
+
assert.deepStrictEqual(c.fronts.spare_ports, [41002]);
|
|
116
|
+
assert.strictEqual(c.fronts[B], undefined);
|
|
117
|
+
assert.deepStrictEqual(fronts.read(config), { fronts: [{ id: A, port: 41001 }], spare: [41002] });
|
|
118
|
+
assert.deepStrictEqual(out.fronts.map((f) => [f.name, f.address, f.port_pending]), [
|
|
119
|
+
['Gestion', 'http://localhost:41001', false],
|
|
120
|
+
['Sans port', null, true],
|
|
121
|
+
]);
|
|
122
|
+
const chalk = require('chalk-v2');
|
|
123
|
+
const lines = fronts.describe(config, out, chalk).join('\n');
|
|
124
|
+
assert.match(lines, /Front Gestion : .*http:\/\/localhost:41001/);
|
|
125
|
+
assert.match(lines, /Sans port : .*restart the project/);
|
|
126
|
+
assert.match(lines, /Spare front ports: 41002/);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test('sync : meta absent (engine ancien, 404) ou injoignable : rien ne change', async () => {
|
|
130
|
+
const text = `${BASE}\n[fronts]\nspare_ports = [41001, 41002]\n`;
|
|
131
|
+
const file = project(text);
|
|
132
|
+
const config = { ...parse(file), auth: { service: 'svc' } };
|
|
133
|
+
assert.strictEqual(await fronts.sync(file, config, fakeFetch({ error: 'route inconnue' }, 404)), null);
|
|
134
|
+
assert.strictEqual(
|
|
135
|
+
await fronts.sync(file, config, async () => {
|
|
136
|
+
throw new Error('ECONNREFUSED');
|
|
137
|
+
}),
|
|
138
|
+
null,
|
|
139
|
+
);
|
|
140
|
+
assert.strictEqual(fs.readFileSync(file, 'utf-8'), text);
|
|
141
|
+
// Sans sync, l'affichage se rabat sur config.toml
|
|
142
|
+
assert.match(fronts.describe({ fronts: { [A]: { port: 41003 } } }, null, require('chalk-v2')).join('\n'), new RegExp(`Front ${A} : .*41003`));
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test('portOf : seulement une adresse locale', () => {
|
|
146
|
+
assert.strictEqual(fronts.portOf('http://localhost:41001'), 41001);
|
|
147
|
+
assert.strictEqual(fronts.portOf('http://127.0.0.1:41001/'), 41001);
|
|
148
|
+
assert.strictEqual(fronts.portOf(`https://${A}.app.poad.io`), null);
|
|
149
|
+
assert.strictEqual(fronts.portOf(null), null);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test('poad logs : front= et page= filtrent attrs', () => {
|
|
153
|
+
const r = attrConditions({ front: A, page: 'accueil' });
|
|
154
|
+
assert.deepStrictEqual(r.conditions, [
|
|
155
|
+
["attrs->>'front' = ?", A],
|
|
156
|
+
["attrs->>'page' = ?", 'accueil'],
|
|
157
|
+
]);
|
|
158
|
+
assert.match(attrConditions({ front: true }).error, /front=k3x9q2m7a1bc/);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test('fetchFronts : nouvel essai tant que la passerelle répond 502 juste après le démarrage, abandon sur 404', async () => {
|
|
162
|
+
const fronts = require('../utils/fronts');
|
|
163
|
+
const config = { web: { port: 1 }, auth: { service: 's' } };
|
|
164
|
+
let calls = 0;
|
|
165
|
+
const flaky = async () => (++calls < 3 ? { ok: false, status: 502 } : { ok: true, status: 200, json: async () => [{ id: 'abc123def456', name: 'Démo', address: 'http://localhost:41001' }] });
|
|
166
|
+
const list = await fronts.fetchFronts(config, flaky, { attempts: 5, delayMs: 1 });
|
|
167
|
+
require('node:assert').equal(calls, 3);
|
|
168
|
+
require('node:assert').equal(list[0].name, 'Démo');
|
|
169
|
+
calls = 0;
|
|
170
|
+
const gone = async () => (++calls, { ok: false, status: 404 });
|
|
171
|
+
require('node:assert').equal(await fronts.fetchFronts(config, gone, { attempts: 5, delayMs: 1 }), null);
|
|
172
|
+
require('node:assert').equal(calls, 1);
|
|
173
|
+
});
|
package/utils/cloud/cli.js
CHANGED
|
@@ -8,9 +8,10 @@ const { CloudError, EXIT, usageError } = require('./api');
|
|
|
8
8
|
* Options des mots tapés : « --env x », « --env=x », « env=x » pour les
|
|
9
9
|
* options à valeur ; « --yes », « -y », « yes » pour les drapeaux ; le reste
|
|
10
10
|
* est positionnel. Une option à valeur sans valeur : erreur d'usage.
|
|
11
|
-
* spec : { values: ['env', 'name'], flags: ['yes', 'json'], alias: { y: 'yes' } }
|
|
11
|
+
* spec : { values: ['env', 'name'], flags: ['yes', 'json'], alias: { y: 'yes' }, multi: ['credential'] }
|
|
12
|
+
* multi : options à valeur répétables (un tableau, dans l'ordre)
|
|
12
13
|
*/
|
|
13
|
-
function parse(raw = [], { values = [], flags = [], alias = {} } = {}) {
|
|
14
|
+
function parse(raw = [], { values = [], flags = [], alias = {}, multi = [] } = {}) {
|
|
14
15
|
const opts = {};
|
|
15
16
|
const positionals = [];
|
|
16
17
|
const words = raw.map(String);
|
|
@@ -29,7 +30,8 @@ function parse(raw = [], { values = [], flags = [], alias = {} } = {}) {
|
|
|
29
30
|
if (i + 1 >= words.length || /^--?[A-Za-z]/.test(words[i + 1])) throw usageError(`--${key} needs a value`);
|
|
30
31
|
v = words[++i];
|
|
31
32
|
}
|
|
32
|
-
opts[key] = v;
|
|
33
|
+
if (multi.includes(key)) (opts[key] = opts[key] || []).push(v);
|
|
34
|
+
else opts[key] = v;
|
|
33
35
|
} else if (flags.includes(key)) {
|
|
34
36
|
opts[key] = true;
|
|
35
37
|
} else {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Clone de la production vers un environnement (poad env create, poad env clone) :
|
|
2
|
+
// les choix des credentials, « production » (sa valeur reprise : le même compte
|
|
3
|
+
// extérieur réel) ou « custom » (créé vide, à compléter dans l'environnement).
|
|
4
|
+
// Sans choix, poad.io applique son défaut : l'IA reprend la production, le
|
|
5
|
+
// reste (SMTP, paiement, bases et API extérieures) est à saisir.
|
|
6
|
+
const api = require('./api');
|
|
7
|
+
|
|
8
|
+
const NAME = /^[a-z][a-z0-9-]{0,62}$/;
|
|
9
|
+
const MODES = { production: 'production', prod: 'production', custom: 'custom', personnalise: 'custom' };
|
|
10
|
+
|
|
11
|
+
/** --credential nom=production|custom (répétable, ou séparé par des virgules) -> { nom: mode } */
|
|
12
|
+
function credentialChoices(values) {
|
|
13
|
+
const out = {};
|
|
14
|
+
for (const item of [].concat(values || []).flatMap((v) => String(v).split(','))) {
|
|
15
|
+
const s = item.trim();
|
|
16
|
+
if (!s) continue;
|
|
17
|
+
const m = /^([^=]+)=(.+)$/.exec(s);
|
|
18
|
+
const mode = m && MODES[m[2].trim().toLowerCase()];
|
|
19
|
+
if (!m || !NAME.test(m[1].trim()) || !mode) throw api.usageError(`--credential ${s}: expected <name>=production|custom`);
|
|
20
|
+
out[m[1].trim()] = mode;
|
|
21
|
+
}
|
|
22
|
+
return out;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Ce que le clone reprend, en une phrase (sortie texte) */
|
|
26
|
+
const SUMMARY = 'structure and migration history, code, settings (auth, e-mail templates, AI models, buckets), variables and credentials';
|
|
27
|
+
|
|
28
|
+
module.exports = { credentialChoices, SUMMARY };
|
package/utils/fronts.js
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
// Fronts dessinés dans poad (engine 0.46.0+) : un port de cette machine par
|
|
2
|
+
// front, comme sur poad.io un sous-domaine par front (<id>.app.poad.io). Même
|
|
3
|
+
// origine isolée en local qu'en ligne : cookies, stockage et service workers
|
|
4
|
+
// propres au front, et des adresses de pages identiques (pas de /apps/<nom>).
|
|
5
|
+
//
|
|
6
|
+
// poad/config.toml :
|
|
7
|
+
// [fronts]
|
|
8
|
+
// spare_ports = [41001, 41002] réservés d'avance, publiés à chaque poad start
|
|
9
|
+
// [fronts.k3x9q2m7a1bc]
|
|
10
|
+
// port = 41003
|
|
11
|
+
//
|
|
12
|
+
// Chaque port est publié sur le port 8100 du conteneur (second écouteur de la
|
|
13
|
+
// passerelle de l'engine) ; l'engine reconnaît le front à l'hôte d'arrivée
|
|
14
|
+
// (localhost:<port>). Un port ne s'ajoute pas à un conteneur qui tourne :
|
|
15
|
+
// la réserve permet à la console de créer un front pendant que le projet
|
|
16
|
+
// tourne, joignable aussitôt. Réserve vide : le front attend le prochain
|
|
17
|
+
// poad start (la console le dit).
|
|
18
|
+
const SPARE = 2;
|
|
19
|
+
const CONTAINER_PORT = '8100/tcp';
|
|
20
|
+
const ID_RE = /^[a-z][a-z0-9]{11}$/;
|
|
21
|
+
|
|
22
|
+
/** Engine 0.46.0 et plus : fronts servis par l'engine */
|
|
23
|
+
const supportsFronts = (config) => {
|
|
24
|
+
const [major, minor] = String(config.engine || '').split('.').map(Number);
|
|
25
|
+
return major > 0 || minor >= 46;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const portOk = (p) => Number.isInteger(p) && p > 0 && p < 65536;
|
|
29
|
+
|
|
30
|
+
/** { fronts: [{ id, port }], spare: [port…] } d'après config.fronts */
|
|
31
|
+
const read = (config) => {
|
|
32
|
+
const section = (config && config.fronts) || {};
|
|
33
|
+
const fronts = [];
|
|
34
|
+
for (const [id, v] of Object.entries(section)) {
|
|
35
|
+
if (!ID_RE.test(id) || !v || typeof v !== 'object' || Array.isArray(v)) continue;
|
|
36
|
+
const port = Number(v.port);
|
|
37
|
+
if (portOk(port)) fronts.push({ id, port });
|
|
38
|
+
}
|
|
39
|
+
const taken = new Set(fronts.map((f) => f.port));
|
|
40
|
+
const spare = [...new Set((Array.isArray(section.spare_ports) ? section.spare_ports : []).map(Number))].filter((p) => portOk(p) && !taken.has(p));
|
|
41
|
+
return { fronts, spare };
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/** Ports du projet hors fronts (base, API, Mailpit, collecteur…) : jamais pris pour un front */
|
|
45
|
+
const projectPorts = (config) =>
|
|
46
|
+
[config.db && config.db.port, config.web && config.web.port, config.mail && config.mail.port, config.logs && config.logs.gelf_port, config.valkey && config.valkey.port]
|
|
47
|
+
.map(Number)
|
|
48
|
+
.filter(Boolean);
|
|
49
|
+
|
|
50
|
+
/** Écrit la réserve, et les sections [fronts.<id>] données ({ id: port | null }) */
|
|
51
|
+
const write = (root, { spare, fronts = {} }) => {
|
|
52
|
+
const { setKeys, removeSection } = require('./tomlfile');
|
|
53
|
+
if (spare) setKeys(root, 'fronts', { spare_ports: spare });
|
|
54
|
+
for (const [id, port] of Object.entries(fronts)) {
|
|
55
|
+
if (!ID_RE.test(id)) continue;
|
|
56
|
+
if (port === null) removeSection(root, `fronts.${id}`);
|
|
57
|
+
else setKeys(root, `fronts.${id}`, { port });
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/** Met config.fronts à jour sur place d'après un état { fronts, spare } */
|
|
62
|
+
const apply = (config, state) => {
|
|
63
|
+
const section = { spare_ports: state.spare };
|
|
64
|
+
for (const f of state.fronts) section[f.id] = { port: f.port };
|
|
65
|
+
config.fronts = section;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Réserve complétée à SPARE ports libres (avant poad start). Renvoie les ports
|
|
70
|
+
* ajoutés. deps.findFreePorts et deps.isPortFree pour les tests.
|
|
71
|
+
*/
|
|
72
|
+
const ensureSpare = async (root, config, deps = {}) => {
|
|
73
|
+
const ports = require('./ports');
|
|
74
|
+
const findFreePorts = deps.findFreePorts || ports.findFreePorts;
|
|
75
|
+
const isPortFree = deps.isPortFree || ports.isPortFree;
|
|
76
|
+
const state = read(config);
|
|
77
|
+
const used = new Set([...projectPorts(config), ...state.fronts.map((f) => f.port), ...state.spare]);
|
|
78
|
+
const added = [];
|
|
79
|
+
// Ports de réserve pris sur cette machine par autre chose : remplacés
|
|
80
|
+
const spare = [];
|
|
81
|
+
for (const p of state.spare) if (await isPortFree(p)) spare.push(p);
|
|
82
|
+
while (spare.length < SPARE) {
|
|
83
|
+
const [p] = await findFreePorts(1, 20000, 60000);
|
|
84
|
+
if (used.has(p)) continue;
|
|
85
|
+
used.add(p);
|
|
86
|
+
spare.push(p);
|
|
87
|
+
added.push(p);
|
|
88
|
+
}
|
|
89
|
+
if (added.length || spare.length !== state.spare.length || (config.fronts || {}).spare_ports === undefined) write(root, { spare });
|
|
90
|
+
apply(config, { ...state, spare });
|
|
91
|
+
return added;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/** Entrées pour ports.reassignBusyPorts : le port de chaque front (section fronts.<id>) */
|
|
95
|
+
const busyEntries = (config) =>
|
|
96
|
+
read(config).fronts.map((f) => {
|
|
97
|
+
// reassignBusyPorts lit config[section][key] : alias à plat, replié par foldMoved
|
|
98
|
+
config[`fronts.${f.id}`] = { port: f.port };
|
|
99
|
+
return { section: `fronts.${f.id}`, key: 'port', label: `Front ${f.id}` };
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Après reassignBusyPorts, config['fronts.<id>'] porte le port déplacé : le
|
|
104
|
+
* ramener dans config.fronts.<id>
|
|
105
|
+
*/
|
|
106
|
+
const foldMoved = (config) => {
|
|
107
|
+
for (const key of Object.keys(config)) {
|
|
108
|
+
const m = /^fronts\.([a-z][a-z0-9]{11})$/.exec(key);
|
|
109
|
+
if (!m) continue;
|
|
110
|
+
config.fronts = config.fronts || {};
|
|
111
|
+
config.fronts[m[1]] = { ...(config.fronts[m[1]] || {}), ...config[key] };
|
|
112
|
+
delete config[key];
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
/** Variables de l'engine : fronts connus, réserve, nom du projet */
|
|
117
|
+
const engineEnv = (config) => {
|
|
118
|
+
const { fronts, spare } = read(config);
|
|
119
|
+
return [
|
|
120
|
+
`POAD_FRONT_PORTS=${fronts.map((f) => `${f.id}=${f.port}`).join(',')}`,
|
|
121
|
+
`POAD_FRONT_SPARE_PORTS=${spare.join(',')}`,
|
|
122
|
+
`POAD_PROJECT_NAME=${projectName(config)}`,
|
|
123
|
+
];
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
/** Nom du projet (project_id de config.toml, celui que montre poad projects) */
|
|
127
|
+
const projectName = (config) => String((config && (config.project_id || config.project_uuid)) || 'poad').replace(/[\r\n]/g, ' ').slice(0, 80);
|
|
128
|
+
|
|
129
|
+
/** Ports publiés : tous sur 8100/tcp du conteneur, à la même interface que les autres ports */
|
|
130
|
+
const bindings = (config) => {
|
|
131
|
+
const { fronts, spare } = read(config);
|
|
132
|
+
const all = [...fronts.map((f) => f.port), ...spare];
|
|
133
|
+
if (!all.length) return { exposed: {}, bindings: {} };
|
|
134
|
+
const HostIp = require('./ports').hostIp(config);
|
|
135
|
+
return { exposed: { [CONTAINER_PORT]: {} }, bindings: { [CONTAINER_PORT]: all.map((p) => ({ HostIp, HostPort: String(p) })) } };
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
/** Fronts de l'engine (GET /meta/v1/fronts) ; null si meta ne répond pas ou ne les connaît pas */
|
|
139
|
+
// attempts : juste après poad start, meta peut ne pas répondre encore (passerelle pas encore ouverte, 502) :
|
|
140
|
+
// nouvel essai toutes les 1,5 s ; 404 (engine sans fronts) ou réponse illisible : abandon tout de suite
|
|
141
|
+
const fetchFronts = async (config, fetchFn = globalThis.fetch, { attempts = 1, delayMs = 1500 } = {}) => {
|
|
142
|
+
for (let i = 0; i < attempts; i++) {
|
|
143
|
+
if (i) await new Promise((r) => setTimeout(r, delayMs));
|
|
144
|
+
try {
|
|
145
|
+
const res = await fetchFn(`http://localhost:${config.web.port}/meta/v1/fronts`, {
|
|
146
|
+
headers: { apikey: config.auth.service, authorization: `Bearer ${config.auth.service}` },
|
|
147
|
+
signal: AbortSignal.timeout(8000),
|
|
148
|
+
});
|
|
149
|
+
if (res.status >= 502 && res.status <= 504) continue;
|
|
150
|
+
if (!res.ok) return null;
|
|
151
|
+
const list = await res.json();
|
|
152
|
+
return Array.isArray(list) ? list.filter((f) => f && typeof f.id === 'string' && ID_RE.test(f.id)) : null;
|
|
153
|
+
} catch {
|
|
154
|
+
/* pas encore joignable : essai suivant */
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return null;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
/** Port local d'une adresse http://localhost:<port> (ou 127.0.0.1) */
|
|
161
|
+
const portOf = (address) => {
|
|
162
|
+
const m = /^http:\/\/(?:localhost|127\.0\.0\.1):(\d{1,5})\/?$/.exec(String(address || ''));
|
|
163
|
+
return m && portOk(Number(m[1])) ? Number(m[1]) : null;
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Après le démarrage : config.toml suit les fronts de l'engine. Un front qui a
|
|
168
|
+
* pris un port de réserve reçoit sa section, et ce port quitte la réserve ;
|
|
169
|
+
* la section d'un front supprimé part. Ne fait rien si meta ne répond pas.
|
|
170
|
+
* Renvoie { fronts: [{ id, name, address, port_pending }] } ou null.
|
|
171
|
+
*/
|
|
172
|
+
const sync = async (root, config, fetchFn, options) => {
|
|
173
|
+
const list = await fetchFronts(config, fetchFn, options);
|
|
174
|
+
if (!list) return null;
|
|
175
|
+
const state = read(config);
|
|
176
|
+
const known = new Map(state.fronts.map((f) => [f.id, f.port]));
|
|
177
|
+
const changes = {};
|
|
178
|
+
let spare = state.spare;
|
|
179
|
+
for (const f of list) {
|
|
180
|
+
const port = portOf(f.address);
|
|
181
|
+
if (port && known.get(f.id) !== port) {
|
|
182
|
+
changes[f.id] = port;
|
|
183
|
+
spare = spare.filter((p) => p !== port);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
const ids = new Set(list.map((f) => f.id));
|
|
187
|
+
for (const f of state.fronts) if (!ids.has(f.id)) changes[f.id] = null;
|
|
188
|
+
if (Object.keys(changes).length || spare.length !== state.spare.length) {
|
|
189
|
+
write(root, { spare, fronts: changes });
|
|
190
|
+
const fronts = state.fronts.filter((f) => changes[f.id] !== null).map((f) => (changes[f.id] ? { id: f.id, port: changes[f.id] } : f));
|
|
191
|
+
for (const [id, port] of Object.entries(changes)) if (port && !known.has(id)) fronts.push({ id, port });
|
|
192
|
+
apply(config, { fronts, spare });
|
|
193
|
+
}
|
|
194
|
+
return { fronts: list.map((f) => ({ id: f.id, name: typeof f.name === 'string' ? f.name : f.id, address: f.address || null, port_pending: f.port_pending === true })) };
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
/** Lignes d'affichage (poad start, poad info) */
|
|
198
|
+
const describe = (config, synced, chalk) => {
|
|
199
|
+
const lines = [];
|
|
200
|
+
const { fronts, spare } = read(config);
|
|
201
|
+
if (synced) {
|
|
202
|
+
for (const f of synced.fronts) {
|
|
203
|
+
if (f.address) lines.push(`Front ${f.name} : ${chalk.bold.cyanBright(f.address)}`);
|
|
204
|
+
else lines.push(`Front ${f.name} : ${chalk.yellowBright('no port yet, restart the project (poad stop, then poad start)')}`);
|
|
205
|
+
}
|
|
206
|
+
} else {
|
|
207
|
+
for (const f of fronts) lines.push(`Front ${f.id} : ${chalk.bold.cyanBright(`http://localhost:${f.port}`)}`);
|
|
208
|
+
}
|
|
209
|
+
if (spare.length) lines.push(chalk.grey(`Spare front ports: ${spare.join(', ')} (for fronts created from the console)`));
|
|
210
|
+
return lines;
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
module.exports = { SPARE, CONTAINER_PORT, supportsFronts, read, write, ensureSpare, busyEntries, foldMoved, engineEnv, projectName, bindings, fetchFronts, portOf, sync, describe };
|
package/utils/help-details.js
CHANGED
|
@@ -239,13 +239,15 @@ Object.assign(sheets, {
|
|
|
239
239
|
},
|
|
240
240
|
unlink: { usage: ['poad unlink [--json]'], text: ['Remove [cloud] project from poad/config.toml. Nothing changes on poad.io.'], options: [JSON_OPT] },
|
|
241
241
|
env: {
|
|
242
|
-
usage: ['poad env ls', 'poad env create <name> [--kind persistent|preview]', 'poad env rm <name> [--yes]'],
|
|
242
|
+
usage: ['poad env ls', 'poad env create <name> [--kind persistent|preview] [--empty] [--with-data] [--credential <name>=production|custom]…', 'poad env clone <name> [--with-data] [--credential <name>=production|custom]… [--yes]', 'poad env rm <name> [--yes]'],
|
|
243
243
|
text: [
|
|
244
244
|
'Environments of the linked poad.io project: one branch each, with its own database and files; main is production. poad deploy, poad db url and poad db pull use the current git branch when an environment of that name exists, else main; --env <name> chooses.',
|
|
245
245
|
],
|
|
246
246
|
options: [
|
|
247
247
|
['ls', 'the environments (the default one is marked)'],
|
|
248
|
-
['create <name>', 'a new environment; --kind persistent (default
|
|
248
|
+
['create <name>', 'a new environment, by default a clone of production: structure and migration history, code, settings, variables and credentials, without the data; --with-data: all the data too (tables, auth users, storage files); --empty: an empty environment; --kind persistent (default) or preview'],
|
|
249
|
+
['clone <name>', 'reclone an environment from production (asks first, --yes outside a terminal); what it has of its own is replaced; --with-data: its data too. Production is only read. (sync: old name)'],
|
|
250
|
+
['--credential <name>=production|custom', 'per credential: production reuses its value (the same external account: real e-mails, billed AI calls…), custom creates it empty to fill in the environment. Default: AI credentials production, the others custom'],
|
|
249
251
|
['rm <name>', 'remove an environment with its database and files (asks first, --yes outside a terminal); main is never removed here'],
|
|
250
252
|
PROJECT_OPT,
|
|
251
253
|
JSON_OPT,
|
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' };
|
|
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' };
|
|
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' };
|
|
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' };
|
|
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
|
|
package/utils/report.js
CHANGED
|
@@ -71,6 +71,18 @@ async function printProject(root, config, opts = {}) {
|
|
|
71
71
|
const line = await migrationsLine(root, config);
|
|
72
72
|
if (line) info.Migrations = line;
|
|
73
73
|
console.log(prettyoutput(info));
|
|
74
|
+
// Fronts dessinés dans poad (engine 0.46.0+) : config.toml suit l'engine (port pris dans la réserve), puis une ligne par front
|
|
75
|
+
const fronts = require('./fronts');
|
|
76
|
+
if (fronts.supportsFronts(config)) {
|
|
77
|
+
// Juste après poad start (opts.justStarted) : meta peut mettre quelques secondes à répondre
|
|
78
|
+
const synced = opts.offline ? null : await fronts.sync(root, config, undefined, opts.justStarted ? { attempts: 20 } : undefined);
|
|
79
|
+
const lines = fronts.describe(config, synced, chalk);
|
|
80
|
+
if (lines.length) {
|
|
81
|
+
console.log(chalk.bold('Fronts'));
|
|
82
|
+
lines.forEach((l) => console.log(` ${l}`));
|
|
83
|
+
console.log(' ');
|
|
84
|
+
}
|
|
85
|
+
}
|
|
74
86
|
}
|
|
75
87
|
|
|
76
88
|
async function printServices(root, config, opts = {}) {
|
package/utils/tomlfile.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
// Modifications ciblées d'un fichier TOML simple (config.toml, secrets.toml) :
|
|
2
2
|
// le texte est modifié ligne à ligne, les commentaires et l'ordre restent.
|
|
3
|
-
// Valeurs : chaîne, nombre, booléen
|
|
3
|
+
// Valeurs : chaîne, nombre, booléen, tableau de ces valeurs (sur une ligne) ;
|
|
4
|
+
// null retire la clé. Section imbriquée : son nom pointé (« fronts.k3x9q2m7a1bc »).
|
|
4
5
|
const fs = require('fs');
|
|
5
6
|
|
|
6
|
-
const format = (v) => (typeof v === 'string' ? JSON.stringify(v) : String(v));
|
|
7
|
+
const format = (v) => (Array.isArray(v) ? `[${v.map(format).join(', ')}]` : typeof v === 'string' ? JSON.stringify(v) : String(v));
|
|
7
8
|
|
|
8
9
|
/** Bornes [début, fin) des lignes de la section (début = ligne d'en-tête), ou null */
|
|
9
10
|
function sectionRange(lines, section) {
|