swarm-deploy 0.1.0 → 0.2.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/CHANGELOG.md +44 -0
- package/README.md +680 -49
- package/RELEASING.md +2 -2
- package/SECURITY.md +2 -3
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +79 -22
- package/dist/cli.js.map +1 -1
- package/dist/client.d.ts +19 -29
- package/dist/client.js +46 -55
- package/dist/client.js.map +1 -1
- package/dist/errors.d.ts +4 -0
- package/dist/errors.js +4 -0
- package/dist/errors.js.map +1 -1
- package/dist/files.d.ts +13 -28
- package/dist/files.js +13 -78
- package/dist/files.js.map +1 -1
- package/dist/hooks-module.d.ts +9 -0
- package/dist/hooks-module.js +118 -0
- package/dist/hooks-module.js.map +1 -0
- package/dist/hooks.d.ts +69 -0
- package/dist/hooks.js +88 -0
- package/dist/hooks.js.map +1 -0
- package/dist/index.d.ts +7 -3
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/release.d.ts +26 -0
- package/dist/release.js +419 -0
- package/dist/release.js.map +1 -0
- package/dist/server.d.ts +86 -0
- package/dist/server.js +405 -53
- package/dist/server.js.map +1 -1
- package/dist/storage/commit-journal.d.ts +39 -2
- package/dist/storage/commit-journal.js +140 -2
- package/dist/storage/commit-journal.js.map +1 -1
- package/dist/storage/commit-store.d.ts +69 -8
- package/dist/storage/commit-store.js +374 -22
- package/dist/storage/commit-store.js.map +1 -1
- package/dist/storage/layout.js +7 -1
- package/dist/storage/layout.js.map +1 -1
- package/dist/storage/link-store.d.ts +70 -0
- package/dist/storage/link-store.js +363 -0
- package/dist/storage/link-store.js.map +1 -0
- package/dist/storage/recovery.d.ts +2 -1
- package/dist/storage/recovery.js +8 -1
- package/dist/storage/recovery.js.map +1 -1
- package/dist/storage/retention.d.ts +41 -21
- package/dist/storage/retention.js +162 -8
- package/dist/storage/retention.js.map +1 -1
- package/dist/storage/tar-session-store.d.ts +36 -5
- package/dist/storage/tar-session-store.js +283 -55
- package/dist/storage/tar-session-store.js.map +1 -1
- package/dist/storage/tree-fs.d.ts +44 -0
- package/dist/storage/tree-fs.js +580 -0
- package/dist/storage/tree-fs.js.map +1 -0
- package/dist/storage/tree-staging.d.ts +9 -0
- package/dist/storage/tree-staging.js +64 -0
- package/dist/storage/tree-staging.js.map +1 -0
- package/dist/storage/types.d.ts +15 -0
- package/dist/symlinks.d.ts +36 -0
- package/dist/symlinks.js +128 -0
- package/dist/symlinks.js.map +1 -0
- package/dist/tar-protocol/controls.d.ts +25 -0
- package/dist/tar-protocol/controls.js +108 -2
- package/dist/tar-protocol/controls.js.map +1 -1
- package/dist/tar-protocol/direct-wire.d.ts +3 -3
- package/dist/tar-protocol/direct-wire.js +2 -2
- package/dist/tar-protocol/direct-wire.js.map +1 -1
- package/dist/tar-protocol/manifest.d.ts +13 -1
- package/dist/tar-protocol/manifest.js +26 -1
- package/dist/tar-protocol/manifest.js.map +1 -1
- package/dist/tar-protocol/tree-extract.d.ts +37 -0
- package/dist/tar-protocol/tree-extract.js +240 -0
- package/dist/tar-protocol/tree-extract.js.map +1 -0
- package/dist/tar-protocol/tree-manifest.d.ts +45 -0
- package/dist/tar-protocol/tree-manifest.js +277 -0
- package/dist/tar-protocol/tree-manifest.js.map +1 -0
- package/dist/tar-protocol/tree-path.d.ts +15 -0
- package/dist/tar-protocol/tree-path.js +68 -0
- package/dist/tar-protocol/tree-path.js.map +1 -0
- package/dist/tar-protocol/tree.d.ts +68 -0
- package/dist/tar-protocol/tree.js +269 -0
- package/dist/tar-protocol/tree.js.map +1 -0
- package/dist/tar-protocol/ustar.d.ts +14 -0
- package/dist/tar-protocol/ustar.js +81 -1
- package/dist/tar-protocol/ustar.js.map +1 -1
- package/dist/types.d.ts +3 -0
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -155,7 +155,12 @@ swarm-deploy server \
|
|
|
155
155
|
[--allow-key <64-lower-hex>]... \
|
|
156
156
|
[--max-storage-bytes <bytes>] \
|
|
157
157
|
[--max-age-days <days>] \
|
|
158
|
-
[--replace-name <safe-basename>]...
|
|
158
|
+
[--replace-name <safe-basename>]... \
|
|
159
|
+
[--artifact-pattern <template>]... \
|
|
160
|
+
[--max-count <count>] \
|
|
161
|
+
[--max-versions <count> --version-granularity <major|minor>] \
|
|
162
|
+
[--symlink <selector> <link-name>]... \
|
|
163
|
+
[--hooks <module>]
|
|
159
164
|
```
|
|
160
165
|
|
|
161
166
|
Replace `--seed-file <seed-file>` with `--seed <64-lower-hex>` to provide the
|
|
@@ -181,6 +186,30 @@ Optional options:
|
|
|
181
186
|
- `--max-age-days`: remove eligible committed artifacts at or beyond this age.
|
|
182
187
|
- `--replace-name`: permit replacement of this exact basename. Repeat for
|
|
183
188
|
multiple mutable names.
|
|
189
|
+
- `--artifact-pattern <template>`: identify releases and make matching
|
|
190
|
+
mandatory. Repeat for multiple templates; declaration order is match order.
|
|
191
|
+
See [Artifact patterns and rotation](#artifact-patterns-and-rotation).
|
|
192
|
+
- `--max-count <count>`: keep the newest `<count>` releases per series. Requires
|
|
193
|
+
at least one `--artifact-pattern`.
|
|
194
|
+
- `--max-versions <count>`: keep every release in the newest `<count>` distinct
|
|
195
|
+
version groups per series. Requires a pattern containing `{version}` and
|
|
196
|
+
`--version-granularity`.
|
|
197
|
+
- `--version-granularity <major|minor>`: how versions are grouped for
|
|
198
|
+
`--max-versions`. It is rejected without `--max-versions`, and there is no
|
|
199
|
+
default.
|
|
200
|
+
- `--symlink <selector> <link-name>`: declarative managed symlink rule.
|
|
201
|
+
Repeat for multiple links. A selector that begins and ends with `/` is an
|
|
202
|
+
unflagged regular expression matched against managed artifact basenames;
|
|
203
|
+
anything else is an exact managed basename. The link name must be a safe
|
|
204
|
+
single-component basename and must not collide with another rule.
|
|
205
|
+
- `--hooks <module>`: JavaScript module (`.js`, `.mjs`, or `.cjs`) exporting
|
|
206
|
+
trusted lifecycle callbacks. The path is resolved against the working
|
|
207
|
+
directory. See [Deployment hooks](#deployment-hooks).
|
|
208
|
+
|
|
209
|
+
All counts are positive safe integers. Invalid combinations, malformed or
|
|
210
|
+
duplicate templates, and unloadable hook modules are configuration errors that
|
|
211
|
+
exit `2` before the server listens. Each hooks-module error names only the
|
|
212
|
+
module basename with a fixed reason, never module content.
|
|
184
213
|
|
|
185
214
|
The CLI requires at least one `--allow-key`. Its snapshot is immutable for the
|
|
186
215
|
life of the process.
|
|
@@ -192,6 +221,7 @@ swarm-deploy upload \
|
|
|
192
221
|
--seed-file <seed-file> \
|
|
193
222
|
--server-key <64-lower-hex> \
|
|
194
223
|
[--idle-timeout <milliseconds>] \
|
|
224
|
+
[--no-source-parent] \
|
|
195
225
|
<file-or-directory>
|
|
196
226
|
```
|
|
197
227
|
|
|
@@ -204,12 +234,19 @@ seed inline.
|
|
|
204
234
|
- The input may be any regular binary file; Swarm Deploy creates the canonical
|
|
205
235
|
one-entry USTAR stream automatically. Pre-tarring is not required.
|
|
206
236
|
- A direct file retains its basename.
|
|
207
|
-
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
237
|
+
- Each upload also carries the immediate local parent directory name as
|
|
238
|
+
optional `sourceParent` metadata, but only when that name is a safe single
|
|
239
|
+
component (see [Source parent](#source-parent)).
|
|
240
|
+
- `--no-source-parent` takes no value and suppresses that metadata for every
|
|
241
|
+
file in the run. The upload then keeps the legacy transfer identity and
|
|
242
|
+
cannot match a server pattern with a parent segment.
|
|
243
|
+
- A directory input commits exactly one recursive managed directory artifact
|
|
244
|
+
named after the input basename. Every member must be a safe regular file or
|
|
245
|
+
directory; symlinks, hard links, devices, sockets, FIFOs, unsafe names,
|
|
246
|
+
over-depth, over-count, or over-length members reject the whole upload.
|
|
247
|
+
Nothing is silently skipped.
|
|
248
|
+
- On success the CLI prints one line: `<name> <kind> <status>` (for example
|
|
249
|
+
`0.18.1 directory COMMITTED`).
|
|
213
250
|
|
|
214
251
|
Accepted names start with an ASCII letter or digit, contain only letters,
|
|
215
252
|
digits, `.`, `_`, and `-`, and occupy at most 100 UTF-8 bytes. `history-` is
|
|
@@ -240,13 +277,10 @@ tooling logs is acceptable.
|
|
|
240
277
|
|
|
241
278
|
### CLI exit codes
|
|
242
279
|
|
|
243
|
-
- `0`:
|
|
280
|
+
- `0`: the upload committed or was already committed.
|
|
244
281
|
- `1`: upload, network, protocol, storage, cleanup, or runtime failure.
|
|
245
282
|
- `2`: usage or configuration error.
|
|
246
283
|
|
|
247
|
-
For a directory, the CLI prints one line for every selected or skipped entry and
|
|
248
|
-
returns `1` if any selected upload failed.
|
|
249
|
-
|
|
250
284
|
## CI uploader example
|
|
251
285
|
|
|
252
286
|
Store the client seed as a protected CI secret and the server public key as a
|
|
@@ -279,7 +313,7 @@ Each file follows this lifecycle:
|
|
|
279
313
|
2. The server firewall and connection handler verify the authenticated client
|
|
280
314
|
key against the startup allowlist.
|
|
281
315
|
3. The client sends bounded metadata containing the name, file size and digest,
|
|
282
|
-
deterministic TAR size and digest, and
|
|
316
|
+
deterministic TAR size and digest, transfer ID, and optional `sourceParent`.
|
|
283
317
|
4. The server responds with `ACCEPT`, `RESUME`, `VERIFIED`,
|
|
284
318
|
`ALREADY_COMMITTED`, or a stable rejection.
|
|
285
319
|
5. The client sends exactly the required deterministic one-entry USTAR bytes.
|
|
@@ -331,9 +365,23 @@ Optional retention applies to managed artifacts only:
|
|
|
331
365
|
- `maxAge`/`--max-age-days` removes eligible artifacts by age.
|
|
332
366
|
- `maxStorageBytes`/`--max-storage-bytes` removes the oldest eligible artifacts
|
|
333
367
|
until under quota.
|
|
334
|
-
-
|
|
335
|
-
|
|
336
|
-
|
|
368
|
+
- `maxCount`/`--max-count` and `maxVersions`/`--max-versions` rotate released
|
|
369
|
+
artifacts by series; see
|
|
370
|
+
[Artifact patterns and rotation](#artifact-patterns-and-rotation).
|
|
371
|
+
- Directory artifacts are create-only. A directory offer for a configured
|
|
372
|
+
`replaceNames` entry, a file-to-directory kind change, or a directory-to-file
|
|
373
|
+
kind change is rejected. Directory replacement and history are deferred.
|
|
374
|
+
- Committed artifacts, including directories, are immutable on disk. Do not write
|
|
375
|
+
into a committed directory after publish: hooks must not run `npm ci`, create
|
|
376
|
+
`.cache`, dotfiles, or extra symlinks inside the tree. If the tree changes,
|
|
377
|
+
startup hash scrub drops the sidecar while leaving the bytes in place, the
|
|
378
|
+
name stays occupied (`FILE_EXISTS`), the tree falls outside quota and rotation,
|
|
379
|
+
and a managed `latest` link can move to an older release.
|
|
380
|
+
- Managed directories are deleted by renaming into `.swarm-deploy/trash` before
|
|
381
|
+
recursive removal. Startup sweeps proven trash residue.
|
|
382
|
+
- Startup recovery re-hashes managed files and recursively verifies directory
|
|
383
|
+
tree digests. Scheduled and pre-commit passes validate type, sidecar, and root
|
|
384
|
+
identity without re-hashing entire trees on every tick.
|
|
337
385
|
|
|
338
386
|
Runtime defaults:
|
|
339
387
|
|
|
@@ -345,7 +393,561 @@ Runtime defaults:
|
|
|
345
393
|
- 7-day resumable-session lifetime.
|
|
346
394
|
|
|
347
395
|
The advanced runtime API can override these values; the server CLI intentionally
|
|
348
|
-
exposes only its required limits, committed retention
|
|
396
|
+
exposes only its required limits, committed retention and rotation, replacement
|
|
397
|
+
policy, artifact patterns, and hooks module.
|
|
398
|
+
|
|
399
|
+
## Artifact patterns and rotation
|
|
400
|
+
|
|
401
|
+
Artifact patterns teach the server which uploads belong to which release
|
|
402
|
+
series and, optionally, which SemVer version each one carries. They drive count
|
|
403
|
+
and version rotation and are configured only on the server:
|
|
404
|
+
`ServerOptions.artifactPatterns` or repeatable `--artifact-pattern`.
|
|
405
|
+
|
|
406
|
+
### Pattern templates
|
|
407
|
+
|
|
408
|
+
A template is literal text plus the placeholders `{series}` and `{version}`:
|
|
409
|
+
|
|
410
|
+
- At least one placeholder is required; each may appear at most once.
|
|
411
|
+
- Two placeholders in one path segment must be separated by literal text.
|
|
412
|
+
- `{` and `}` are reserved. A template whose literal text still contains a
|
|
413
|
+
brace after the exact `{series}` and `{version}` placeholders are removed
|
|
414
|
+
(`{serie}-{version}.tar.gz`, `{{series}.zip`) is rejected at startup rather
|
|
415
|
+
than matched literally.
|
|
416
|
+
- A template has one segment (matched against the basename) or two segments
|
|
417
|
+
separated by one `/` (`<source-parent>/<basename>`). Empty segments, further
|
|
418
|
+
`/` characters, and duplicate templates are rejected at startup.
|
|
419
|
+
- `{series}` captures one safe component. A template without `{series}` is a
|
|
420
|
+
fixed series whose key is `fixed-` followed by the lowercase hex SHA-256 of
|
|
421
|
+
the exact template text. `{version}/payments.tar.gz` therefore has the series
|
|
422
|
+
`fixed-594ef13d9808171190f7827f7d2fb1dc33f000f531b69d55c1bd485a70ff8c4b`. The
|
|
423
|
+
key is a 70-character safe basename, so it persists in commit records and
|
|
424
|
+
stays identical across restarts and between Node.js and Bare. The root export
|
|
425
|
+
`fixedSeriesKey(template)` derives the same value, so an operator can map a
|
|
426
|
+
series in a sidecar or log line back to the template that produced it.
|
|
427
|
+
- That derived shape is a reserved namespace: a captured `{series}` of exactly
|
|
428
|
+
`fixed-` plus 64 lowercase hex characters never matches, so an uploaded
|
|
429
|
+
filename cannot place itself in a version-only pattern's rotation group. The
|
|
430
|
+
offer is simply unmatched, which with mandatory matching means
|
|
431
|
+
`INVALID_FILENAME`. Look-alikes (different length, uppercase, non-hex) are
|
|
432
|
+
unaffected.
|
|
433
|
+
- `{version}` must be strict SemVer 2.0.0: no `v` prefix, no leading zeros, no
|
|
434
|
+
padding. The stored version is the normalized `major.minor.patch[-prerelease]`;
|
|
435
|
+
build metadata is accepted in a folder name but dropped, and it never
|
|
436
|
+
influences precedence.
|
|
437
|
+
- Basenames never contain `+`, so build metadata can only appear in a
|
|
438
|
+
source-parent segment.
|
|
439
|
+
- A malformed version is a non-match, not a partial match.
|
|
440
|
+
|
|
441
|
+
Examples:
|
|
442
|
+
|
|
443
|
+
| Template | Offer (`sourceParent`, basename) | Series | Version |
|
|
444
|
+
| --------------------------- | ----------------------------------- | ------------- | ------------ |
|
|
445
|
+
| `{series}-{version}.tar.gz` | `payments-2.4.1.tar.gz` | `payments` | `2.4.1` |
|
|
446
|
+
| `{series}-{version}.tar.gz` | `payments-3.0.0-rc.1.tar.gz` | `payments` | `3.0.0-rc.1` |
|
|
447
|
+
| `{version}/{series}.tar.gz` | `2.4.1+build.7` / `payments.tar.gz` | `payments` | `2.4.1` |
|
|
448
|
+
| `releases/{series}.zip` | `releases` / `payments.zip` | `payments` | none |
|
|
449
|
+
| `{version}/payments.tar.gz` | `1.8.0` / `payments.tar.gz` | `fixed-594e…` | `1.8.0` |
|
|
450
|
+
| `{series}.tar.gz` | `payments.tar.gz` | `payments` | none |
|
|
451
|
+
|
|
452
|
+
With a series-first template such as `{series}-{version}.tar.gz`, the split
|
|
453
|
+
chosen is the right-most `-` that yields a valid SemVer, so hyphenated series
|
|
454
|
+
names and prereleases both work. A version-first template such as
|
|
455
|
+
`{version}-{series}.tar.gz` splits at the left-most valid position and cannot
|
|
456
|
+
tell a prerelease hyphen from the series separator; prefer series-first or a
|
|
457
|
+
folder-based version for prereleases.
|
|
458
|
+
|
|
459
|
+
Patterns are tried in declaration order and the first template that produces
|
|
460
|
+
coordinates wins. A template with a parent segment never matches an offer that
|
|
461
|
+
carries no `sourceParent`.
|
|
462
|
+
|
|
463
|
+
### Source parent
|
|
464
|
+
|
|
465
|
+
The client sends the immediate parent directory name of the resolved input as
|
|
466
|
+
optional authenticated metadata, never an absolute path or a higher component.
|
|
467
|
+
Uploading `/ci/2.4.1+build.7/payments.tar.gz` sends `sourceParent`
|
|
468
|
+
`2.4.1+build.7`; uploading a directory sends that directory's name for each
|
|
469
|
+
child.
|
|
470
|
+
|
|
471
|
+
The parent is sent only when it is a safe single component
|
|
472
|
+
(`[A-Za-z0-9][A-Za-z0-9._+-]*`, at most 100 UTF-8 bytes). A parent with a space,
|
|
473
|
+
a leading dot, a non-ASCII character, an overlong name, or the filesystem root
|
|
474
|
+
is omitted, and the upload keeps the pre-existing metadata shape. Consequently a
|
|
475
|
+
folder pattern rejects uploads whose parent is unsafe or omitted: stage release
|
|
476
|
+
files in a conforming directory. `sourceParent` is part of the transfer ID, so
|
|
477
|
+
it cannot change between resume attempts.
|
|
478
|
+
|
|
479
|
+
A client can also suppress it deliberately with `includeSourceParent: false`
|
|
480
|
+
(CLI `--no-source-parent`) where the staging folder name itself is sensitive.
|
|
481
|
+
The upload then sends no parent and derives the same transfer ID as a client
|
|
482
|
+
that predates the field, so a server pattern needing a parent segment rejects
|
|
483
|
+
it with `INVALID_FILENAME`.
|
|
484
|
+
|
|
485
|
+
### Mandatory matching
|
|
486
|
+
|
|
487
|
+
When `artifactPatterns` is non-empty, matching is mandatory for new uploads. An
|
|
488
|
+
offer that matches no pattern is rejected with `INVALID_FILENAME` before
|
|
489
|
+
session admission, staging, verification, commit, `beforeCommit`, and
|
|
490
|
+
`afterCommit`; the server then calls `onFailure` once with phase `offer`, a
|
|
491
|
+
`null` path, and no `release`. A server with no patterns accepts every
|
|
492
|
+
otherwise-valid name, and records get no release identity.
|
|
493
|
+
|
|
494
|
+
Release coordinates (`series` and, if the pattern has one, `version`) are
|
|
495
|
+
decided at commit time and persisted in the commit record, replacement history
|
|
496
|
+
inherits them, and they survive restarts and later pattern changes. A commit
|
|
497
|
+
record written before this feature, or by a server without patterns, has no
|
|
498
|
+
release and is never deleted by count or version rotation; it remains subject
|
|
499
|
+
to age and quota retention.
|
|
500
|
+
|
|
501
|
+
A new upload whose matched release differs from the persisted release of the
|
|
502
|
+
same transfer fails closed instead of reporting `ALREADY_COMMITTED`.
|
|
503
|
+
|
|
504
|
+
### Selection rules
|
|
505
|
+
|
|
506
|
+
Retention runs under the root lease at startup, on schedule, around every
|
|
507
|
+
commit, and manually. After session expiry and a committed-state scrub, its
|
|
508
|
+
stages run in this order, each working from the records the previous stage
|
|
509
|
+
left:
|
|
510
|
+
|
|
511
|
+
1. age (`maxAge`);
|
|
512
|
+
2. count (`maxCount`);
|
|
513
|
+
3. version (`maxVersions` with `versionGranularity`);
|
|
514
|
+
4. storage quota (`maxStorageBytes`).
|
|
515
|
+
|
|
516
|
+
**Count.** Records are grouped by series and ordered by commit order: newest
|
|
517
|
+
`committedAt` first, with transfer ID and then name as deterministic
|
|
518
|
+
tie-breakers. The newest `maxCount` records in each series are kept. Replacement
|
|
519
|
+
history records count like any other release.
|
|
520
|
+
|
|
521
|
+
**Version.** Records with a version are grouped by series and ordered by SemVer
|
|
522
|
+
precedence, not by commit time. With `major`, every record in the newest
|
|
523
|
+
`maxVersions` distinct majors is kept; with `minor`, in the newest
|
|
524
|
+
`maxVersions` distinct `major.minor` groups. Prereleases and history records in
|
|
525
|
+
a retained group are kept, so `2.0.0-rc.1` and `2.0.0` share group `2`. Series-only
|
|
526
|
+
records (no `{version}`) are never selected by version rotation.
|
|
527
|
+
|
|
528
|
+
**Combined limits.** A record may be removed by either configured bound, so
|
|
529
|
+
`maxCount` plus `maxVersions` retains the intersection of the two keep sets, and
|
|
530
|
+
age and quota then apply to what remains.
|
|
531
|
+
|
|
532
|
+
**Pinned mutable names.** The current artifact of a `--replace-name` name is
|
|
533
|
+
never deleted by any stage, but it still takes part in the accounting. If it
|
|
534
|
+
occupies a slot or falls outside a keep set, the limit is best-effort: the
|
|
535
|
+
series can hold more than the configured number until a later upload moves the
|
|
536
|
+
name on.
|
|
537
|
+
|
|
538
|
+
**Immediate effect.** Rotation also runs right after each commit, so an upload
|
|
539
|
+
that is older than the retained window (for example version `1.0.0` when
|
|
540
|
+
`maxVersions` is `2` and `3.x` and `2.x` exist) is committed and then removed in
|
|
541
|
+
that same pass. The exact ordering depends on hooks:
|
|
542
|
+
|
|
543
|
+
- Without an `afterCommit` hook, the post-commit pass runs immediately after the
|
|
544
|
+
commit becomes durable, before `COMMITTED` is sent.
|
|
545
|
+
- With an `afterCommit` hook, the post-commit pass is deferred. Order:
|
|
546
|
+
commit (the pre-commit quota and age checks still run first), `afterCommit`
|
|
547
|
+
with the final path and sidecar present, and only after the callback
|
|
548
|
+
succeeds the post-commit pass, then `COMMITTED` (or `ALREADY_COMMITTED`).
|
|
549
|
+
Because the deferred pass runs before the terminal reply, a slow retention
|
|
550
|
+
pass delays `COMMITTED` or `ALREADY_COMMITTED`. `beforeCommit`-only and
|
|
551
|
+
`onFailure`-only servers do not defer.
|
|
552
|
+
- The final path exists when `afterCommit` begins in the sequential server
|
|
553
|
+
flow, including for an out-of-window release, and for replacement commits
|
|
554
|
+
(a replaced artifact's history record is also present). It is not a lock:
|
|
555
|
+
a concurrent commit's retention pass, a scheduled retention pass, or a manual
|
|
556
|
+
retention pass can remove the file while the callback runs. A hook that needs stable bytes should open or
|
|
557
|
+
copy the file promptly at the start of the callback.
|
|
558
|
+
- If `afterCommit` throws, no post-commit pass runs for that connection. The
|
|
559
|
+
artifact and its record stay, and the server remembers in memory that this
|
|
560
|
+
transfer still owes a pass. An immediate retry normally reaches
|
|
561
|
+
`ALREADY_COMMITTED`, runs `afterCommit` again with the existing path, and runs
|
|
562
|
+
the owed pass only after that call succeeds. A failing already-committed
|
|
563
|
+
`afterCommit` likewise skips the pass and keeps the transfer owed. See the
|
|
564
|
+
retry caveat below.
|
|
565
|
+
- An ordinary duplicate offer — one whose `afterCommit` already succeeded, or
|
|
566
|
+
that this process never committed — still calls `afterCommit` with
|
|
567
|
+
`alreadyCommitted: true`, but starts **no** retention pass. Only a connection
|
|
568
|
+
that committed in this process, or a retry of a transfer whose hook failed
|
|
569
|
+
here, can trigger the deferred pass, so repeated duplicate offers cannot be
|
|
570
|
+
used to force repeated full retention scans.
|
|
571
|
+
- The owed-transfer set lives only in memory. A server restart forgets it, and
|
|
572
|
+
closing the server clears it; the artifact is then rotated by the next
|
|
573
|
+
startup, scheduled, or commit-triggered pass instead.
|
|
574
|
+
- Post-commit retention failures stay non-fatal: they are logged and reported as
|
|
575
|
+
`retention` events, and never fail the upload.
|
|
576
|
+
|
|
577
|
+
**Retry caveat.** There is no persistent "hook pending" marker. After
|
|
578
|
+
`afterCommit` fails for an out-of-window artifact, any intervening retention
|
|
579
|
+
pass can remove it before the client retries: a startup pass after a restart, a
|
|
580
|
+
scheduled or manual cleanup, or the retention pass of another concurrent commit.
|
|
581
|
+
The retry is then a normal fresh upload (transfer, verification, `beforeCommit`,
|
|
582
|
+
commit, `afterCommit` with `alreadyCommitted: false`), not `ALREADY_COMMITTED`.
|
|
583
|
+
Every statement below that a failed hook is retried as `ALREADY_COMMITTED`
|
|
584
|
+
assumes the artifact was not removed in between.
|
|
585
|
+
|
|
586
|
+
`retention` events and results report `ageDeleted`, `countDeleted`,
|
|
587
|
+
`versionDeleted`, and `storageDeleted` next to `expiredSessions` and `scrubbed`.
|
|
588
|
+
Logged deletions use the reasons `MAX_AGE`, `MAX_COUNT`, `MAX_VERSIONS`, and
|
|
589
|
+
`MAX_STORAGE`.
|
|
590
|
+
|
|
591
|
+
### Configuration and CLI examples
|
|
592
|
+
|
|
593
|
+
Filename versions, keeping the newest 5 builds per product and the newest two
|
|
594
|
+
minor lines:
|
|
595
|
+
|
|
596
|
+
```sh
|
|
597
|
+
swarm-deploy server --seed-file server.seed --storage /srv/artifacts \
|
|
598
|
+
--allow-key "$CLIENT_KEY" --max-file-bytes 1073741824 --max-staging-bytes 2147483648 \
|
|
599
|
+
--artifact-pattern '{series}-{version}.tar.gz' \
|
|
600
|
+
--max-count 5 --max-versions 2 --version-granularity minor
|
|
601
|
+
```
|
|
602
|
+
|
|
603
|
+
Folder versions (the source parent carries the version, build metadata
|
|
604
|
+
included), keeping the two newest majors:
|
|
605
|
+
|
|
606
|
+
```sh
|
|
607
|
+
swarm-deploy server --seed-file server.seed --storage /srv/artifacts \
|
|
608
|
+
--allow-key "$CLIENT_KEY" --max-file-bytes 1073741824 --max-staging-bytes 2147483648 \
|
|
609
|
+
--artifact-pattern '{version}/{series}.tar.gz' \
|
|
610
|
+
--max-versions 2 --version-granularity major
|
|
611
|
+
|
|
612
|
+
# client: /ci/out/2.4.1+build.7/payments.tar.gz is offered as
|
|
613
|
+
# sourceParent "2.4.1+build.7", name "payments.tar.gz"
|
|
614
|
+
swarm-deploy upload --seed-file client.seed --server-key "$SERVER_KEY" \
|
|
615
|
+
/ci/out/2.4.1+build.7/payments.tar.gz
|
|
616
|
+
```
|
|
617
|
+
|
|
618
|
+
The runtime API takes the same values:
|
|
619
|
+
|
|
620
|
+
```ts
|
|
621
|
+
new Server({
|
|
622
|
+
// ...required options
|
|
623
|
+
artifactPatterns: ['{series}-{version}.tar.gz', 'releases/{series}.zip'],
|
|
624
|
+
maxCount: 5,
|
|
625
|
+
maxVersions: 2,
|
|
626
|
+
versionGranularity: 'minor'
|
|
627
|
+
})
|
|
628
|
+
```
|
|
629
|
+
|
|
630
|
+
`maxCount` requires at least one pattern. `maxVersions` requires at least one
|
|
631
|
+
pattern containing `{version}` and a `versionGranularity`; a granularity without
|
|
632
|
+
`maxVersions` is invalid. These errors are raised at construction or CLI startup
|
|
633
|
+
(exit `2`). The pattern list is snapshotted at construction.
|
|
634
|
+
|
|
635
|
+
### Rollout and compatibility
|
|
636
|
+
|
|
637
|
+
Upgrade every server before any client. An older server decodes upload metadata
|
|
638
|
+
with an exact key set and rejects the new `sourceParent` field, so a new client
|
|
639
|
+
that sends a parent to an old server fails.
|
|
640
|
+
|
|
641
|
+
A new server remains compatible with older clients: they never send
|
|
642
|
+
`sourceParent`, no-pattern servers are unaffected, filename-only patterns still
|
|
643
|
+
match, and patterns that need a parent reject their offers as unmatched. Older
|
|
644
|
+
sessions and commit records stay readable, and older commit records are not
|
|
645
|
+
count or version rotated.
|
|
646
|
+
|
|
647
|
+
Roll out the server, then the pattern configuration, then clients that stage
|
|
648
|
+
into conforming folders.
|
|
649
|
+
|
|
650
|
+
#### Overlapping retries now get `FILE_BUSY`
|
|
651
|
+
|
|
652
|
+
**Behavior change.** A transfer ID may have only one in-flight commit
|
|
653
|
+
lifecycle. If a client (or a job runner that fans the same artifact out to
|
|
654
|
+
parallel workers) opens a second connection for a transfer that is still
|
|
655
|
+
verifying or committing, that second connection is now rejected with
|
|
656
|
+
`FILE_BUSY` instead of being admitted alongside the first. Sequential retries,
|
|
657
|
+
resumes, and verified reconnects are unaffected, and so is a retry issued after
|
|
658
|
+
the previous attempt failed — the server releases the transfer before running
|
|
659
|
+
its observational `onFailure`, so a slow callback never blocks the retry.
|
|
660
|
+
|
|
661
|
+
Audit any automation that uploads the same artifact from more than one worker
|
|
662
|
+
at a time, and treat `FILE_BUSY` on an upload as "retry after the in-flight
|
|
663
|
+
attempt finishes" rather than a permanent failure.
|
|
664
|
+
|
|
665
|
+
#### Enabling or changing patterns
|
|
666
|
+
|
|
667
|
+
A commit record's release identity is durable and is never rewritten in place.
|
|
668
|
+
Enabling patterns, or editing one that an in-flight upload already matched,
|
|
669
|
+
therefore changes the identity a retry computes for bytes that are already
|
|
670
|
+
committed, and the server fails closed rather than relabelling them:
|
|
671
|
+
|
|
672
|
+
- A create-only name whose record carries a different release (or none) is no
|
|
673
|
+
longer recognised as the same commit, so the retry is rejected with
|
|
674
|
+
`FILE_EXISTS`.
|
|
675
|
+
- A replaceable name retried under the same transfer ID with a different
|
|
676
|
+
release is rejected as a release-identity conflict.
|
|
677
|
+
|
|
678
|
+
Drain or complete in-flight uploads before enabling or changing
|
|
679
|
+
`artifactPatterns`. Uploads started after the change are unaffected, and a
|
|
680
|
+
rejected legacy retry is resolved by re-uploading under a new transfer (new
|
|
681
|
+
content or a new staged name), not by editing records on disk.
|
|
682
|
+
|
|
683
|
+
#### Session records and rollback
|
|
684
|
+
|
|
685
|
+
A resumable session is written at on-disk version 3 only when it carries a
|
|
686
|
+
`sourceParent`; a session without one is written at version 2, exactly as an
|
|
687
|
+
older server would. The new server reads both. An older server cannot read
|
|
688
|
+
version 3, so only parent-bearing resumable sessions are lost to a downgrade:
|
|
689
|
+
they cannot resume and must be re-uploaded. Draining in-flight uploads before
|
|
690
|
+
rolling a server back avoids this entirely.
|
|
691
|
+
|
|
692
|
+
Commit-record compatibility with older code is covered only by what this
|
|
693
|
+
version's tests assert: an older record without release coordinates is read by
|
|
694
|
+
this version and is not count or version rotated. Whether older code tolerates
|
|
695
|
+
the release coordinates this version writes is untested.
|
|
696
|
+
|
|
697
|
+
## Managed symlinks
|
|
698
|
+
|
|
699
|
+
Configure repeatable managed symlinks so the server keeps versioned artifacts
|
|
700
|
+
and maintains declarative links in the storage root:
|
|
701
|
+
|
|
702
|
+
```sh
|
|
703
|
+
swarm-deploy server \
|
|
704
|
+
--seed-file ./server.seed \
|
|
705
|
+
--storage /srv/artifacts \
|
|
706
|
+
--allow-key <64-lower-hex> \
|
|
707
|
+
--max-file-bytes 1073741824 \
|
|
708
|
+
--max-staging-bytes 4294967296 \
|
|
709
|
+
--symlink '/^\d+\.\d+\.\d+$/' latest \
|
|
710
|
+
--symlink release.tar.gz current.tar.gz
|
|
711
|
+
```
|
|
712
|
+
|
|
713
|
+
Resulting layout:
|
|
714
|
+
|
|
715
|
+
```text
|
|
716
|
+
/srv/artifacts/
|
|
717
|
+
├── 0.18.0/
|
|
718
|
+
├── 0.18.1/
|
|
719
|
+
└── latest -> 0.18.1
|
|
720
|
+
```
|
|
721
|
+
|
|
722
|
+
Runtime equivalent:
|
|
723
|
+
|
|
724
|
+
```js
|
|
725
|
+
const server = new Server({
|
|
726
|
+
seed,
|
|
727
|
+
storageDir: '/srv/artifacts',
|
|
728
|
+
allowedKeys,
|
|
729
|
+
maxFileBytes: 1024 ** 3,
|
|
730
|
+
maxStagingBytes: 4 * 1024 ** 3,
|
|
731
|
+
symlinks: [
|
|
732
|
+
{ selector: '/^\\d+\\.\\d+\\.\\d+$/', name: 'latest' },
|
|
733
|
+
{ selector: 'release.tar.gz', name: 'current.tar.gz' }
|
|
734
|
+
]
|
|
735
|
+
})
|
|
736
|
+
```
|
|
737
|
+
|
|
738
|
+
Selection uses only validated managed commit records. The newest `committedAt`
|
|
739
|
+
wins, tie-broken by transfer ID then name. Replacement history names never
|
|
740
|
+
match. A rule is dormant until its target exists.
|
|
741
|
+
|
|
742
|
+
Safety: an unmanaged file, directory, unrecorded symlink, changed symlink, or
|
|
743
|
+
foreign ownership record is never replaced, moved, or deleted and causes a
|
|
744
|
+
fail-closed error. An upload whose name equals a configured link name is
|
|
745
|
+
rejected before admission.
|
|
746
|
+
|
|
747
|
+
Retention pins every selected symlink target against age, count, SemVer, and
|
|
748
|
+
quota deletion. Pinned targets still count toward the quota. The desired-link
|
|
749
|
+
set is recomputed under the root lease before any deletion, so a repoint always
|
|
750
|
+
precedes the old target becoming eligible. Removing a rule removes its ownership
|
|
751
|
+
record and visible link only while ownership is still proven.
|
|
752
|
+
|
|
753
|
+
`symlinks` requires `StorageAdapter.symlink` and `readlink`. The Node and Bare
|
|
754
|
+
default adapters provide them; a custom adapter without symlink rules stays
|
|
755
|
+
source-compatible.
|
|
756
|
+
|
|
757
|
+
## Deployment hooks
|
|
758
|
+
|
|
759
|
+
Hooks let a trusted server operator run code around the commit. They are
|
|
760
|
+
server-side only, run in the server process with its privileges, and receive no
|
|
761
|
+
seeds, secret keys, TAR bytes, or session material.
|
|
762
|
+
|
|
763
|
+
### Lifecycle points
|
|
764
|
+
|
|
765
|
+
- `beforeCommit(context)`: after verification, before any commit mutation. For a
|
|
766
|
+
file, `path` is the verified `.part` staging file; for a directory, `path` is
|
|
767
|
+
the verified `.tree` staging directory. Its failure aborts the commit.
|
|
768
|
+
- `afterCommit(context)`: after the artifact is durably committed and configured
|
|
769
|
+
links are reconciled, before the terminal success reply. For a directory,
|
|
770
|
+
`path` is the committed directory tree. Its failure fails the upload even
|
|
771
|
+
though the artifact is already stored. When it is configured, post-commit
|
|
772
|
+
rotation is deferred until it succeeds (see "Immediate effect" above).
|
|
773
|
+
- `onFailure(context)`: once per failed connection whose metadata was decoded,
|
|
774
|
+
after the client has been answered.
|
|
775
|
+
|
|
776
|
+
Callbacks may return `void` or a promise, are called with no receiver, and
|
|
777
|
+
receive a frozen context. The artifact is
|
|
778
|
+
`{ name, kind, size, sha256, transferId, entryCount?, sourceParent?, release? }`,
|
|
779
|
+
where `entryCount` is present only for directories and `release` is
|
|
780
|
+
`{ series, version? }` when patterns are configured. These descriptive fields
|
|
781
|
+
come from decoded offer metadata, not yet from verified content.
|
|
782
|
+
|
|
783
|
+
| Callback | Extra context |
|
|
784
|
+
| -------------- | ---------------------------------------------------------------------------- |
|
|
785
|
+
| `beforeCommit` | `path` (verified staging file or tree), `resumed`, `alreadyCommitted: false` |
|
|
786
|
+
| `afterCommit` | `path` (committed artifact), `resumed`, `alreadyCommitted` |
|
|
787
|
+
| `onFailure` | `path` (`string \| null`), `phase`, `resumed`, `alreadyCommitted`, `error` |
|
|
788
|
+
|
|
789
|
+
`resumed` is `true` when the server admitted the connection as `RESUME` or
|
|
790
|
+
`VERIFIED`. Closing the server aborts the wait; a callback that outlives the
|
|
791
|
+
abort continues detached and its later result is ignored.
|
|
792
|
+
|
|
793
|
+
There is no hook timeout, and a hung callback holds more than its own
|
|
794
|
+
connection. On a fresh or resumed upload it also holds a `maxActiveUploads`
|
|
795
|
+
slot and the session's staging reservation for as long as it runs, so enough
|
|
796
|
+
simultaneously hung callbacks stop the server from admitting new uploads
|
|
797
|
+
(`ACTIVE_UPLOAD_LIMIT`) until the server is closed and the waits are aborted.
|
|
798
|
+
Only the already-committed path holds no upload slot. Write callbacks that
|
|
799
|
+
finish or throw; bounded hook timeout and anti-spam controls are tracked in
|
|
800
|
+
issue #8.
|
|
801
|
+
|
|
802
|
+
The **lifecycle** hooks `beforeCommit` and `afterCommit` never run concurrently
|
|
803
|
+
for one transfer. Once a transfer ID authenticates, that connection owns it for
|
|
804
|
+
the whole verify/commit sequence; a second connection offering the same transfer
|
|
805
|
+
ID — fresh, resumed, verified, or already committed — is rejected with
|
|
806
|
+
`FILE_BUSY` before any lifecycle hook runs, and that rejection is reported to
|
|
807
|
+
`onFailure` once with `phase: 'offer'`.
|
|
808
|
+
|
|
809
|
+
`onFailure` is observational and is **not** covered by that guarantee. A failed
|
|
810
|
+
connection hands the transfer back before awaiting its `onFailure`, because the
|
|
811
|
+
callback only reports an outcome and the connection has already finished
|
|
812
|
+
mutating state. A slow callback must not reject the client's legitimate retry,
|
|
813
|
+
so a retry of the same transfer can be admitted — and can run its own
|
|
814
|
+
`beforeCommit`/`afterCommit` — while the previous `onFailure` is still running.
|
|
815
|
+
Each connection still calls `onFailure` at most once, so write it to tolerate
|
|
816
|
+
overlapping with the next attempt and key any external effect on
|
|
817
|
+
`artifact.transferId`.
|
|
818
|
+
|
|
819
|
+
Hooks for **different** transfers always run concurrently.
|
|
820
|
+
|
|
821
|
+
### Invocation sequences
|
|
822
|
+
|
|
823
|
+
Fresh upload:
|
|
824
|
+
|
|
825
|
+
1. Offer inspected and admitted (`ACCEPT`), TAR received.
|
|
826
|
+
2. Verification.
|
|
827
|
+
3. `beforeCommit` (`resumed: false`).
|
|
828
|
+
4. Commit.
|
|
829
|
+
5. `afterCommit` (`resumed: false`, `alreadyCommitted: false`).
|
|
830
|
+
6. `COMMITTED`.
|
|
831
|
+
|
|
832
|
+
Partial resume (`RESUME`): the same steps, with `resumed: true` in both hooks.
|
|
833
|
+
|
|
834
|
+
Verified reconnect (`VERIFIED`): the staged data was already verified, so the
|
|
835
|
+
server re-reads it, calls `beforeCommit` again with `resumed: true`, commits, and
|
|
836
|
+
calls `afterCommit` with `resumed: true`. A previous connection may have ended
|
|
837
|
+
after `beforeCommit` returned but before the commit finished.
|
|
838
|
+
|
|
839
|
+
Already committed: identical content is detected during offer inspection, so
|
|
840
|
+
there is no transfer, verification, or `beforeCommit`. The server calls
|
|
841
|
+
`afterCommit` with `resumed: false` and `alreadyCommitted: true`, then replies
|
|
842
|
+
`ALREADY_COMMITTED`. A deferred retention pass follows only when this process
|
|
843
|
+
committed that transfer and its `afterCommit` has not yet succeeded. This path
|
|
844
|
+
is reached only while the artifact still exists; see the
|
|
845
|
+
[retry caveat](#artifact-patterns-and-rotation).
|
|
846
|
+
|
|
847
|
+
Failure sequences:
|
|
848
|
+
|
|
849
|
+
- `beforeCommit` throws: nothing is committed and the verified session remains.
|
|
850
|
+
The client receives `HOOK_FAILED`; `onFailure` runs (`phase: 'beforeCommit'`).
|
|
851
|
+
A retry reconnects as `VERIFIED` and calls `beforeCommit` again.
|
|
852
|
+
- `afterCommit` throws on a fresh or resumed upload: the artifact **stays
|
|
853
|
+
durably committed** and its session is retired. The client receives
|
|
854
|
+
`HOOK_FAILED`; `onFailure` runs (`phase: 'afterCommit'`, final path). Unless
|
|
855
|
+
retention removed the artifact first (see the
|
|
856
|
+
[retry caveat](#artifact-patterns-and-rotation)), a retry takes the
|
|
857
|
+
already-committed path and calls `afterCommit` with `alreadyCommitted: true`;
|
|
858
|
+
otherwise it is a fresh upload.
|
|
859
|
+
- `afterCommit` throws on an already-committed retry: the offer is rejected with
|
|
860
|
+
`HOOK_FAILED` and a later retry repeats `afterCommit`, subject to the same
|
|
861
|
+
retry caveat.
|
|
862
|
+
- A failure after both hooks succeeded (for example the terminal reply cannot be
|
|
863
|
+
written) does not call `onFailure`.
|
|
864
|
+
|
|
865
|
+
Retries therefore can call hooks more than once for one transfer. **Make hooks
|
|
866
|
+
idempotent and key external side effects on `artifact.transferId`.** Treat
|
|
867
|
+
`afterCommit` as at-least-once: record the transfer ID when the deployment step
|
|
868
|
+
finishes and skip repeated calls.
|
|
869
|
+
|
|
870
|
+
### onFailure
|
|
871
|
+
|
|
872
|
+
`phase` is one of `offer`, `transfer`, `verification`, `beforeCommit`, `commit`,
|
|
873
|
+
or `afterCommit`. `offer` covers every failure before a staging path exists:
|
|
874
|
+
metadata or transfer-ID problems, unmatched patterns, file-size, capacity and
|
|
875
|
+
destination rejections, and inspection errors.
|
|
876
|
+
|
|
877
|
+
An `offer`-phase context is built from decoded metadata **before** the transfer
|
|
878
|
+
ID is authenticated, and it is also reported when that authentication is exactly
|
|
879
|
+
what failed. Its `transferId`, `name`, `size`, `sha256`, and `sourceParent` are
|
|
880
|
+
therefore attacker-chosen values from an allowlisted key, not verified identity.
|
|
881
|
+
Use them for logging and alerting only; never as audit records or idempotency
|
|
882
|
+
keys. Every later phase runs after authentication, so only `offer` carries this
|
|
883
|
+
caveat.
|
|
884
|
+
|
|
885
|
+
`error` is the original failure. For an exception thrown by `beforeCommit` or
|
|
886
|
+
`afterCommit`, hooks receive the **raw thrown value** (not a wrapper) because
|
|
887
|
+
hooks are trusted. The client and server events see only the stable wire code
|
|
888
|
+
`HOOK_FAILED` with a fixed message, so callback text never reaches the wire. Other
|
|
889
|
+
failures arrive as `SwarmDeployError` (or raw storage errors).
|
|
890
|
+
A failing `onFailure` is logged as a secondary warning and never replaces the
|
|
891
|
+
original failure.
|
|
892
|
+
|
|
893
|
+
`path` by phase:
|
|
894
|
+
|
|
895
|
+
| Situation | `path` |
|
|
896
|
+
| ------------------------------------------------------------------ | ------------------------------------------------------- |
|
|
897
|
+
| `offer` | `null` |
|
|
898
|
+
| `transfer`; fresh-upload `verification` | `<storage>/.swarm-deploy/staging/<transferId>.tar.part` |
|
|
899
|
+
| `beforeCommit`, `commit`; `verification` of a `VERIFIED` reconnect | `<storage>/.swarm-deploy/staging/<transferId>.part` |
|
|
900
|
+
| `afterCommit` (including already committed) | `<storage>/<name>` |
|
|
901
|
+
|
|
902
|
+
### Hook modules
|
|
903
|
+
|
|
904
|
+
`--hooks <module>` accepts `.js`, `.mjs`, and `.cjs`; any other extension is
|
|
905
|
+
rejected at startup with exit code `2` before the module is loaded. ESM and
|
|
906
|
+
CommonJS examples:
|
|
907
|
+
|
|
908
|
+
```js
|
|
909
|
+
// hooks.mjs
|
|
910
|
+
export async function afterCommit({ artifact, path, alreadyCommitted }) {
|
|
911
|
+
// Idempotent: keyed by artifact.transferId.
|
|
912
|
+
await deploy(artifact.transferId, path)
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
export function onFailure({ phase, artifact, error }) {
|
|
916
|
+
console.error('deploy failed', phase, artifact.transferId, error)
|
|
917
|
+
}
|
|
918
|
+
```
|
|
919
|
+
|
|
920
|
+
```js
|
|
921
|
+
// hooks.cjs
|
|
922
|
+
module.exports = {
|
|
923
|
+
beforeCommit({ artifact, path }) {
|
|
924
|
+
// Return or throw; a throw rejects the upload with HOOK_FAILED.
|
|
925
|
+
},
|
|
926
|
+
async afterCommit({ artifact, path }) {
|
|
927
|
+
await deploy(artifact.transferId, path)
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
```
|
|
931
|
+
|
|
932
|
+
Loader rules:
|
|
933
|
+
|
|
934
|
+
- Only the own properties `beforeCommit`, `afterCommit`, and `onFailure` are
|
|
935
|
+
read. Other exports (helpers, configuration) are ignored, including a
|
|
936
|
+
harmless non-object default export.
|
|
937
|
+
- Named exports take precedence over callbacks on a default export object; a
|
|
938
|
+
named export set to `undefined` does not override it.
|
|
939
|
+
- A hook name that is present must be a function, the callbacks must be plain
|
|
940
|
+
own properties, and at least one must exist; otherwise startup fails.
|
|
941
|
+
- One level of compiled-CommonJS interop (`__esModule` with `default`) is
|
|
942
|
+
unwrapped; deeper nesting is ignored.
|
|
943
|
+
- Modules are loaded once with `import()` and cached by the runtime. Top-level
|
|
944
|
+
code runs with the server's privileges during startup, so the module is fully
|
|
945
|
+
trusted.
|
|
946
|
+
|
|
947
|
+
`ServerOptions.hooks` is stricter: it must be a hook object whose own keys are
|
|
948
|
+
only the three callbacks, every callback a function. Unknown keys and
|
|
949
|
+
non-function values throw `PROTOCOL_INVALID`. The object is snapshotted at
|
|
950
|
+
construction, so later mutation has no effect.
|
|
349
951
|
|
|
350
952
|
## Runtime API
|
|
351
953
|
|
|
@@ -378,6 +980,16 @@ newlines. Blank lines and lines beginning with `#` are ignored; malformed or
|
|
|
378
980
|
duplicate keys throw. It returns a `Set<string>` suitable for
|
|
379
981
|
`ServerOptions.allowedKeys`.
|
|
380
982
|
|
|
983
|
+
`fixedSeriesKey(template)` returns the series a template without `{series}`
|
|
984
|
+
persists, so an operator reading `fixed-…` in a commit sidecar, retention log,
|
|
985
|
+
or hook context can identify which configured pattern owns it:
|
|
986
|
+
|
|
987
|
+
```ts
|
|
988
|
+
import { fixedSeriesKey } from 'swarm-deploy'
|
|
989
|
+
|
|
990
|
+
const owner = patterns.find((template) => fixedSeriesKey(template) === record.release?.series)
|
|
991
|
+
```
|
|
992
|
+
|
|
381
993
|
### Server
|
|
382
994
|
|
|
383
995
|
```ts
|
|
@@ -423,6 +1035,27 @@ Optional operational limits and policies:
|
|
|
423
1035
|
- `maxConnections`, `maxActiveUploads`, `idleTimeout`
|
|
424
1036
|
- `cleanupInterval`, `resumeTtl`, `minFreeBytes`
|
|
425
1037
|
- `maxAge`, `maxStorageBytes`, `replaceNames`
|
|
1038
|
+
- `artifactPatterns?: Iterable<string>`, `maxCount?: number`,
|
|
1039
|
+
`maxVersions?: number`, and `versionGranularity?: 'major' | 'minor'`; see
|
|
1040
|
+
[Artifact patterns and rotation](#artifact-patterns-and-rotation).
|
|
1041
|
+
- `hooks?: ServerHooks | null`; see [Deployment hooks](#deployment-hooks).
|
|
1042
|
+
|
|
1043
|
+
The root package exports the `ServerHooks`, `BeforeCommitContext`,
|
|
1044
|
+
`AfterCommitContext`, `HookFailureContext`, `HookFailurePhase`, `HookArtifact`,
|
|
1045
|
+
`ReleaseCoordinates`, and `VersionGranularity` types:
|
|
1046
|
+
|
|
1047
|
+
```ts
|
|
1048
|
+
import type { ServerHooks } from 'swarm-deploy'
|
|
1049
|
+
|
|
1050
|
+
const hooks: ServerHooks = {
|
|
1051
|
+
async afterCommit({ artifact, path, alreadyCommitted }) {
|
|
1052
|
+
// Idempotent: skip work already recorded for artifact.transferId.
|
|
1053
|
+
},
|
|
1054
|
+
onFailure({ phase, path, error }) {
|
|
1055
|
+
console.error(phase, path, error)
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
```
|
|
426
1059
|
|
|
427
1060
|
Advanced integration and test seams:
|
|
428
1061
|
|
|
@@ -451,9 +1084,12 @@ await client.close()
|
|
|
451
1084
|
|
|
452
1085
|
`ClientOptions.seed` accepts a Buffer or canonical lowercase 64-character hex
|
|
453
1086
|
string. `serverPublicKey` is a Buffer produced by `parsePublicKey`. Optional
|
|
454
|
-
values are `connectTimeout`, `idleTimeout`, `
|
|
1087
|
+
values are `connectTimeout`, `idleTimeout`, `includeSourceParent`, `dht`,
|
|
1088
|
+
`dhtFactory`, and `logger`.
|
|
455
1089
|
|
|
456
1090
|
`connectTimeout` defaults to 30 seconds. `idleTimeout` defaults to 60 seconds.
|
|
1091
|
+
`includeSourceParent` defaults to `true`; set it to `false` to suppress the
|
|
1092
|
+
[source parent](#source-parent) for every upload the client makes.
|
|
457
1093
|
Calling `close()` aborts pending work, closes active sockets, and is idempotent.
|
|
458
1094
|
|
|
459
1095
|
### Upload results
|
|
@@ -463,36 +1099,18 @@ A direct file resolves to:
|
|
|
463
1099
|
```ts
|
|
464
1100
|
interface UploadResult {
|
|
465
1101
|
status: 'COMMITTED' | 'ALREADY_COMMITTED'
|
|
1102
|
+
kind: 'file' | 'directory'
|
|
466
1103
|
name: string
|
|
467
1104
|
size: number
|
|
468
1105
|
digest: Buffer
|
|
469
1106
|
transferId: Buffer
|
|
1107
|
+
entryCount?: number
|
|
470
1108
|
}
|
|
471
1109
|
```
|
|
472
1110
|
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
interface BatchUploadResult {
|
|
477
|
-
status: 'COMMITTED' | 'FAILED'
|
|
478
|
-
results: Array<
|
|
479
|
-
| UploadResult
|
|
480
|
-
| {
|
|
481
|
-
name: string
|
|
482
|
-
status: ErrorCode
|
|
483
|
-
reason?: string
|
|
484
|
-
}
|
|
485
|
-
>
|
|
486
|
-
skipped: Array<{
|
|
487
|
-
name: string
|
|
488
|
-
path: string
|
|
489
|
-
reason: SkippedUploadReason
|
|
490
|
-
}>
|
|
491
|
-
}
|
|
492
|
-
```
|
|
493
|
-
|
|
494
|
-
Directory members are processed sequentially. A failed member does not prevent
|
|
495
|
-
later members from being attempted.
|
|
1111
|
+
Files and directories share the same result shape. For a directory, `size` is
|
|
1112
|
+
aggregate payload bytes and `entryCount` counts stored entries (files and
|
|
1113
|
+
directories).
|
|
496
1114
|
|
|
497
1115
|
### Events
|
|
498
1116
|
|
|
@@ -510,12 +1128,16 @@ Server events:
|
|
|
510
1128
|
- `connection`, `connection-open`, `connection-close`: authenticated connection
|
|
511
1129
|
lifecycle and current count.
|
|
512
1130
|
- `offer`: accepted, resumed, reset, rejected, or already-committed state.
|
|
513
|
-
|
|
1131
|
+
Includes artifact `kind`.
|
|
1132
|
+
- `progress`: durable TAR bytes received and total TAR bytes. Includes artifact
|
|
1133
|
+
`kind`.
|
|
514
1134
|
- `verification`: started, succeeded, or failed.
|
|
515
1135
|
- `commit`: succeeded or failed.
|
|
516
1136
|
- `recovery`: startup, per-journal, corruption, resumable, and completion
|
|
517
1137
|
outcomes.
|
|
518
|
-
- `retention`: startup, scheduled, manual, commit, or post-commit outcomes
|
|
1138
|
+
- `retention`: startup, scheduled, manual, commit, or post-commit outcomes,
|
|
1139
|
+
with `expiredSessions`, `scrubbed`, `ageDeleted`, `countDeleted`,
|
|
1140
|
+
`versionDeleted`, and `storageDeleted` counters.
|
|
519
1141
|
- `failure`: stable failure code and peer fingerprint.
|
|
520
1142
|
- `listening`: local server-key fingerprint.
|
|
521
1143
|
- `close`: closed or failed outcome.
|
|
@@ -527,8 +1149,7 @@ Client events:
|
|
|
527
1149
|
- `progress`: cumulative TAR `bytesSent` and full `totalBytes`, including a
|
|
528
1150
|
durable resume offset.
|
|
529
1151
|
- `verification`, `commit`
|
|
530
|
-
- `result`:
|
|
531
|
-
- `skipped`: skipped directory member and stable reason.
|
|
1152
|
+
- `result`: terminal upload result with artifact `kind`.
|
|
532
1153
|
- `failure`, `close`
|
|
533
1154
|
|
|
534
1155
|
Use the exported `ServerEventMap`, `ClientEventMap`, `ServerEventName`, and
|
|
@@ -584,11 +1205,19 @@ try {
|
|
|
584
1205
|
}
|
|
585
1206
|
```
|
|
586
1207
|
|
|
1208
|
+
`HOOK_FAILED` is the stable code for a failed `beforeCommit` or `afterCommit`
|
|
1209
|
+
callback. Its message is fixed and the original exception is available only as
|
|
1210
|
+
`cause` and to `onFailure`.
|
|
1211
|
+
|
|
587
1212
|
Stable codes include authentication and server-key rejection, invalid
|
|
588
1213
|
configuration and protocol records, file and staging limits, disk reserve,
|
|
589
1214
|
filename and replacement conflicts, checksum failures, connection or upload
|
|
590
|
-
timeouts, aborts, commit failures,
|
|
591
|
-
|
|
1215
|
+
timeouts, aborts, commit failures, cleanup failures, and managed-link failures
|
|
1216
|
+
(`LINK_CONFLICT`, `LINK_FAILED`, `UNSUPPORTED_STORAGE`). A link reconciliation
|
|
1217
|
+
failure after a durable commit behaves like other post-commit deployment
|
|
1218
|
+
failures: the artifact stays committed, the client receives a stable failure,
|
|
1219
|
+
and an already-committed retry reruns reconciliation before succeeding. Import
|
|
1220
|
+
`ERRORS` rather than matching exception messages.
|
|
592
1221
|
|
|
593
1222
|
## Production operations
|
|
594
1223
|
|
|
@@ -596,8 +1225,10 @@ than matching exception messages.
|
|
|
596
1225
|
- Restrict the server seed and storage root to that account.
|
|
597
1226
|
- Supervise the process and wait for the final `ready` line before marking it
|
|
598
1227
|
healthy.
|
|
599
|
-
-
|
|
600
|
-
|
|
1228
|
+
- Upgrade servers before clients; see
|
|
1229
|
+
[Rollout and compatibility](#rollout-and-compatibility).
|
|
1230
|
+
- Restart with the same seed, allowlist, limits, replacement names, artifact
|
|
1231
|
+
patterns, rotation limits, hooks module, and storage root so interrupted sessions and commit journals can recover.
|
|
601
1232
|
- Alert on nonzero CLI exits and failed authentication, recovery, verification,
|
|
602
1233
|
commit, retention, and cleanup events.
|
|
603
1234
|
- Never edit `.swarm-deploy/` while the server is running.
|
|
@@ -617,7 +1248,7 @@ untracked `dist/` and `.test-dist/`. Tests generate binary payloads in temporary
|
|
|
617
1248
|
directories and use an isolated local HyperDHT testnet, not the public DHT.
|
|
618
1249
|
|
|
619
1250
|
```sh
|
|
620
|
-
npm
|
|
1251
|
+
npm install
|
|
621
1252
|
npm run build
|
|
622
1253
|
npm run build:test
|
|
623
1254
|
npm run test:types
|