@synopackageland/cli 0.48.15 → 0.48.17
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/CHANGELOG.md +11 -0
- package/README.md +7 -0
- package/dist/error-registry.js +20 -0
- package/dist/host/catalog-install.d.ts +5 -0
- package/dist/host/catalog-install.js +20 -9
- package/dist/host/compose-project-recovery.d.ts +14 -0
- package/dist/host/compose-project-recovery.js +68 -0
- package/dist/host/container-pull.js +12 -1
- package/dist/host/dsm-client.js +3 -1
- package/dist/host/install-plan.d.ts +2 -1
- package/dist/host/install-plan.js +9 -2
- package/dist/host/package-commands.d.ts +9 -2
- package/dist/host/package-commands.js +39 -17
- package/dist/standalone/inspect-spk.d.ts +1 -0
- package/dist/standalone/inspect-spk.js +1 -0
- package/package.json +1 -1
- package/schema/dsm-api-contract.json +54 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.48.17
|
|
4
|
+
|
|
5
|
+
- install and repair reclaim a stopped Container Manager project left behind by the same package (exact Compose path ownership) before reinstalling; named volumes, data and images are kept, and foreign or active projects stop the install
|
|
6
|
+
- repair verifies a pinned image already on the NAS by its full digest reference instead of pulling it again
|
|
7
|
+
- Add missing error registry entries and make the test suite pass under both root and non-root accounts
|
|
8
|
+
|
|
9
|
+
## 0.48.16
|
|
10
|
+
|
|
11
|
+
- install and deploy repair a broken package at its installed version with an in-place reinstall that keeps App data; healthy packages at the same version stay unchanged
|
|
12
|
+
- status shows broken packages with the exact repair command
|
|
13
|
+
|
|
3
14
|
## 0.48.15
|
|
4
15
|
|
|
5
16
|
- Accept identity_gateway.secure_context: required; check and build reject it when the pinned SDK does not support it, and the gateway shows a localized HTTPS guidance page for HTTP visits without redirecting
|
package/README.md
CHANGED
|
@@ -520,6 +520,13 @@ and daemon cause/endpoint when DSM provides them. Configure a reachable mirror,
|
|
|
520
520
|
trust an inspecting CA in Container Manager, or use `images pin` and preload the
|
|
521
521
|
pinned image. Pinning alone does not download layers onto the NAS. Pull tasks
|
|
522
522
|
are not cancelled or replayed when their response is lost or a budget expires.
|
|
523
|
+
Installing the same release of a healthy package is a no-op. For a broken package,
|
|
524
|
+
`install <package-id>@<installed-version> --yes` or `install <file.spk> --yes`
|
|
525
|
+
reports `action: "repair"` and uses DSM's in-place reinstall with the existing data;
|
|
526
|
+
it never uninstalls first. Completion requires the selected version, a running
|
|
527
|
+
payload and no broken/error state. `status <package-id>` includes the failure
|
|
528
|
+
and a pinned repair command. An unresolved repair retains its operation record;
|
|
529
|
+
check DSM Package Center before retrying, since uncertain writes are not replayed.
|
|
523
530
|
Broken packages skip stop during uninstall; their existing install error does not
|
|
524
531
|
block removal, while new uninstall errors still fail clearly.
|
|
525
532
|
Uninstall resumes a stopped or stopping package, waits for an existing uninstall,
|
package/dist/error-registry.js
CHANGED
|
@@ -332,6 +332,26 @@ export const ERROR_REGISTRY = {
|
|
|
332
332
|
description: "The package daemon declaration does not match the fixed argv, environment and lifecycle contract.",
|
|
333
333
|
suggestion: "Check daemon.exec, the per-architecture targets, args, env, uninstall_args and integer-second timeouts; remove shell, user and custom conf.",
|
|
334
334
|
},
|
|
335
|
+
STANDALONE_DAEMON_NOFILE_INVALID: {
|
|
336
|
+
code: "STANDALONE_DAEMON_NOFILE_INVALID",
|
|
337
|
+
description: "The daemon file-descriptor limit or package account is invalid.",
|
|
338
|
+
suggestion: "Use an integer daemon.nofile from 1024 to 1048576 and a valid non-root package ID; new builds currently require omitting daemon.nofile because activation is unsupported.",
|
|
339
|
+
},
|
|
340
|
+
STANDALONE_DAEMON_NOFILE_DSM_REQUIRED: {
|
|
341
|
+
code: "STANDALONE_DAEMON_NOFILE_DSM_REQUIRED",
|
|
342
|
+
description: "The declared DSM minimum does not support the daemon file-descriptor limit contract.",
|
|
343
|
+
suggestion: "Remove daemon.nofile; the legacy contract requires DSM 7.0-40761 or later and new builds currently reject activation.",
|
|
344
|
+
},
|
|
345
|
+
STANDALONE_DAEMON_NOFILE_SDK_REQUIRED: {
|
|
346
|
+
code: "STANDALONE_DAEMON_NOFILE_SDK_REQUIRED",
|
|
347
|
+
description: "The selected SDK version does not support the daemon file-descriptor limit contract.",
|
|
348
|
+
suggestion: "Remove daemon.nofile; the legacy contract requires SDK 0.49.5 or later and new builds currently reject activation.",
|
|
349
|
+
},
|
|
350
|
+
CTL_COMMAND_UNREGISTERED: {
|
|
351
|
+
code: "CTL_COMMAND_UNREGISTERED",
|
|
352
|
+
description: "A ctl command references a method that is absent from the RPC registry.",
|
|
353
|
+
suggestion: "Reference a registered RPC method in ctl commands; raw HTTP routes cannot be used as RPC methods.",
|
|
354
|
+
},
|
|
335
355
|
STANDALONE_DAEMON_RESTART_INVALID: {
|
|
336
356
|
code: "STANDALONE_DAEMON_RESTART_INVALID",
|
|
337
357
|
description: "daemon.restart does not match the bounded native crash-recovery policy.",
|
|
@@ -40,6 +40,7 @@ export declare function fetchInstalledPackageState(dsmOrigin: string, cookieHead
|
|
|
40
40
|
signal?: AbortSignal;
|
|
41
41
|
ignoreOperation?: boolean;
|
|
42
42
|
}): Promise<InstalledPackageState | undefined>;
|
|
43
|
+
export declare function packageIsBroken(state: InstalledPackageState): boolean;
|
|
43
44
|
export interface InstallWaitOptions {
|
|
44
45
|
packageId: string;
|
|
45
46
|
expectedVersion?: string;
|
|
@@ -47,6 +48,8 @@ export interface InstallWaitOptions {
|
|
|
47
48
|
pollMs?: number;
|
|
48
49
|
requireRunning?: boolean;
|
|
49
50
|
requireTransition?: boolean;
|
|
51
|
+
/** The old corrupt payload can remain visible until DSM replaces it. */
|
|
52
|
+
repairing?: boolean;
|
|
50
53
|
onProgress?: (message: string) => void;
|
|
51
54
|
maxPolls?: number;
|
|
52
55
|
consumePoll?: () => void;
|
|
@@ -78,11 +81,13 @@ export interface LocalSpkInstallOptions {
|
|
|
78
81
|
spkPath: string;
|
|
79
82
|
version: string;
|
|
80
83
|
profileName?: string;
|
|
84
|
+
repair?: boolean;
|
|
81
85
|
extraValues?: Record<string, string>;
|
|
82
86
|
deadlineMs?: number;
|
|
83
87
|
pollMs?: number;
|
|
84
88
|
onProgress?: (message: string) => void;
|
|
85
89
|
containerImages?: string[];
|
|
90
|
+
composeProject?: string;
|
|
86
91
|
maxPolls?: number;
|
|
87
92
|
signal?: AbortSignal;
|
|
88
93
|
}
|
|
@@ -2,6 +2,7 @@ import { CtlError } from '../ctl/errors.js';
|
|
|
2
2
|
import { readFileSync } from "node:fs";
|
|
3
3
|
import { progressReporter } from '../terminal-output.js';
|
|
4
4
|
import { pullContainerImages } from './container-pull.js';
|
|
5
|
+
import { reclaimOwnedComposeProject } from './compose-project-recovery.js';
|
|
5
6
|
import { savePullFailure } from './package-diagnostics.js';
|
|
6
7
|
import { readPackageOperation, operationOwnerAlive, savePackageOperation, clearPackageOperation, releasePackageOperation } from './package-operation.js';
|
|
7
8
|
import { cancelableInstall, installDelay, installWorkload, installCanceled } from './install-control.js';
|
|
@@ -161,7 +162,7 @@ export async function fetchInstalledPackageState(dsmOrigin, cookieHeader, packag
|
|
|
161
162
|
state.installed = true;
|
|
162
163
|
}
|
|
163
164
|
}
|
|
164
|
-
if (operation && !state.state && !(state.installed &&
|
|
165
|
+
if (operation && !state.state && !(state.installed && packageIsBroken(state))) {
|
|
165
166
|
const task = await dsmWebApi(dsmOrigin, cookieHeader, {
|
|
166
167
|
api: 'SYNO.Core.Package.Installation', method: 'status', version: '1', task_id: jsonApiParam(operation.taskId),
|
|
167
168
|
}, { timeoutMs, signal: context.signal, allowFailure: true });
|
|
@@ -196,7 +197,7 @@ function installStatusIsBroken(status) {
|
|
|
196
197
|
}
|
|
197
198
|
return /(broken|error|fail|150)/i.test(status);
|
|
198
199
|
}
|
|
199
|
-
function
|
|
200
|
+
export function packageIsBroken(state) {
|
|
200
201
|
return installStatusIsBroken(state.status) || state.statusCode === 150 ||
|
|
201
202
|
Boolean(state.statusCode && /broken|error|fail|corruption/i.test(state.statusDescription ?? '')) ||
|
|
202
203
|
Boolean(state.error && (state.error.code !== undefined ? state.error.code !== 0 : state.error.description));
|
|
@@ -219,6 +220,7 @@ export async function waitForInstalledVersion(readState, options) {
|
|
|
219
220
|
const pollMs = options.pollMs ?? dsmPollIntervalMs();
|
|
220
221
|
const progress = progressReporter(options.onProgress);
|
|
221
222
|
let transitioned = !options.requireTransition;
|
|
223
|
+
let repairStarted = !options.repairing;
|
|
222
224
|
while (Date.now() < deadline) {
|
|
223
225
|
consumePoll();
|
|
224
226
|
let state;
|
|
@@ -231,7 +233,9 @@ export async function waitForInstalledVersion(readState, options) {
|
|
|
231
233
|
throw error;
|
|
232
234
|
timedOut = true;
|
|
233
235
|
}
|
|
234
|
-
if (state &&
|
|
236
|
+
if (state && (installInProgress(state) || !packageIsBroken(state)))
|
|
237
|
+
repairStarted = true;
|
|
238
|
+
if (state && repairStarted && !installInProgress(state) && packageIsBroken(state)) {
|
|
235
239
|
throw new CtlError('DSM_INSTALL_FAILED', `DSM reports package ${options.packageId} install did not complete (Package Center status ${state.status ?? 'unknown'}): ${failureDetail(state)}`.trim(), 'Check the DSM Package Center install/start log');
|
|
236
240
|
}
|
|
237
241
|
const running = /^(run|running)$/i.test(state?.status ?? '');
|
|
@@ -240,7 +244,7 @@ export async function waitForInstalledVersion(readState, options) {
|
|
|
240
244
|
transitioned = true;
|
|
241
245
|
if (Date.now() >= deadline)
|
|
242
246
|
break;
|
|
243
|
-
if (state?.installed && !/installing|upgrading|starting/i.test(state.status ?? '') &&
|
|
247
|
+
if (state?.installed && !packageIsBroken(state) && !/installing|upgrading|starting/i.test(state.status ?? '') &&
|
|
244
248
|
(!options.expectedVersion || state.version === options.expectedVersion) &&
|
|
245
249
|
(!options.requireRunning || running) && transitioned)
|
|
246
250
|
return state;
|
|
@@ -292,7 +296,7 @@ export async function uninstallPackageFromDsm(options) {
|
|
|
292
296
|
if (state && Date.now() < deadline) {
|
|
293
297
|
if (done(state))
|
|
294
298
|
return state;
|
|
295
|
-
if (
|
|
299
|
+
if (packageIsBroken(state) && !(phase === 'uninstalling' && previousFailure === failureDetail(state)))
|
|
296
300
|
throw new CtlError('DSM_UNINSTALL_FAILED', `DSM reports ${options.packageId} failed while ${phase}: ${failureDetail(state) || state.status}`, 'Check the DSM Package Center stop/uninstall log');
|
|
297
301
|
}
|
|
298
302
|
progress(timedOut ? `${options.packageId}: status request timed out; ${phase}…` :
|
|
@@ -331,7 +335,7 @@ export async function uninstallPackageFromDsm(options) {
|
|
|
331
335
|
throw new CtlError('PACKAGE_BUSY', `Package ${options.packageId} has an unresolved operation`, 'Wait for DSM to finish before uninstalling');
|
|
332
336
|
if (before.installed === false)
|
|
333
337
|
return;
|
|
334
|
-
const broken =
|
|
338
|
+
const broken = packageIsBroken(before) && !installInProgress(before);
|
|
335
339
|
if (broken) {
|
|
336
340
|
previousFailure = failureDetail(before);
|
|
337
341
|
progress(`${options.packageId}: broken package (${previousFailure || before.status}); uninstalling directly without stop…`);
|
|
@@ -490,8 +494,14 @@ export async function installPackageFromLocalSpk(options) {
|
|
|
490
494
|
await installDelay(Math.min(pollMs, remaining(requestMs)), signal);
|
|
491
495
|
}
|
|
492
496
|
}
|
|
493
|
-
if (before.state || before.installed === null
|
|
497
|
+
if (before.state || before.installed === null ||
|
|
498
|
+
(options.repair && readPackageOperation(options.dsmOrigin, options.packageId)))
|
|
494
499
|
throw new CtlError('PACKAGE_BUSY', `Package ${options.packageId} already has an unresolved operation`, 'Check package status before installing again');
|
|
500
|
+
if (options.composeProject) {
|
|
501
|
+
phase = 'checking Compose project ownership';
|
|
502
|
+
await reclaimOwnedComposeProject({ ...options, projectName: options.composeProject,
|
|
503
|
+
reclaim: !before.installed || packageIsBroken(before), onProgress: progress });
|
|
504
|
+
}
|
|
495
505
|
if (options.containerImages?.length) {
|
|
496
506
|
phase = 'pulling container images';
|
|
497
507
|
try {
|
|
@@ -508,7 +518,7 @@ export async function installPackageFromLocalSpk(options) {
|
|
|
508
518
|
progress(`${options.packageId}: uploading…`);
|
|
509
519
|
const uploaded = await cancelableInstall(() => uploadLocalSpk(options, sid, remaining(operationMs)), signal);
|
|
510
520
|
const compound = JSON.stringify(catalogCompoundSteps(uploaded, { version: options.version, size: readFileSync(options.spkPath).byteLength }, { blupgrade: before.installed, extraValues: options.extraValues }));
|
|
511
|
-
phase = before.installed ? 'upgrading' : 'installing';
|
|
521
|
+
phase = options.repair ? 'repairing' : before.installed ? 'upgrading' : 'installing';
|
|
512
522
|
operation = savePackageOperation(options.dsmOrigin, options.packageId, { taskId: uploaded.taskId,
|
|
513
523
|
operation: before.installed ? 'upgrading' : 'installing', fromVersion: before.installed ? before.version : undefined, toVersion: options.version });
|
|
514
524
|
progress(`${options.packageId}: ${phase}…`);
|
|
@@ -529,7 +539,8 @@ export async function installPackageFromLocalSpk(options) {
|
|
|
529
539
|
const completed = await waitForInstalledVersion(budget => fetchInstalledPackageState(options.dsmOrigin, options.cookieHeader, options.packageId, Math.min(requestMs, budget), { signal, ignoreOperation: true }), { packageId: options.packageId, expectedVersion: options.version,
|
|
530
540
|
deadlineMs: Number.isFinite(deadline) ? remaining(Number.MAX_SAFE_INTEGER) : undefined, pollMs, requireRunning: true, consumePoll, signal,
|
|
531
541
|
// A lost same-version reinstall reply must not accept the old running instance.
|
|
532
|
-
requireTransition: timedOut && before.installed === true && before.version === options.version,
|
|
542
|
+
requireTransition: timedOut && !packageIsBroken(before) && before.installed === true && before.version === options.version,
|
|
543
|
+
repairing: options.repair && packageIsBroken(before),
|
|
533
544
|
onProgress: progress });
|
|
534
545
|
verified = true;
|
|
535
546
|
progress(`${options.packageId}: ${phase} complete (${completed.version}, DSM status ${completed.status})`);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
interface RecoveryOptions {
|
|
2
|
+
dsmOrigin: string;
|
|
3
|
+
cookieHeader: string;
|
|
4
|
+
packageId: string;
|
|
5
|
+
/** Project name from the inspected SDK Compose plan. */
|
|
6
|
+
projectName: string;
|
|
7
|
+
/** Healthy upgrades retain the worker's existing registration. */
|
|
8
|
+
reclaim: boolean;
|
|
9
|
+
signal?: AbortSignal;
|
|
10
|
+
onProgress?: (message: string) => void;
|
|
11
|
+
}
|
|
12
|
+
/** Administrator-side only. App hooks never receive this session or Docker access. */
|
|
13
|
+
export declare function reclaimOwnedComposeProject(options: RecoveryOptions): Promise<void>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { CtlError } from '../ctl/errors.js';
|
|
2
|
+
import { dsmFetch } from './dsm-http.js';
|
|
3
|
+
import { dsmOperationTimeoutMs, dsmRequestTimeoutMs } from '../nas/timeouts.js';
|
|
4
|
+
const record = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
5
|
+
const hint = 'Check this App in Container Manager. Resolve a foreign same-name project without deleting it. For an owned stopped project, preserve volumes, files and images when removing its registration, then repair this App again.';
|
|
6
|
+
const fail = (code, message) => new CtlError(code, message, hint);
|
|
7
|
+
/** Administrator-side only. App hooks never receive this session or Docker access. */
|
|
8
|
+
export async function reclaimOwnedComposeProject(options) {
|
|
9
|
+
const { packageId, projectName } = options;
|
|
10
|
+
if (!/^[A-Za-z][A-Za-z0-9_]*$/.test(packageId) || !/^[a-z0-9][a-z0-9_-]*$/.test(projectName))
|
|
11
|
+
throw fail('COMPOSE_PROJECT_INVALID', 'Invalid inspected Compose project identity');
|
|
12
|
+
const call = async (api, method, params = {}, version = 1) => {
|
|
13
|
+
const response = await dsmFetch(`${options.dsmOrigin}/webapi/entry.cgi`, {
|
|
14
|
+
method: 'POST', headers: { cookie: options.cookieHeader, 'content-type': 'application/x-www-form-urlencoded' }, signal: options.signal,
|
|
15
|
+
body: new URLSearchParams({ api, method, version: String(version), ...Object.fromEntries(Object.entries(params).map(([k, v]) => [k, JSON.stringify(v)])) }),
|
|
16
|
+
}, method === 'delete' ? dsmOperationTimeoutMs() : dsmRequestTimeoutMs());
|
|
17
|
+
const body = await response.json();
|
|
18
|
+
if (!response.ok || body?.success !== true)
|
|
19
|
+
throw fail('COMPOSE_PROJECT_RECOVERY_FAILED', `Container Manager ${method} failed (DSM ${Number(body?.error?.code) || 'unknown'}); no install request was sent`);
|
|
20
|
+
return body.data;
|
|
21
|
+
};
|
|
22
|
+
const inventory = async () => {
|
|
23
|
+
const data = await call('SYNO.Docker.Project', 'list');
|
|
24
|
+
if (!record(data) || Object.entries(data).some(([id, p]) => !record(p) || p.id !== id || typeof p.name !== 'string'))
|
|
25
|
+
throw fail('COMPOSE_PROJECT_INVENTORY_INVALID', 'Cannot verify Container Manager project inventory');
|
|
26
|
+
return Object.values(data);
|
|
27
|
+
};
|
|
28
|
+
const matches = (projects) => projects.filter(p => p.name === projectName);
|
|
29
|
+
const owned = (p) => p.is_package === true && typeof p.path === 'string' &&
|
|
30
|
+
(p.path === `/var/packages/${packageId}/target/compose` || new RegExp(`^/volume[1-9][0-9]*/@appstore/${packageId}/compose$`).test(p.path)) &&
|
|
31
|
+
(p.package_name === undefined || p.package_name === '' || p.package_name === packageId);
|
|
32
|
+
const stopped = (p) => ['STOPPED', 'CREATED'].includes(String(p.status)) &&
|
|
33
|
+
(p.state === '' || p.state === undefined) && Array.isArray(p.containerIds) && p.containerIds.every(id => typeof id === 'string');
|
|
34
|
+
const found = matches(await inventory());
|
|
35
|
+
if (!found.length)
|
|
36
|
+
return;
|
|
37
|
+
if (found.length !== 1 || !owned(found[0]))
|
|
38
|
+
throw fail('COMPOSE_PROJECT_CONFLICT', `Container Manager project ${projectName} cannot be proved to belong to ${packageId}; it was left untouched`);
|
|
39
|
+
if (!options.reclaim)
|
|
40
|
+
return;
|
|
41
|
+
const project = found[0];
|
|
42
|
+
if (!stopped(project))
|
|
43
|
+
throw fail('COMPOSE_PROJECT_NOT_STOPPED', `Stop the owned Container Manager project ${projectName} before repairing this App`);
|
|
44
|
+
// Older Docker forces --rmi all even when rmi=false. Unknown versions stay closed.
|
|
45
|
+
const packages = await call('SYNO.Core.Package', 'list', { additional: ['status'], ignore_hidden: false }, 2);
|
|
46
|
+
const manager = Array.isArray(packages?.packages) ? packages.packages.find((p) => p?.id === 'ContainerManager') : undefined;
|
|
47
|
+
if (typeof manager?.version !== 'string' || !/^24\.0\.2-\d+$/.test(manager.version))
|
|
48
|
+
throw fail('COMPOSE_PROJECT_RECOVERY_UNSUPPORTED', 'Automatic project recovery requires the verified Container Manager 24.0.2 image-preserving delete contract');
|
|
49
|
+
// Summary metadata proves ownership even when get/Detail cannot read the old
|
|
50
|
+
// definition (2105). Never rewrite Compose content or use get as a delete fallback.
|
|
51
|
+
const current = matches(await inventory());
|
|
52
|
+
if (current.length !== 1 || current[0].id !== project.id || !owned(current[0]) || !stopped(current[0]) ||
|
|
53
|
+
JSON.stringify(current[0].containerIds) !== JSON.stringify(project.containerIds))
|
|
54
|
+
throw fail('COMPOSE_PROJECT_CHANGED', 'Compose project changed during recovery; it was left untouched');
|
|
55
|
+
options.onProgress?.(`Recovering this App's stopped Compose project ${projectName}; retaining volumes, files and images…`);
|
|
56
|
+
try {
|
|
57
|
+
// Native delete can remove stopped containers/networks. These flags forbid
|
|
58
|
+
// named-volume and image deletion; no filesystem deletion API is called.
|
|
59
|
+
await call('SYNO.Docker.Project', 'delete', { id: project.id, volumes: false, rmi: false });
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
// Never replay a mutation with an uncertain outcome.
|
|
63
|
+
throw fail('COMPOSE_PROJECT_RECOVERY_FAILED', `${error instanceof CtlError && error.code === 'COMPOSE_PROJECT_RECOVERY_FAILED' ? error.message + '. ' : ''}Project removal did not confirm success; check Container Manager before retrying. No install request was sent`);
|
|
64
|
+
}
|
|
65
|
+
const remaining = await inventory();
|
|
66
|
+
if (remaining.some(p => p.id === project.id) || matches(remaining).length)
|
|
67
|
+
throw fail('COMPOSE_PROJECT_RECOVERY_FAILED', 'Project removal readback did not confirm the name is available; no install request was sent');
|
|
68
|
+
}
|
|
@@ -42,13 +42,15 @@ export async function pullContainerImages(options) {
|
|
|
42
42
|
throw fail('CONTAINER_PULL_STALLED', `no download progress for ${stallMs / 1000} seconds; NAS pull may still be running`);
|
|
43
43
|
return Math.max(1, Math.min(dsmRequestTimeoutMs(), deadline - Date.now(), stallMs - (Date.now() - lastAdvance)));
|
|
44
44
|
};
|
|
45
|
-
const call = async (method, params) => {
|
|
45
|
+
const call = async (method, params, missingImageOK = false) => {
|
|
46
46
|
const response = await dsmFetch(`${options.dsmOrigin}/webapi/entry.cgi`, {
|
|
47
47
|
method: 'POST', headers: { cookie: options.cookieHeader, 'content-type': 'application/x-www-form-urlencoded' },
|
|
48
48
|
signal: options.signal,
|
|
49
49
|
body: new URLSearchParams({ api: 'SYNO.Docker.Image', version: '1', method, ...params }),
|
|
50
50
|
}, remaining());
|
|
51
51
|
const body = await response.json();
|
|
52
|
+
if (response.ok && body?.success === false && missingImageOK && body.error?.code === 1202)
|
|
53
|
+
return undefined;
|
|
52
54
|
if (!response.ok || body?.success !== true) {
|
|
53
55
|
const error = body?.error;
|
|
54
56
|
throw fail('CONTAINER_PULL_FAILED', `Container Manager ${method}: HTTP ${response.status}, DSM ${error?.code ?? 'unknown'} ${typeof error?.description === 'string' ? error.description : ''}; cause unknown if not supplied by DSM`);
|
|
@@ -69,6 +71,15 @@ export async function pullContainerImages(options) {
|
|
|
69
71
|
progress(`${context}: pinned digest already present on NAS; no registry pull needed`);
|
|
70
72
|
continue;
|
|
71
73
|
}
|
|
74
|
+
// CM can omit digest from list. Ask the daemon to resolve the exact
|
|
75
|
+
// repository@manifest reference, never a config ID or remote update digest.
|
|
76
|
+
const detail = await call('get', { identity: JSON.stringify(image) }, true);
|
|
77
|
+
if (detail !== undefined) {
|
|
78
|
+
if (typeof detail?.id !== 'string' || !/^sha256:[a-f0-9]{64}$/.test(detail.id))
|
|
79
|
+
throw fail('CONTAINER_PULL_FAILED', 'invalid exact-reference image inspection');
|
|
80
|
+
progress(`${context}: pinned reference verified on NAS; no registry pull needed`);
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
72
83
|
}
|
|
73
84
|
let task;
|
|
74
85
|
try {
|
package/dist/host/dsm-client.js
CHANGED
|
@@ -116,6 +116,7 @@ function createDsmNasHost(credentials, profileName) {
|
|
|
116
116
|
const members = await call('SYNO.Core.Group.Member', 'list', 1, { group: 'administrators', offset: '0', limit: '-1' });
|
|
117
117
|
if (!Array.isArray(members.data?.users) || !members.data.users.some((u) => u.name === credentials.username))
|
|
118
118
|
throw new CtlError('NAS_ADMIN_REQUIRED', 'Package installation requires a DSM administrator account', 'Log in with a DSM administrator account', 4);
|
|
119
|
+
const inspected = await inspectAnySpk(input.spkPath);
|
|
119
120
|
await installPackageFromLocalSpk({
|
|
120
121
|
dsmOrigin,
|
|
121
122
|
cookieHeader: cookieHeader ?? "",
|
|
@@ -124,7 +125,8 @@ function createDsmNasHost(credentials, profileName) {
|
|
|
124
125
|
version: input.version,
|
|
125
126
|
profileName,
|
|
126
127
|
extraValues: input.extraValues,
|
|
127
|
-
containerImages: containerImageReferences(
|
|
128
|
+
containerImages: containerImageReferences(inspected),
|
|
129
|
+
composeProject: inspected.compose?.projectName,
|
|
128
130
|
});
|
|
129
131
|
},
|
|
130
132
|
async getExecutorStatus(packageIdentity) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type InstalledPackageState } from "./catalog-install.js";
|
|
1
2
|
export interface NasTarget {
|
|
2
3
|
arch: string;
|
|
3
4
|
version: string;
|
|
@@ -28,5 +29,5 @@ export interface Dependency {
|
|
|
28
29
|
}
|
|
29
30
|
export declare function dependencies(value: unknown): Dependency[];
|
|
30
31
|
export declare function satisfies(version: string, dependency: Dependency): boolean;
|
|
31
|
-
export declare function resolveInstallPlan(root: StoreEntry, entries: StoreEntry[], target: NasTarget, installed:
|
|
32
|
+
export declare function resolveInstallPlan(root: StoreEntry, entries: StoreEntry[], target: NasTarget, installed: ReadonlyMap<string, string | InstalledPackageState>): StoreEntry[];
|
|
32
33
|
export declare function verifyPins(bytes: Buffer, entry: Pick<StoreEntry, "size" | "md5" | "sha256">): void;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { packageIsBroken } from "./catalog-install.js";
|
|
1
2
|
import { createHash } from "node:crypto";
|
|
2
3
|
import { CtlError } from "../ctl/errors.js";
|
|
3
4
|
import { familyOfArchToken } from "../build-spk/dsm-arch.js";
|
|
@@ -127,9 +128,15 @@ export function resolveInstallPlan(root, entries, target, installed) {
|
|
|
127
128
|
throw fail("PACKAGE_DEPENDENCY_CONFLICT", `Conflicting dependency ${dep.id}`);
|
|
128
129
|
continue;
|
|
129
130
|
}
|
|
130
|
-
|
|
131
|
+
const current = installed.get(dep.id);
|
|
132
|
+
const currentVersion = typeof current === "string" ? current : current?.version;
|
|
133
|
+
if (typeof current === "object" && (current.state || current.installed === null))
|
|
134
|
+
throw fail("PACKAGE_BUSY", `Dependency ${dep.id} already has an unresolved operation`);
|
|
135
|
+
if (currentVersion && satisfies(currentVersion, dep) &&
|
|
136
|
+
(typeof current === "string" || !packageIsBroken(current)))
|
|
131
137
|
continue;
|
|
132
|
-
const candidates = entries.filter((e) => e.package === dep.id && satisfies(e.version, dep)
|
|
138
|
+
const candidates = entries.filter((e) => e.package === dep.id && satisfies(e.version, dep) &&
|
|
139
|
+
(!(typeof current === "object" && packageIsBroken(current) && currentVersion && satisfies(currentVersion, dep)) || e.version === currentVersion));
|
|
133
140
|
if (!candidates.length)
|
|
134
141
|
throw fail("PACKAGE_DEPENDENCY_REQUIRED", `Install required Synology package ${dep.id}${Object.entries(dep.constraints)
|
|
135
142
|
.map(([k, v]) => k + v)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type NasConnection } from "./connection.js";
|
|
2
|
+
import { type InstalledPackageState } from "./catalog-install.js";
|
|
2
3
|
import { type NasTarget, type StoreEntry } from "./install-plan.js";
|
|
3
4
|
export declare const DEFAULT_PACKAGE_SOURCE = "https://packages.synopkgland.com";
|
|
4
5
|
export declare function packageId(value: string): string;
|
|
@@ -18,6 +19,7 @@ export declare function installPackage(spec: string, options?: InstallOptions, c
|
|
|
18
19
|
source: string;
|
|
19
20
|
packages: {
|
|
20
21
|
signed?: boolean | undefined;
|
|
22
|
+
status?: string | undefined;
|
|
21
23
|
package: string;
|
|
22
24
|
version: string;
|
|
23
25
|
size: number;
|
|
@@ -31,6 +33,7 @@ export declare function installPackage(spec: string, options?: InstallOptions, c
|
|
|
31
33
|
source: string;
|
|
32
34
|
packages: {
|
|
33
35
|
signed?: boolean | undefined;
|
|
36
|
+
status?: string | undefined;
|
|
34
37
|
package: string;
|
|
35
38
|
version: string;
|
|
36
39
|
size: number;
|
|
@@ -39,13 +42,14 @@ export declare function installPackage(spec: string, options?: InstallOptions, c
|
|
|
39
42
|
parameters: string[];
|
|
40
43
|
dryRun: boolean;
|
|
41
44
|
} | {
|
|
42
|
-
status:
|
|
45
|
+
status: InstalledPackageState | undefined;
|
|
43
46
|
message?: string | undefined;
|
|
44
47
|
host: string;
|
|
45
48
|
target: NasTarget;
|
|
46
49
|
source: string;
|
|
47
50
|
packages: {
|
|
48
51
|
signed?: boolean | undefined;
|
|
52
|
+
status?: string | undefined;
|
|
49
53
|
package: string;
|
|
50
54
|
version: string;
|
|
51
55
|
size: number;
|
|
@@ -69,7 +73,10 @@ export declare function uninstallPackage(id: string, options?: {
|
|
|
69
73
|
package: string;
|
|
70
74
|
action: string;
|
|
71
75
|
}>;
|
|
72
|
-
export declare function packageStatus(id: string, host?: string): Promise<{
|
|
76
|
+
export declare function packageStatus(id: string, host?: string, connection?: NasConnection): Promise<{
|
|
77
|
+
recommendedCommand?: string | undefined;
|
|
78
|
+
message?: string | undefined;
|
|
79
|
+
broken: boolean;
|
|
73
80
|
installed: boolean | null;
|
|
74
81
|
state?: "installing" | "upgrading" | "starting" | "stopping" | "uninstalling" | "unknown";
|
|
75
82
|
fromVersion?: string;
|
|
@@ -7,7 +7,7 @@ import { inspectAnySpk } from "../spk/inspect.js";
|
|
|
7
7
|
import { containerImageReferences } from './container-pull.js';
|
|
8
8
|
import { connectNas, requireAdministrator, } from "./connection.js";
|
|
9
9
|
import { fetchPackageSource } from "../package-source.js";
|
|
10
|
-
import { fetchInstalledPackageState, installPackageFromLocalSpk, uninstallPackageFromDsm, } from "./catalog-install.js";
|
|
10
|
+
import { fetchInstalledPackageState, packageStateFromRecord, packageIsBroken, installPackageFromLocalSpk, uninstallPackageFromDsm, } from "./catalog-install.js";
|
|
11
11
|
import { assertCompatible, sourceUrl, selectEntry, resolveInstallPlan, verifyPins, compareVersions, } from "./install-plan.js";
|
|
12
12
|
export const DEFAULT_PACKAGE_SOURCE = "https://packages.synopkgland.com";
|
|
13
13
|
const fail = (code, message, hint = "Check Package Center and retry") => new CtlError(code, message, hint, 3);
|
|
@@ -49,13 +49,13 @@ export async function readFeed(source, target) {
|
|
|
49
49
|
}
|
|
50
50
|
async function inventory(nas) {
|
|
51
51
|
const data = await nas.call("SYNO.Core.Package", "list", 2, {
|
|
52
|
-
additional: '["status"]',
|
|
52
|
+
additional: '["status","installed_info"]',
|
|
53
53
|
ignore_hidden: "false",
|
|
54
54
|
});
|
|
55
55
|
if (!Array.isArray(data?.packages) ||
|
|
56
56
|
(data.total !== undefined && data.total !== data.packages.length))
|
|
57
57
|
throw fail("NAS_INVENTORY_INVALID", "Installed package inventory is incomplete");
|
|
58
|
-
return new Map(data.packages.map((p) => [p.id, p
|
|
58
|
+
return new Map(data.packages.map((p) => [p.id, packageStateFromRecord(p)]));
|
|
59
59
|
}
|
|
60
60
|
async function confirm(action, yes) {
|
|
61
61
|
if (yes)
|
|
@@ -118,12 +118,24 @@ export async function installPackage(spec, options = {}, connection) {
|
|
|
118
118
|
root = selectEntry(entries, packageId(match[1]), match[2], target);
|
|
119
119
|
}
|
|
120
120
|
const plan = resolveInstallPlan(root, entries, target, installed);
|
|
121
|
-
for (const item of plan)
|
|
122
|
-
|
|
123
|
-
|
|
121
|
+
for (const item of plan) {
|
|
122
|
+
const state = installed.get(item.package);
|
|
123
|
+
if (state?.state || state?.installed === null)
|
|
124
|
+
throw fail("PACKAGE_BUSY", `Package ${item.package} already has an unresolved operation`, "Check package status before installing again");
|
|
125
|
+
if (state && !state.version)
|
|
126
|
+
throw fail("NAS_INVENTORY_INVALID", `DSM did not report the installed version of ${item.package}`);
|
|
127
|
+
if (state && compareVersions(item.version, state.version) < 0)
|
|
124
128
|
throw fail("PACKAGE_DOWNGRADE_REFUSED", `Refusing downgrade of ${item.package}`, "Choose the installed version or a newer release");
|
|
125
|
-
|
|
126
|
-
|
|
129
|
+
}
|
|
130
|
+
const actionFor = (item) => {
|
|
131
|
+
const state = installed.get(item.package);
|
|
132
|
+
if (!state)
|
|
133
|
+
return "install";
|
|
134
|
+
if (compareVersions(item.version, state.version) !== 0)
|
|
135
|
+
return "upgrade";
|
|
136
|
+
return packageIsBroken(state) ? "repair" : "none";
|
|
137
|
+
};
|
|
138
|
+
const changes = plan.filter((item) => actionFor(item) !== "none");
|
|
127
139
|
const publicPlan = {
|
|
128
140
|
host: nas.name,
|
|
129
141
|
target,
|
|
@@ -132,11 +144,9 @@ export async function installPackage(spec, options = {}, connection) {
|
|
|
132
144
|
package: item.package,
|
|
133
145
|
version: item.version,
|
|
134
146
|
size: item.size,
|
|
135
|
-
action:
|
|
136
|
-
|
|
137
|
-
:
|
|
138
|
-
? "none"
|
|
139
|
-
: "upgrade",
|
|
147
|
+
action: actionFor(item),
|
|
148
|
+
...(installed.get(item.package)?.status
|
|
149
|
+
? { status: installed.get(item.package).status } : {}),
|
|
140
150
|
...(item.package === root.package && report
|
|
141
151
|
? { signed: report.signed }
|
|
142
152
|
: {}),
|
|
@@ -151,10 +161,11 @@ export async function installPackage(spec, options = {}, connection) {
|
|
|
151
161
|
if (!changes.length)
|
|
152
162
|
return publicPlan;
|
|
153
163
|
await requireAdministrator(nas);
|
|
154
|
-
await confirm(
|
|
164
|
+
await confirm(changes.map((e) => `${actionFor(e)} ${e.package}@${e.version}`).join(", "), options.yes);
|
|
155
165
|
// Download, verify and inspect the entire plan before the first NAS write.
|
|
156
166
|
const files = new Map();
|
|
157
167
|
const images = new Map();
|
|
168
|
+
const composeProjects = new Map();
|
|
158
169
|
for (const entry of changes) {
|
|
159
170
|
let file = localFile;
|
|
160
171
|
if (!local || entry.package !== root.package) {
|
|
@@ -173,6 +184,8 @@ export async function installPackage(spec, options = {}, connection) {
|
|
|
173
184
|
throw fail("PACKAGE_IDENTITY_MISMATCH", "Downloaded SPK identity differs from the selected release");
|
|
174
185
|
files.set(entry.package, file);
|
|
175
186
|
images.set(entry.package, containerImageReferences(checked));
|
|
187
|
+
if (checked.compose?.projectName)
|
|
188
|
+
composeProjects.set(entry.package, checked.compose.projectName);
|
|
176
189
|
}
|
|
177
190
|
let completed;
|
|
178
191
|
for (const entry of changes) {
|
|
@@ -182,7 +195,9 @@ export async function installPackage(spec, options = {}, connection) {
|
|
|
182
195
|
packageId: entry.package,
|
|
183
196
|
version: entry.version,
|
|
184
197
|
spkPath: files.get(entry.package),
|
|
198
|
+
repair: actionFor(entry) === "repair",
|
|
185
199
|
containerImages: images.get(entry.package),
|
|
200
|
+
composeProject: composeProjects.get(entry.package),
|
|
186
201
|
extraValues: entry.package === root.package ? options.param : undefined,
|
|
187
202
|
});
|
|
188
203
|
if (entry.package === root.package)
|
|
@@ -219,11 +234,18 @@ export async function uninstallPackage(id, options = {}) {
|
|
|
219
234
|
});
|
|
220
235
|
return { host: nas.name, package: id, installed: false };
|
|
221
236
|
}
|
|
222
|
-
export async function packageStatus(id, host) {
|
|
237
|
+
export async function packageStatus(id, host, connection) {
|
|
223
238
|
packageId(id);
|
|
224
|
-
const nas = await connectNas(host);
|
|
239
|
+
const nas = connection ?? await connectNas(host);
|
|
225
240
|
const state = await fetchInstalledPackageState(nas.session.origin, nas.session.cookie, id);
|
|
226
241
|
if (!state)
|
|
227
242
|
throw fail("PACKAGE_STATUS_UNKNOWN", "DSM did not return a verifiable package state");
|
|
228
|
-
|
|
243
|
+
const broken = packageIsBroken(state);
|
|
244
|
+
const quotedHost = "'" + nas.name.replace(/'/g, "'\\''") + "'";
|
|
245
|
+
return { host: nas.name, package: id, ...state, broken,
|
|
246
|
+
...(broken && state.version && /^[0-9][0-9._-]*$/.test(state.version) && !state.state ? {
|
|
247
|
+
recommendedCommand: `synopkgland install ${id}@${state.version}${nas.name === "env" ? "" : ` --host ${quotedHost}`} --yes`,
|
|
248
|
+
message: "Package is broken; reinstall the same release to repair it while retaining data",
|
|
249
|
+
} : {}),
|
|
250
|
+
};
|
|
229
251
|
}
|
|
@@ -901,6 +901,7 @@ async function inspectUnifiedCompose(dir, payload, metadata, findings) {
|
|
|
901
901
|
if (storageProblem)
|
|
902
902
|
throw new Error(`[${storageProblem.code}] ${storageProblem.message}`);
|
|
903
903
|
base.compose = {
|
|
904
|
+
projectName: c.plan.project_name,
|
|
904
905
|
...(c.plan.host_udp?.length ? { hostUdp: c.plan.host_udp } : {}),
|
|
905
906
|
...(c.plan.devices ? { devices: c.plan.devices } : {}),
|
|
906
907
|
...(c.plan.ingress ? { ingress: c.plan.ingress } : {}),
|
package/package.json
CHANGED
|
@@ -1059,6 +1059,54 @@
|
|
|
1059
1059
|
"standalone/root-window.ts"
|
|
1060
1060
|
],
|
|
1061
1061
|
"hubConfirmed": []
|
|
1062
|
+
},
|
|
1063
|
+
{
|
|
1064
|
+
"api": "SYNO.Docker.Project",
|
|
1065
|
+
"method": "list",
|
|
1066
|
+
"version": 1,
|
|
1067
|
+
"dsm": {
|
|
1068
|
+
"7.2": "unverified",
|
|
1069
|
+
"7.3": "unverified",
|
|
1070
|
+
"7.4": "unverified"
|
|
1071
|
+
},
|
|
1072
|
+
"parameters": {},
|
|
1073
|
+
"sources": [
|
|
1074
|
+
"host/compose-project-recovery.ts"
|
|
1075
|
+
]
|
|
1076
|
+
},
|
|
1077
|
+
{
|
|
1078
|
+
"api": "SYNO.Docker.Project",
|
|
1079
|
+
"method": "delete",
|
|
1080
|
+
"version": 1,
|
|
1081
|
+
"dsm": {
|
|
1082
|
+
"7.2": "unverified",
|
|
1083
|
+
"7.3": "unverified",
|
|
1084
|
+
"7.4": "unverified"
|
|
1085
|
+
},
|
|
1086
|
+
"parameters": {
|
|
1087
|
+
"id": {},
|
|
1088
|
+
"volumes": {},
|
|
1089
|
+
"rmi": {}
|
|
1090
|
+
},
|
|
1091
|
+
"sources": [
|
|
1092
|
+
"host/compose-project-recovery.ts"
|
|
1093
|
+
]
|
|
1094
|
+
},
|
|
1095
|
+
{
|
|
1096
|
+
"api": "SYNO.Docker.Image",
|
|
1097
|
+
"method": "get",
|
|
1098
|
+
"version": 1,
|
|
1099
|
+
"dsm": {
|
|
1100
|
+
"7.2": "unverified",
|
|
1101
|
+
"7.3": "unverified",
|
|
1102
|
+
"7.4": "confirmed"
|
|
1103
|
+
},
|
|
1104
|
+
"parameters": {
|
|
1105
|
+
"identity": {}
|
|
1106
|
+
},
|
|
1107
|
+
"sources": [
|
|
1108
|
+
"host/container-pull.ts"
|
|
1109
|
+
]
|
|
1062
1110
|
}
|
|
1063
1111
|
],
|
|
1064
1112
|
"sourceAudit": {
|
|
@@ -1075,13 +1123,14 @@
|
|
|
1075
1123
|
"deploy/spk-version.ts": "407a79491ffac8d00ecb9b056ab0b352e08bf6142871fa46f302fd217f98fc24",
|
|
1076
1124
|
"e2e/certificates.ts": "e9801e5f4d326d31c3c281e5106f34138493e26cd7f0ad2b1dd3f6a566832389",
|
|
1077
1125
|
"e2e/dsm.ts": "407fa489a7fa44a5fa851e4acc019acec582dd3bb02fa4f0e4c6f2f82d1d92da",
|
|
1078
|
-
"error-registry.ts": "
|
|
1079
|
-
"host/catalog-install.ts": "
|
|
1080
|
-
"host/
|
|
1081
|
-
"host/
|
|
1126
|
+
"error-registry.ts": "4c34a6e4c229ddc067a8ca9344cdd52b64a9a6352570600657260d6a55967125",
|
|
1127
|
+
"host/catalog-install.ts": "df27409d835a901658dae7c2048c9028c2dc886e17575fe9189e88ae705c0fd2",
|
|
1128
|
+
"host/compose-project-recovery.ts": "c76efa505f8ba14f50a8705b63d0f9f8a022b70505fe6a5f5976146afae17532",
|
|
1129
|
+
"host/container-pull.ts": "d85314dd265f7609ab1fda87e23cce0fa81165baeeaf79a792d7bb6dc10338e3",
|
|
1130
|
+
"host/dsm-client.ts": "52c34d520154e43d823a64dbb0ff7f3ae40e427fb835a5136ab6d847827a4b7a",
|
|
1082
1131
|
"host/dsm-compound.ts": "5674b6f11d2b36a86a97ac7edf590abb34bd72f441c1f43ab057a43cfb5d7e88",
|
|
1083
1132
|
"host/dsm-port-profile.ts": "9ebd06bbbc918267ef2d8a4ff9737b9d35579e45224dd4de362389921446ae8d",
|
|
1084
|
-
"host/package-commands.ts": "
|
|
1133
|
+
"host/package-commands.ts": "ba1debaee82b19f310efe59eb0692a6495282e0e5e2ac2b474a8b85465eadafc",
|
|
1085
1134
|
"host/port-info-lookup.ts": "b7af19dd8194bc424eb2100ce5953cf0737e8158da373e93b66627c6a7028c8e",
|
|
1086
1135
|
"host/port-info.ts": "9ab70c37860df681bee70039aebda9ad974fbd2e200fc2741daf9aacf7943905",
|
|
1087
1136
|
"host/share-lookup.ts": "c158baffc774cb7b5b36a82b633bc48f7b8522f67972ef09ab1a15a8b4609196",
|