poad 2.36.0 → 2.38.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/.github/workflows/release.yml +13 -1
- package/global/clean.js +3 -2
- package/global/init.js +6 -1
- package/global/install.js +2 -1
- package/package.json +1 -1
- package/project/cli.js +1 -1
- package/project/upgrade.js +10 -7
- package/utils/engine.js +10 -11
- package/utils/latest.js +102 -15
- package/utils/version.js +43 -0
|
@@ -31,10 +31,21 @@ jobs:
|
|
|
31
31
|
- name: Install dependencies
|
|
32
32
|
run: bun install --frozen-lockfile
|
|
33
33
|
|
|
34
|
+
# Une préversion (x.y.z-beta.N) sort sous l'étiquette npm « beta »
|
|
35
|
+
# (npm install -g poad@beta) ; « latest » reste la dernière version finale.
|
|
36
|
+
- name: npm tag
|
|
37
|
+
id: tag
|
|
38
|
+
run: |
|
|
39
|
+
case "$(node -p "require('./package.json').version")" in
|
|
40
|
+
*-*) echo "tag=beta" >> "$GITHUB_OUTPUT" ;;
|
|
41
|
+
*) echo "tag=latest" >> "$GITHUB_OUTPUT" ;;
|
|
42
|
+
esac
|
|
43
|
+
|
|
34
44
|
- name: Publish to npm
|
|
35
45
|
uses: JS-DevTools/npm-publish@v1
|
|
36
46
|
with:
|
|
37
47
|
token: ${{ secrets.NPM_TOKEN }}
|
|
48
|
+
tag: ${{ steps.tag.outputs.tag }}
|
|
38
49
|
|
|
39
50
|
# Le registre annonce une version avant que son archive soit servie
|
|
40
51
|
# partout : le workflow n'est vert que lorsqu'elle s'installe vraiment.
|
|
@@ -42,10 +53,11 @@ jobs:
|
|
|
42
53
|
run: |
|
|
43
54
|
NAME=$(node -p "require('./package.json').name")
|
|
44
55
|
VERSION=$(node -p "require('./package.json').version")
|
|
56
|
+
TAG=${{ steps.tag.outputs.tag }}
|
|
45
57
|
URL="https://registry.npmjs.org/$NAME/-/${NAME##*/}-$VERSION.tgz"
|
|
46
58
|
for i in $(seq 1 60); do
|
|
47
59
|
if [ "$(curl -s -o /dev/null -w '%{http_code}' "$URL")" = "200" ] \
|
|
48
|
-
&& [ "$(curl -s "https://registry.npmjs.org/$NAME
|
|
60
|
+
&& [ "$(curl -s "https://registry.npmjs.org/$NAME/$TAG" | node -p "JSON.parse(require('fs').readFileSync(0,'utf8')).version")" = "$VERSION" ]; then
|
|
49
61
|
echo "$NAME@$VERSION is installable"
|
|
50
62
|
exit 0
|
|
51
63
|
fi
|
package/global/clean.js
CHANGED
|
@@ -50,9 +50,10 @@ module.exports = async (args = {}) => {
|
|
|
50
50
|
return m && !running.has(m[1]);
|
|
51
51
|
});
|
|
52
52
|
|
|
53
|
-
// Images d'engine qu'aucun conteneur n'utilise (sauf
|
|
53
|
+
// Images d'engine qu'aucun conteneur n'utilise (sauf la dernière publiée)
|
|
54
54
|
const usedImages = new Set(containers.map((c) => c.Image));
|
|
55
|
-
const
|
|
55
|
+
const { engineRelease, engineChannel } = require('../utils/latest');
|
|
56
|
+
const keep = `poadio/engine:${await engineRelease({ channel: engineChannel() })}`;
|
|
56
57
|
const images = (await docker.listImages())
|
|
57
58
|
.flatMap((i) => (i.RepoTags || []).map((tag) => ({ tag, size: i.Size })))
|
|
58
59
|
.filter((i) => i.tag.startsWith('poadio/engine:') && i.tag !== keep && !usedImages.has(i.tag));
|
package/global/init.js
CHANGED
|
@@ -23,10 +23,15 @@ module.exports = async () => {
|
|
|
23
23
|
|
|
24
24
|
fs.mkdirSync(path.join(dir, 'data'), { recursive: true });
|
|
25
25
|
const ports = await findFreePorts(3);
|
|
26
|
+
const { engineRelease, engineChannel } = require('../utils/latest');
|
|
27
|
+
const channel = engineChannel();
|
|
28
|
+
const engine = await engineRelease({ channel });
|
|
26
29
|
const config = {
|
|
27
30
|
project_id: path.basename(process.cwd()),
|
|
28
31
|
project_uuid: generateUniqueId(),
|
|
29
|
-
engine
|
|
32
|
+
engine,
|
|
33
|
+
// POAD_CHANNEL=beta poad init : le projet reste sur le canal beta (poad start, poad upgrade)
|
|
34
|
+
...(channel === 'beta' ? { channel } : {}),
|
|
30
35
|
db: { port: ports[0] },
|
|
31
36
|
web: { port: ports[1] },
|
|
32
37
|
// Interface web de Mailpit (e-mails du projet local)
|
package/global/install.js
CHANGED
|
@@ -4,7 +4,8 @@ module.exports = async (args) => {
|
|
|
4
4
|
const { pullImage } = require('../utils/pull');
|
|
5
5
|
|
|
6
6
|
const docker = new Docker();
|
|
7
|
-
const
|
|
7
|
+
const { engineRelease, engineChannel } = require('../utils/latest');
|
|
8
|
+
const imageName = 'poadio/engine:' + (await engineRelease({ fresh: true, channel: engineChannel() }));
|
|
8
9
|
|
|
9
10
|
console.log(chalk.bold('\nInstalling poad environment...'));
|
|
10
11
|
|
package/package.json
CHANGED
package/project/cli.js
CHANGED
|
@@ -21,7 +21,7 @@ module.exports = {
|
|
|
21
21
|
seed: 'Apply poad/seed.sql (development data)',
|
|
22
22
|
diff: 'Structure changes made outside the migrations (console SQL, psql…): diff to list them, diff <name> to write them as a migration, diff --discard to forget them',
|
|
23
23
|
},
|
|
24
|
-
upgrade: 'Upgrade the engine of the project (backs up poad/ first): upgrade, upgrade to=<version>, upgrade --rollback, upgrade --list (--yes outside a terminal)',
|
|
24
|
+
upgrade: 'Upgrade the engine of the project (backs up poad/ first): upgrade, upgrade to=<version>, upgrade channel=beta (or channel = "beta" in poad/config.toml, or POAD_CHANNEL=beta), upgrade --rollback, upgrade --list (--yes outside a terminal)',
|
|
25
25
|
logs: 'Unified logs of the project: logs [service…] level=warn since=15m request=<id> grep=<text> flow=<name> run=<id or its first 8 characters> step=<name> function=<name> limit=100 -f --json',
|
|
26
26
|
gen: {
|
|
27
27
|
description: 'Generators: gen types (TypeScript types of the database), gen env (types of the public variables)',
|
package/project/upgrade.js
CHANGED
|
@@ -103,16 +103,19 @@ module.exports = async (args = {}) => {
|
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
// Mise à jour
|
|
106
|
-
// Sans to= :
|
|
106
|
+
// Sans to= : la version recommandée du canal du projet (poadio/permalink),
|
|
107
|
+
// sinon le dernier engine publié (Docker Hub), sinon celui inscrit dans le CLI
|
|
107
108
|
const current = config.engine;
|
|
108
109
|
let target = String(args.to || '');
|
|
109
110
|
if (!target) {
|
|
110
|
-
const
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
111
|
+
const latest = require('../utils/latest');
|
|
112
|
+
const channel = latest.engineChannel(config, args);
|
|
113
|
+
const info = await latest.engineReleaseInfo({ fresh: true, channel, timeout: 4000 });
|
|
114
|
+
target = String(info.version || '');
|
|
115
|
+
if (channel === 'beta') console.log(chalk.grey(` Channel: beta (${target || 'none'}).`));
|
|
116
|
+
if (info.source === 'cache' || info.source === 'cli') {
|
|
117
|
+
console.log(chalk.grey(` Offline: latest engine unknown, last known ${target || 'none'}.`));
|
|
118
|
+
// Hors ligne, la version connue peut être en retard : jamais de retour en arrière sans to=
|
|
116
119
|
if (target && target !== current && !isNewerVersion(target, current)) {
|
|
117
120
|
return console.log(chalk.yellow(` This project uses engine ${current}. Retry online, or "poad upgrade to=<version>".`));
|
|
118
121
|
}
|
package/utils/engine.js
CHANGED
|
@@ -71,13 +71,10 @@ module.exports = { usesMinio, storageInfo, supportsData, supportsRealtime, suppo
|
|
|
71
71
|
// est d'abord sauvegardé dans poad/backups (poad upgrade --rollback y revient).
|
|
72
72
|
// poad start ne la propose qu'au sein de la même version mineure (seules des
|
|
73
73
|
// migrations s'appliquent) ; poad upgrade accepte aussi un saut de mineure.
|
|
74
|
-
const
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
for (let i = 0; i < 3; i++) if ((pa[i] || 0) !== (pb[i] || 0)) return (pa[i] || 0) > (pb[i] || 0);
|
|
79
|
-
return false;
|
|
80
|
-
};
|
|
74
|
+
const { compareVersions } = require('./version');
|
|
75
|
+
const parseVersion = (v) => String(v || '').split(/[.-]/).slice(0, 3).map((n) => parseInt(n, 10) || 0);
|
|
76
|
+
// x.y.z-beta.N passe avant x.y.z (utils/version.js)
|
|
77
|
+
const isNewer = (a, b) => compareVersions(a, b) > 0;
|
|
81
78
|
|
|
82
79
|
const ask = (question) =>
|
|
83
80
|
new Promise((resolve) => {
|
|
@@ -130,14 +127,16 @@ const backupBefore = async (root, config, target) => {
|
|
|
130
127
|
|
|
131
128
|
/**
|
|
132
129
|
* Version d'engine à démarrer (celle du projet, ou la nouvelle si acceptée).
|
|
133
|
-
* args : upgrade (sans question), target (version voulue, défaut :
|
|
134
|
-
*
|
|
130
|
+
* args : upgrade (sans question), target (version voulue, défaut : la dernière
|
|
131
|
+
* publiée, voir latest.js), allowMinor (saut de version mineure permis), noOffer (ne rien proposer).
|
|
135
132
|
*/
|
|
136
133
|
const offerEngineUpgrade = async (root, config, args = {}) => {
|
|
137
134
|
const chalk = require('chalk-v2');
|
|
138
|
-
const target = String(args.target || (global.package && global.package.engine) || '');
|
|
139
135
|
const current = config.engine;
|
|
140
|
-
if (args.noOffer
|
|
136
|
+
if (args.noOffer) return current;
|
|
137
|
+
const latest = require('./latest');
|
|
138
|
+
const target = String(args.target || (await latest.engineRelease({ channel: latest.engineChannel(config, args) })) || '');
|
|
139
|
+
if (!target || !isNewer(target, current)) return current;
|
|
141
140
|
const [cMaj, cMin] = parseVersion(current);
|
|
142
141
|
const [tMaj, tMin] = parseVersion(target);
|
|
143
142
|
if ((cMaj !== tMaj || cMin !== tMin) && !args.allowMinor) {
|
package/utils/latest.js
CHANGED
|
@@ -1,28 +1,115 @@
|
|
|
1
|
-
//
|
|
2
|
-
// le CLI n'a pas à être republié à chaque engine.
|
|
3
|
-
//
|
|
4
|
-
|
|
1
|
+
// Version d'engine à utiliser par défaut (init, install, proposition au
|
|
2
|
+
// démarrage, upgrade, clean) : le CLI n'a pas à être republié à chaque engine.
|
|
3
|
+
//
|
|
4
|
+
// 1. poadio/permalink (poad.json, public) : { "engine": { "stable": "x.y.z", "beta": "x.y.z-beta.N" } }.
|
|
5
|
+
// C'est la version recommandée par canal ; elle permet de retenir un engine
|
|
6
|
+
// publié, de revenir en arrière, ou d'en proposer un en avance (beta).
|
|
7
|
+
// 2. Sans permalink (illisible, sans clé engine) : le dernier tag x.y.z de
|
|
8
|
+
// poadio/engine sur Docker Hub, jamais plus ancien que celui du CLI.
|
|
9
|
+
// 3. Hors ligne : le dernier résultat connu (cache), sinon la version du CLI.
|
|
10
|
+
//
|
|
11
|
+
// Canal : stable par défaut ; beta par POAD_CHANNEL=beta, channel = "beta"
|
|
12
|
+
// dans poad/config.toml, ou channel=beta sur la ligne de commande. Le canal
|
|
13
|
+
// beta prend la beta de permalink si elle est plus récente que la stable.
|
|
14
|
+
const { isVersion, isRelease, compareVersions } = require('./version');
|
|
5
15
|
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
16
|
+
const TAGS_URL = 'https://hub.docker.com/v2/repositories/poadio/engine/tags?page_size=100';
|
|
17
|
+
const PERMALINK_URL = 'https://raw.githubusercontent.com/poadio/permalink/main/poad.json';
|
|
18
|
+
const CHANNELS = ['stable', 'beta'];
|
|
19
|
+
const CACHE_TTL = 6 * 3600 * 1000;
|
|
11
20
|
|
|
12
21
|
// Seules les versions x.y.z comptent : ni latest, ni préversion
|
|
13
22
|
const pickLatest = (tags) => {
|
|
14
|
-
const versions = (tags || []).filter(
|
|
15
|
-
return versions.length ? versions.sort(
|
|
23
|
+
const versions = (tags || []).filter(isRelease);
|
|
24
|
+
return versions.length ? versions.sort(compareVersions).pop() : null;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const fetchJson = async (url, timeout) => {
|
|
28
|
+
try {
|
|
29
|
+
const res = await fetch(url, { signal: AbortSignal.timeout(timeout), headers: { 'cache-control': 'no-cache' } });
|
|
30
|
+
return res.ok ? await res.json() : null;
|
|
31
|
+
} catch {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
16
34
|
};
|
|
17
35
|
|
|
18
36
|
const latestEngine = async (timeout = 4000) => {
|
|
37
|
+
const body = await fetchJson(TAGS_URL, timeout);
|
|
38
|
+
return body ? pickLatest((body.results || []).map((t) => t.name)) : null;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/** Versions d'engine par canal lues dans permalink : { stable?, beta? }, ou null */
|
|
42
|
+
const permalinkEngines = async (timeout = 4000) => {
|
|
43
|
+
const body = await fetchJson(PERMALINK_URL, timeout);
|
|
44
|
+
const engine = body && typeof body === 'object' ? body.engine : null;
|
|
45
|
+
if (!engine || typeof engine !== 'object') return null;
|
|
46
|
+
const out = {};
|
|
47
|
+
if (isRelease(engine.stable)) out.stable = engine.stable;
|
|
48
|
+
if (isVersion(engine.beta)) out.beta = engine.beta;
|
|
49
|
+
return Object.keys(out).length ? out : null;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const engineChannel = (config = {}, args = {}) => {
|
|
53
|
+
const c = String(args.channel || process.env.POAD_CHANNEL || (config && config.channel) || 'stable').toLowerCase();
|
|
54
|
+
return CHANNELS.includes(c) ? c : 'stable';
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const cacheFile = () => require('path').join(require('os').homedir(), '.poad', 'engine-latest.json');
|
|
58
|
+
|
|
59
|
+
const readCache = () => {
|
|
19
60
|
try {
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
return pickLatest(((await res.json()).results || []).map((t) => t.name));
|
|
61
|
+
const c = JSON.parse(require('fs').readFileSync(cacheFile(), 'utf8'));
|
|
62
|
+
return c && typeof c.at === 'number' ? c : null;
|
|
23
63
|
} catch {
|
|
24
64
|
return null;
|
|
25
65
|
}
|
|
26
66
|
};
|
|
27
67
|
|
|
28
|
-
|
|
68
|
+
const writeCache = (data) => {
|
|
69
|
+
try {
|
|
70
|
+
const fs = require('fs');
|
|
71
|
+
fs.mkdirSync(require('path').dirname(cacheFile()), { recursive: true });
|
|
72
|
+
fs.writeFileSync(cacheFile(), JSON.stringify({ ...data, at: Date.now() }));
|
|
73
|
+
} catch {
|
|
74
|
+
// cache facultatif
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* { version, channel, source } : source = permalink, docker-hub, cache ou cli
|
|
80
|
+
* (hors ligne, sans rien de connu). fresh : ignorer le cache récent.
|
|
81
|
+
*/
|
|
82
|
+
const engineReleaseInfo = async ({ fresh = false, channel = 'stable', timeout = 2500 } = {}) => {
|
|
83
|
+
const pinned = (global.package && global.package.engine) || null;
|
|
84
|
+
const cached = readCache();
|
|
85
|
+
let data = !fresh && cached && Date.now() - cached.at < CACHE_TTL ? cached : null;
|
|
86
|
+
let source = data ? 'cache' : null;
|
|
87
|
+
if (!data) {
|
|
88
|
+
const permalink = await permalinkEngines(timeout);
|
|
89
|
+
const hub = permalink && permalink.stable ? null : await latestEngine(timeout);
|
|
90
|
+
if (permalink || hub) {
|
|
91
|
+
data = { permalink, hub };
|
|
92
|
+
writeCache(data);
|
|
93
|
+
source = permalink && permalink.stable ? 'permalink' : 'docker-hub';
|
|
94
|
+
} else if (cached) {
|
|
95
|
+
data = cached;
|
|
96
|
+
source = 'cache';
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const permalink = (data && data.permalink) || null;
|
|
100
|
+
let stable = permalink && permalink.stable ? permalink.stable : null;
|
|
101
|
+
if (!stable) {
|
|
102
|
+
const hub = data && data.hub;
|
|
103
|
+
stable = pickLatest([hub, pinned].filter(Boolean)) || pinned;
|
|
104
|
+
}
|
|
105
|
+
if (!data) source = 'cli';
|
|
106
|
+
let version = stable;
|
|
107
|
+
if (channel === 'beta' && permalink && permalink.beta && (!stable || compareVersions(permalink.beta, stable) > 0)) {
|
|
108
|
+
version = permalink.beta;
|
|
109
|
+
}
|
|
110
|
+
return { version: version || null, channel, source };
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const engineRelease = async (options = {}) => (await engineReleaseInfo(options)).version;
|
|
114
|
+
|
|
115
|
+
module.exports = { latestEngine, pickLatest, permalinkEngines, engineChannel, engineRelease, engineReleaseInfo };
|
package/utils/version.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Versions d'engine : x.y.z, ou x.y.z-beta.N (préversion, canal beta).
|
|
2
|
+
// Une préversion passe avant sa version finale : 0.29.0-beta.1 < 0.29.0-beta.2 < 0.29.0.
|
|
3
|
+
const VERSION_RE = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?$/;
|
|
4
|
+
|
|
5
|
+
const isVersion = (v) => typeof v === 'string' && VERSION_RE.test(v);
|
|
6
|
+
const isRelease = (v) => typeof v === 'string' && /^\d+\.\d+\.\d+$/.test(v);
|
|
7
|
+
|
|
8
|
+
const parse = (v) => {
|
|
9
|
+
const m = VERSION_RE.exec(String(v || ''));
|
|
10
|
+
if (!m) {
|
|
11
|
+
const [a, b, c] = String(v || '').split('.').map((n) => parseInt(n, 10) || 0);
|
|
12
|
+
return { core: [a || 0, b || 0, c || 0], pre: null };
|
|
13
|
+
}
|
|
14
|
+
return { core: [Number(m[1]), Number(m[2]), Number(m[3])], pre: m[4] ? m[4].split('.') : null };
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// Identifiants de préversion : numériques comparés en nombre, sinon en texte (semver)
|
|
18
|
+
const comparePre = (a, b) => {
|
|
19
|
+
if (!a && !b) return 0;
|
|
20
|
+
if (!a) return 1;
|
|
21
|
+
if (!b) return -1;
|
|
22
|
+
for (let i = 0; i < Math.max(a.length, b.length); i++) {
|
|
23
|
+
if (a[i] === undefined) return -1;
|
|
24
|
+
if (b[i] === undefined) return 1;
|
|
25
|
+
const na = /^\d+$/.test(a[i]);
|
|
26
|
+
const nb = /^\d+$/.test(b[i]);
|
|
27
|
+
if (na && nb && Number(a[i]) !== Number(b[i])) return Number(a[i]) - Number(b[i]);
|
|
28
|
+
if (na !== nb) return na ? -1 : 1;
|
|
29
|
+
if (a[i] !== b[i]) return a[i] < b[i] ? -1 : 1;
|
|
30
|
+
}
|
|
31
|
+
return 0;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const compareVersions = (a, b) => {
|
|
35
|
+
const x = parse(a);
|
|
36
|
+
const y = parse(b);
|
|
37
|
+
for (let i = 0; i < 3; i++) if (x.core[i] !== y.core[i]) return x.core[i] - y.core[i];
|
|
38
|
+
return comparePre(x.pre, y.pre);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const isNewer = (a, b) => compareVersions(a, b) > 0;
|
|
42
|
+
|
|
43
|
+
module.exports = { isVersion, isRelease, compareVersions, isNewer };
|