@camunda8/cli 4.7.0-alpha.26 → 4.7.0-alpha.27
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.
|
@@ -77,7 +77,7 @@ patch releases.
|
|
|
77
77
|
|
|
78
78
|
### `start` vs `install` update behavior
|
|
79
79
|
|
|
80
|
-
- **`start`** uses the local version if available. A non-blocking remote check runs in the background — if a newer rolling release exists, a hint is printed (e.g. *"A newer server version is available. Install it with: c8ctl cluster install 8.9"*). If the network is unreachable, the hint is silently skipped.
|
|
80
|
+
- **`start`** uses the local version if available. A non-blocking remote check runs in the background — if a newer rolling release exists, a hint is printed (e.g. *"A newer server version is available. Install it with: c8ctl cluster install 8.9"*). If the network is unreachable, the hint is silently skipped. When starting a named alias (`stable`, `alpha`) whose newer target is already installed (e.g. via `c8ctl cluster install 8.10`), the check instead updates the cached alias so the next `start` uses that version, without downloading anything. If `start` fails, c8ctl waits up to one second for these checks before exiting, so the hint is not lost.
|
|
81
81
|
- **`install`** always checks the remote for a newer rolling release (via ETag comparison) and re-downloads if one is available.
|
|
82
82
|
|
|
83
83
|
If the download server is unreachable, the aliases fall back to the values
|
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
import { once } from 'node:events';
|
|
28
28
|
import { chmod } from 'node:fs/promises';
|
|
29
29
|
import { homedir, platform as osPlatform, arch as osArch } from 'node:os';
|
|
30
|
-
import { join, dirname, isAbsolute, resolve } from 'node:path';
|
|
30
|
+
import { join, dirname, basename, isAbsolute, resolve } from 'node:path';
|
|
31
31
|
import { finished } from 'node:stream/promises';
|
|
32
32
|
import { StringDecoder } from 'node:string_decoder';
|
|
33
33
|
import { fileURLToPath } from 'node:url';
|
|
@@ -215,37 +215,57 @@ function readLocalAliasMapping(cacheDir, alias) {
|
|
|
215
215
|
const filePath = getAliasMappingPath(cacheDir, alias);
|
|
216
216
|
if (!existsSync(filePath)) return null;
|
|
217
217
|
try {
|
|
218
|
-
const value = readFileSync(filePath, 'utf-8').trim();
|
|
219
218
|
// Only use the cached mapping if the version is actually installed
|
|
220
|
-
|
|
221
|
-
if (isC8RunInstalled(config)) return value;
|
|
222
|
-
|
|
223
|
-
// For rolling versions (minor version patterns like "8.9"), check if any
|
|
224
|
-
// installed version matches the minor version prefix (e.g. "8.9" matches
|
|
225
|
-
// "8.9.5"). This prevents re-downloading a rolling alias when a compatible
|
|
226
|
-
// pinned version is already installed locally (#431).
|
|
227
|
-
if (isMinorVersionPattern(value)) {
|
|
228
|
-
const installedVersions = getInstalledVersionsList(cacheDir)
|
|
229
|
-
.sort((a, b) => a.localeCompare(b, undefined, { numeric: true }));
|
|
230
|
-
const match = installedVersions
|
|
231
|
-
.filter((v) => v.startsWith(value + '.'))
|
|
232
|
-
.reverse()
|
|
233
|
-
.find((v) => isC8RunInstalled({ cacheDir, version: v }));
|
|
234
|
-
if (match) return match;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
return null;
|
|
219
|
+
return findInstalledAliasTarget(cacheDir, readFileSync(filePath, 'utf-8').trim(), alias);
|
|
238
220
|
} catch {
|
|
239
221
|
return null;
|
|
240
222
|
}
|
|
241
223
|
}
|
|
242
224
|
|
|
225
|
+
/**
|
|
226
|
+
* Return the installed version that satisfies an alias target, or null.
|
|
227
|
+
* An exact install wins; for a rolling minor pattern ("8.9") the highest
|
|
228
|
+
* installed pin in that minor line ("8.9.5") also counts, so a compatible
|
|
229
|
+
* pinned install is not re-downloaded (#431). For `stable`, an install whose
|
|
230
|
+
* build is a prerelease never counts — whether pinned ("c8run-8.10.0-alpha1")
|
|
231
|
+
* or a rolling dir that still holds an alpha build ("c8run-8.10/c8run-8.10.0-alpha1").
|
|
232
|
+
*/
|
|
233
|
+
function findInstalledAliasTarget(cacheDir, value, alias) {
|
|
234
|
+
const accepts = (version) => {
|
|
235
|
+
const binaryPath = findC8RunBinaryPath({ cacheDir, version });
|
|
236
|
+
if (!binaryPath) return false;
|
|
237
|
+
return alias !== 'stable' || !isPrereleaseBuild(basename(dirname(binaryPath)));
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
if (accepts(value)) return value;
|
|
241
|
+
|
|
242
|
+
if (isMinorVersionPattern(value)) {
|
|
243
|
+
const installedVersions = getInstalledVersionsList(cacheDir)
|
|
244
|
+
.sort((a, b) => a.localeCompare(b, undefined, { numeric: true }));
|
|
245
|
+
const match = installedVersions
|
|
246
|
+
.filter((v) => v.startsWith(value + '.'))
|
|
247
|
+
.reverse()
|
|
248
|
+
.find(accepts);
|
|
249
|
+
if (match) return match;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
return null;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/** True for a build dir like "c8run-8.10.0-alpha1" (anything with a semver prerelease suffix). */
|
|
256
|
+
function isPrereleaseBuild(buildDirName) {
|
|
257
|
+
return /^c8run-\d+\.\d+(\.\d+)?-/.test(buildDirName);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/** Persist an alias mapping. Returns false if it could not be written. */
|
|
243
261
|
export function storeLocalAliasMapping(cacheDir, alias, resolved) {
|
|
244
262
|
try {
|
|
245
263
|
mkdirSync(cacheDir, { recursive: true });
|
|
246
264
|
writeFileSync(getAliasMappingPath(cacheDir, alias), resolved);
|
|
265
|
+
return true;
|
|
247
266
|
} catch {
|
|
248
267
|
// Best-effort — don't break the command if we can't persist
|
|
268
|
+
return false;
|
|
249
269
|
}
|
|
250
270
|
}
|
|
251
271
|
|
|
@@ -270,16 +290,21 @@ export function _resetDynamicAliasCache() {
|
|
|
270
290
|
}
|
|
271
291
|
|
|
272
292
|
/**
|
|
273
|
-
* Non-blocking background check: query the remote download server and
|
|
274
|
-
*
|
|
293
|
+
* Non-blocking background check: query the remote download server and act
|
|
294
|
+
* if the remote alias resolves to a newer minor than the one being started.
|
|
295
|
+
*
|
|
296
|
+
* - Newer version already installed (e.g. via `cluster install 8.10`): the
|
|
297
|
+
* persisted alias mapping is advanced to it, so the *next* `start` uses it.
|
|
298
|
+
* Nothing is downloaded — the user already chose to install that version.
|
|
299
|
+
* - Newer version not installed: only a hint is printed; the mapping is left
|
|
300
|
+
* alone so `start` never silently switches to a version it would have to
|
|
301
|
+
* download.
|
|
275
302
|
*
|
|
276
|
-
*
|
|
277
|
-
* updated when the user explicitly runs `cluster install`, keeping `start`
|
|
278
|
-
* deterministic across runs.
|
|
303
|
+
* The current run is never affected: it has already resolved its version.
|
|
279
304
|
*
|
|
280
305
|
* Returns the fire-and-forget promise (for testing).
|
|
281
306
|
*/
|
|
282
|
-
export function checkBackgroundAliasFreshness(versionSpec, resolvedVersion) {
|
|
307
|
+
export function checkBackgroundAliasFreshness(versionSpec, resolvedVersion, cacheDir) {
|
|
283
308
|
const logger = getLogger();
|
|
284
309
|
const controller = new AbortController();
|
|
285
310
|
const timeoutId = setTimeout(() => controller.abort(), 5000);
|
|
@@ -290,7 +315,22 @@ export function checkBackgroundAliasFreshness(versionSpec, resolvedVersion) {
|
|
|
290
315
|
if (html) {
|
|
291
316
|
const remote = parseVersionsFromHtml(html);
|
|
292
317
|
const remoteVersion = remote?.[versionSpec];
|
|
293
|
-
if (remoteVersion
|
|
318
|
+
if (!remoteVersion || !isRemoteMinorNewer(remoteVersion, resolvedVersion)) return;
|
|
319
|
+
const installed = cacheDir && findInstalledAliasTarget(cacheDir, remoteVersion, versionSpec);
|
|
320
|
+
if (installed) {
|
|
321
|
+
if (storeLocalAliasMapping(cacheDir, versionSpec, remoteVersion)) {
|
|
322
|
+
logger.info(
|
|
323
|
+
`"${versionSpec}" now resolves to ${remoteVersion}, which is already installed. ` +
|
|
324
|
+
`The next "c8ctl cluster start ${versionSpec}" will use it.`,
|
|
325
|
+
);
|
|
326
|
+
} else {
|
|
327
|
+
// Name the exact install: a plain "8.10" would look for c8run-8.10 and download it.
|
|
328
|
+
logger.info(
|
|
329
|
+
`"${versionSpec}" now resolves to ${remoteVersion}, which is already installed, ` +
|
|
330
|
+
`but the cached alias could not be updated. Start it with: c8ctl cluster start ${installed}`,
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
} else {
|
|
294
334
|
logger.info(
|
|
295
335
|
`A newer "${versionSpec}" release is available (${remoteVersion}). ` +
|
|
296
336
|
`Install it with: c8ctl cluster install ${versionSpec}`,
|
|
@@ -315,6 +355,25 @@ function fireAndForget(promise) {
|
|
|
315
355
|
return promise.catch(() => {});
|
|
316
356
|
}
|
|
317
357
|
|
|
358
|
+
/**
|
|
359
|
+
* Give the background `start` hints (alias freshness, rolling update) a short,
|
|
360
|
+
* bounded chance to print before a failed start calls process.exit(), which
|
|
361
|
+
* would otherwise drop them mid-flight. A failed start is when a newer version
|
|
362
|
+
* is most worth knowing about.
|
|
363
|
+
*/
|
|
364
|
+
export async function flushStartHints(config, timeoutMs = 1000) {
|
|
365
|
+
const pending = [config?._aliasHintPromise, config?._hintPromise].filter(Boolean);
|
|
366
|
+
if (pending.length === 0) return;
|
|
367
|
+
let timer;
|
|
368
|
+
await Promise.race([
|
|
369
|
+
Promise.all(pending),
|
|
370
|
+
new Promise((resolve) => {
|
|
371
|
+
timer = setTimeout(resolve, timeoutMs);
|
|
372
|
+
}),
|
|
373
|
+
]);
|
|
374
|
+
clearTimeout(timer);
|
|
375
|
+
}
|
|
376
|
+
|
|
318
377
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
319
378
|
|
|
320
379
|
// ---------------------------------------------------------------------------
|
|
@@ -1716,9 +1775,13 @@ async function startC8Run(config, debug = false, startArgs = []) {
|
|
|
1716
1775
|
});
|
|
1717
1776
|
|
|
1718
1777
|
if (typeof proc.pid !== 'number') {
|
|
1778
|
+
// spawn() reports this failure via an async 'error' event; without a
|
|
1779
|
+
// listener it would crash the process while the hints are flushed below.
|
|
1780
|
+
proc.on('error', (err) => logger.error(`Failed to spawn c8run: ${err.message}`));
|
|
1719
1781
|
logger.error('Failed to start cluster process: no PID received from c8run.');
|
|
1720
1782
|
logger.error(`Check logs in: ${logDir}`);
|
|
1721
1783
|
logger.info(`Print logs with: cat "${logDir}"/*.log`, { essential: true });
|
|
1784
|
+
await flushStartHints(config);
|
|
1722
1785
|
process.exit(1);
|
|
1723
1786
|
}
|
|
1724
1787
|
|
|
@@ -1772,6 +1835,7 @@ async function startC8Run(config, debug = false, startArgs = []) {
|
|
|
1772
1835
|
logger.error(
|
|
1773
1836
|
`c8run start exited with code ${exitCode ?? 'unknown'}${exitSignal ? ` (signal: ${exitSignal})` : ''}. Cluster will not be marked as running.`,
|
|
1774
1837
|
);
|
|
1838
|
+
await flushStartHints(config);
|
|
1775
1839
|
process.exit(typeof exitCode === 'number' && exitCode > 0 ? exitCode : 1);
|
|
1776
1840
|
}
|
|
1777
1841
|
|
|
@@ -3821,11 +3885,6 @@ export const commands = {
|
|
|
3821
3885
|
logger.info(`Resolved alias "${versionSpec}" → ${version}`);
|
|
3822
3886
|
}
|
|
3823
3887
|
|
|
3824
|
-
// For start with a named alias, check in the background whether the
|
|
3825
|
-
// remote resolves to a different (newer) version and hint if so.
|
|
3826
|
-
if (isStart && isVersionAlias(versionSpec)) {
|
|
3827
|
-
checkBackgroundAliasFreshness(versionSpec, version);
|
|
3828
|
-
}
|
|
3829
3888
|
const rolling = isRollingVersion(versionSpec);
|
|
3830
3889
|
const config = {
|
|
3831
3890
|
cacheDir: theCacheDir,
|
|
@@ -3839,12 +3898,19 @@ export const commands = {
|
|
|
3839
3898
|
verbose: ctx?.verbose === true,
|
|
3840
3899
|
};
|
|
3841
3900
|
|
|
3901
|
+
// For start with a named alias, check in the background whether the
|
|
3902
|
+
// remote resolves to a different (newer) version and hint if so.
|
|
3903
|
+
if (isStart && isVersionAlias(versionSpec)) {
|
|
3904
|
+
config._aliasHintPromise = checkBackgroundAliasFreshness(versionSpec, version, theCacheDir);
|
|
3905
|
+
}
|
|
3906
|
+
|
|
3842
3907
|
if (parsed.subcommand === 'start') {
|
|
3843
3908
|
try {
|
|
3844
3909
|
await ensureC8RunInstalled(config);
|
|
3845
3910
|
await startC8Run(config, parsed.debug, parsed.startArgs);
|
|
3846
3911
|
} catch (error) {
|
|
3847
3912
|
logger.error(`Failed to start cluster: ${formatErrorWithCause(error)}`);
|
|
3913
|
+
await flushStartHints(config);
|
|
3848
3914
|
process.exit(1);
|
|
3849
3915
|
}
|
|
3850
3916
|
} else if (parsed.subcommand === 'stop') {
|