@git.zone/cli 7.4.1 → 8.0.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/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/mod_services/classes.dockercontainer.d.ts +13 -2
- package/dist_ts/mod_services/classes.dockercontainer.js +40 -40
- package/dist_ts/mod_services/classes.globalregistry.d.ts +12 -0
- package/dist_ts/mod_services/classes.globalregistry.js +96 -13
- package/dist_ts/mod_services/classes.globalregistrystore.d.ts +7 -1
- package/dist_ts/mod_services/classes.globalregistrystore.js +6 -6
- package/dist_ts/mod_services/classes.legacymongomigration.d.ts +239 -0
- package/dist_ts/mod_services/classes.legacymongomigration.js +970 -0
- package/dist_ts/mod_services/classes.serviceconfiguration.d.ts +18 -8
- package/dist_ts/mod_services/classes.serviceconfiguration.js +47 -35
- package/dist_ts/mod_services/classes.servicedatamarker.d.ts +42 -1
- package/dist_ts/mod_services/classes.servicedatamarker.js +101 -8
- package/dist_ts/mod_services/classes.servicemanager.d.ts +99 -33
- package/dist_ts/mod_services/classes.servicemanager.js +652 -384
- package/dist_ts/mod_services/classes.servicepruner.js +27 -20
- package/dist_ts/mod_services/index.js +51 -7
- package/dist_ts/mod_services/mod.plugins.d.ts +2 -1
- package/dist_ts/mod_services/mod.plugins.js +4 -2
- package/dist_ts_migration/002.runtime-config.d.ts +1 -1
- package/dist_ts_migration/002.runtime-config.js +8 -2
- package/dist_ts_migration/003.service-data-marker.js +125 -30
- package/dist_ts_migration/004.global-registry.js +30 -8
- package/package.json +1 -1
- package/readme.md +127 -28
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/mod_services/classes.dockercontainer.ts +58 -50
- package/ts/mod_services/classes.globalregistry.ts +115 -14
- package/ts/mod_services/classes.globalregistrystore.ts +16 -6
- package/ts/mod_services/classes.legacymongomigration.ts +1308 -0
- package/ts/mod_services/classes.serviceconfiguration.ts +64 -40
- package/ts/mod_services/classes.servicedatamarker.ts +149 -8
- package/ts/mod_services/classes.servicemanager.ts +877 -454
- package/ts/mod_services/classes.servicepruner.ts +27 -19
- package/ts/mod_services/index.ts +67 -6
- package/ts/mod_services/mod.plugins.ts +4 -1
- package/ts_migration/002.runtime-config.ts +8 -1
- package/ts_migration/003.service-data-marker.ts +168 -29
- package/ts_migration/004.global-registry.ts +38 -7
package/readme.md
CHANGED
|
@@ -1246,7 +1246,7 @@ Supported services:
|
|
|
1246
1246
|
|
|
1247
1247
|
| Service | Lifecycle/log aliases |
|
|
1248
1248
|
| ----------------------------- | --------------------- |
|
|
1249
|
-
| MongoDB
|
|
1249
|
+
| MongoDB (NoSQLDB engine) | `mongo`, `mongodb` |
|
|
1250
1250
|
| ObjectStorage (S3-compatible) | `objectstorage`, `s3` |
|
|
1251
1251
|
| Elasticsearch | `elasticsearch`, `es` |
|
|
1252
1252
|
|
|
@@ -1269,16 +1269,36 @@ gitzone services status --json
|
|
|
1269
1269
|
# Print MongoDB Compass connection string
|
|
1270
1270
|
gitzone services compass
|
|
1271
1271
|
|
|
1272
|
+
# Migrate legacy mongod data into NoSQLDB explicitly (start does it automatically)
|
|
1273
|
+
gitzone services migrate mongodb --yes
|
|
1274
|
+
|
|
1272
1275
|
# Show logs
|
|
1273
1276
|
gitzone services logs mongo 50
|
|
1274
1277
|
```
|
|
1275
1278
|
|
|
1276
1279
|
Service config is stored in `.nogit/env.json`. Newly created config files use
|
|
1277
1280
|
owner-only permissions; writes are atomic and reject a stale in-memory snapshot
|
|
1278
|
-
rather than overwriting a concurrent change. MongoDB, ObjectStorage,
|
|
1279
|
-
Elasticsearch data is stored in `.nogit/
|
|
1281
|
+
rather than overwriting a concurrent change. MongoDB (NoSQLDB), ObjectStorage,
|
|
1282
|
+
and Elasticsearch data is stored in `.nogit/nosqldbdata`,
|
|
1280
1283
|
`.nogit/objectstoragedata`, and `.nogit/esdata`, so it stays out of Git.
|
|
1281
1284
|
|
|
1285
|
+
The `mongodb` service runs the NoSQLDB engine from the digest-pinned
|
|
1286
|
+
`code.foss.global/lossless.zone/database` 2.0.0 image (`@lossless.org/nosqldb`
|
|
1287
|
+
10.7.3) as `<project>-nosqldb`. It
|
|
1288
|
+
speaks the MongoDB wire protocol, so the `.nogit/env.json` contract
|
|
1289
|
+
(`MONGODB_URL`, `MONGODB_HOST`, `MONGODB_PORT`, `MONGODB_USER`, `MONGODB_PASS`,
|
|
1290
|
+
`MONGODB_NAME`, `MONGODB_AUTH_ENABLED`) is unchanged and consumers need no code
|
|
1291
|
+
change. The wire port is published as `127.0.0.1:MONGODB_PORT` only. The
|
|
1292
|
+
engine's management UI is not published; its password `MONGODB_ADMIN_PASSWORD`
|
|
1293
|
+
is generated per project, never printed, and redacted from logs and
|
|
1294
|
+
`services config --json`. Startup refuses the default `admin` passwords and an
|
|
1295
|
+
admin password reused as `MONGODB_PASS`, hardens `.nogit/nosqldbdata` to the
|
|
1296
|
+
engine user with mode `0700`, recreates an owned container by immutable ID when
|
|
1297
|
+
its image, port, data bind, `DBST_*` environment, restart policy, command,
|
|
1298
|
+
entrypoint, user, or health check drifted, and waits for an authenticated
|
|
1299
|
+
readiness round trip through `@lossless.org/client/nosqldb`. Transactions run on
|
|
1300
|
+
the single node without a replica set.
|
|
1301
|
+
|
|
1282
1302
|
ObjectStorage uses `S3_PORT` for its local S3 API and `S3_UI_PORT` for its
|
|
1283
1303
|
management UI. `S3_REGION` defaults to `us-east-1`; `S3_ADMIN_PASSWORD` is a
|
|
1284
1304
|
separate randomly generated password for the UI's `admin` user. Startup rejects
|
|
@@ -1357,6 +1377,81 @@ directory, verify its provenance outside GitZone, start a fresh canonical
|
|
|
1357
1377
|
service, and import required objects through S3. Do not synthesize a marker for
|
|
1358
1378
|
unverified data.
|
|
1359
1379
|
|
|
1380
|
+
### Migrating legacy MongoDB (mongod) state
|
|
1381
|
+
|
|
1382
|
+
Releases before NoSQLDB ran `mongo:7.0` as `<project>-mongodb` on
|
|
1383
|
+
`.nogit/mongodata`. The persisted-state migrations move the registry's
|
|
1384
|
+
`containers.mongo` claim to `legacy.mongoContainer` and the marker's mongod
|
|
1385
|
+
directory to a `safeToPrune: false` legacy entry; neither is ever treated as
|
|
1386
|
+
NoSQLDB ownership.
|
|
1387
|
+
|
|
1388
|
+
`gitzone services start` (and the explicit `gitzone services migrate mongodb`,
|
|
1389
|
+
which asks first unless `--yes` is given) migrates the data automatically when
|
|
1390
|
+
ownership is proven: the container carries the exact legacy GitZone labels for
|
|
1391
|
+
this project (or has no GitZone labels and exactly one legacy registry claim),
|
|
1392
|
+
runs `mongo:7.0`, and binds exactly `.nogit/mongodata` at `/data/db`. Data whose
|
|
1393
|
+
container is gone is proven by the marker's legacy entry or a legacy registry
|
|
1394
|
+
claim.
|
|
1395
|
+
|
|
1396
|
+
The migration journals every step in `.nogit/.gitzone-mongodb-migration.json`:
|
|
1397
|
+
|
|
1398
|
+
1. Both images are present before anything is touched.
|
|
1399
|
+
2. Freeze: the legacy container is stopped (by immutable ID, with a 60-second
|
|
1400
|
+
clean-shutdown grace) before anything reads its data, so no application
|
|
1401
|
+
write can land after the snapshot.
|
|
1402
|
+
3. A temporary reader, `<project>-mongodb-migration-<token>`, opens
|
|
1403
|
+
`.nogit/mongodata` with the legacy container's exact image ID. It runs
|
|
1404
|
+
standalone (no `--replSet`, so the stored replica-set configuration is never
|
|
1405
|
+
consulted) with `recoverFromOplogAsStandalone`, which replays the oplog like
|
|
1406
|
+
the replica-set member would and then keeps the node read-only; data that
|
|
1407
|
+
never ran as a replica set is opened as a plain standalone. The reader has
|
|
1408
|
+
no network, no published port, restart policy `no`, and no access control:
|
|
1409
|
+
only short-lived fenced helpers that join its network namespace can reach it.
|
|
1410
|
+
4. From the reader, an inventory (every non-system namespace with document count
|
|
1411
|
+
and index names) and a `mongodump --archive` are taken. MongoDB views are
|
|
1412
|
+
refused before the dump with an error naming every view: NoSQLDB has no
|
|
1413
|
+
general views. The reader is then removed.
|
|
1414
|
+
5. The NoSQLDB container is created on a new `.nogit/nosqldbdata` with no
|
|
1415
|
+
network, no published port, and restart policy `no`, and `mongorestore`
|
|
1416
|
+
restores everything except `admin.*`, `config.*`, and `local.*` with
|
|
1417
|
+
`--stopOnError`. Credentials reach the tools only through the environment
|
|
1418
|
+
and a private config file, never argv.
|
|
1419
|
+
6. The NoSQLDB inventory must match the legacy inventory exactly. The
|
|
1420
|
+
restore-phase container is stopped, and only then does the journal move
|
|
1421
|
+
from `running` to `committing`.
|
|
1422
|
+
7. The restore-phase container is replaced by the published service container
|
|
1423
|
+
(loopback port, `unless-stopped`) on the same data, the legacy container is
|
|
1424
|
+
removed by immutable ID together with its anonymous `/data/configdb` volume,
|
|
1425
|
+
and the journal records `completed`. The bind-mounted `.nogit/mongodata` is
|
|
1426
|
+
never deleted. An interrupted commit resumes on the next start.
|
|
1427
|
+
|
|
1428
|
+
Invariant: while the journal is `running`, no application has ever been able to
|
|
1429
|
+
reach the NoSQLDB data, so it contains only migration writes. Any failure
|
|
1430
|
+
before the commit therefore rolls back safely: the reader and the NoSQLDB
|
|
1431
|
+
container and its data directory are removed, the legacy container is started
|
|
1432
|
+
again by its immutable ID if it was running, and the error carries the redacted
|
|
1433
|
+
tool output. An interrupted migration is rolled back on the next start. Other
|
|
1434
|
+
features NoSQLDB does not support (for example collations, text or geo indexes)
|
|
1435
|
+
surface as restore or verification failures rather than being dropped.
|
|
1436
|
+
|
|
1437
|
+
Every attempt writes its evidence to its own
|
|
1438
|
+
`.nogit/mongodb-migration/<timestamp>-<token>/`: the helper scripts
|
|
1439
|
+
(`inventory.js`, `readiness.js`), the inventories (`source-inventory.json`,
|
|
1440
|
+
`target-inventory.json`), the tool logs (`source-inventory.log`, `dump.log`,
|
|
1441
|
+
`target-readiness.log`, `restore.log`, `target-inventory.log`), and
|
|
1442
|
+
`dump.archive`. Each file exists only if its step ran. A rollback deletes only
|
|
1443
|
+
`dump.archive`, a derived copy of data that stays in `.nogit/mongodata`, and
|
|
1444
|
+
keeps the scripts, inventories, and logs of the failed attempt. After a
|
|
1445
|
+
completed migration, the whole directory, `dump.archive` included, is kept.
|
|
1446
|
+
`.nogit/mongodata` and `.nogit/mongodb-migration/` are never deleted by any
|
|
1447
|
+
GitZone command, including `clean` and `prune`. Remove them manually once the
|
|
1448
|
+
migrated data is confirmed. The journal stays as a permanent completion record,
|
|
1449
|
+
so a later `clean` never re-imports the old data. If ownership cannot be proven, startup
|
|
1450
|
+
stops before any Docker mutation and prints the manual recovery steps. Projects
|
|
1451
|
+
that never run the new CLI keep their running legacy container untouched.
|
|
1452
|
+
`gitzone services stop` and `stop -g` may stop a proven-owned legacy container;
|
|
1453
|
+
nothing else acts on it.
|
|
1454
|
+
|
|
1360
1455
|
### Consuming a service programmatically
|
|
1361
1456
|
|
|
1362
1457
|
`gitzone services status --json` emits only JSON on stdout, so a test suite or
|
|
@@ -1368,9 +1463,10 @@ gitzone services status --json | jq -r '.services.mongodb.connectionString'
|
|
|
1368
1463
|
|
|
1369
1464
|
The ObjectStorage status key is `.services.objectstorage`; the former
|
|
1370
1465
|
`.services.minio` key no longer exists. Preserved predecessor evidence is
|
|
1371
|
-
reported separately under `.legacy`. `minioDataDirectory
|
|
1372
|
-
|
|
1373
|
-
|
|
1466
|
+
reported separately under `.legacy`. `minioDataDirectory`, `minioDataExists`,
|
|
1467
|
+
`mongoDataDirectory`, `mongoDataExists`, `mongoMigrationDirectory`, and
|
|
1468
|
+
`mongoMigrationDirectoryExists` are always emitted; `minioContainer` and
|
|
1469
|
+
`mongoContainer` are present only when container evidence exists. Consumers must treat this as a breaking response-schema change rather
|
|
1374
1470
|
than interpreting legacy evidence as an active service.
|
|
1375
1471
|
|
|
1376
1472
|
### Cleanup levels
|
|
@@ -1395,8 +1491,8 @@ whether still `created` or already `exited`, can be recovered only after their
|
|
|
1395
1491
|
complete runtime envelope, bind target, age, and immutable ID are proven;
|
|
1396
1492
|
running, fresh, or noncanonical occupants block the operation.
|
|
1397
1493
|
|
|
1398
|
-
A helper carries exactly one read-write bind of its target.
|
|
1399
|
-
|
|
1494
|
+
A helper carries exactly one read-write bind of its target. Images such as
|
|
1495
|
+
`mongo:7.0` additionally declare their own `VOLUME` destinations, for which
|
|
1400
1496
|
Docker attaches anonymous volumes GitZone never requested; those are accepted
|
|
1401
1497
|
only where Docker proves them image-declared and anonymous, namely the local
|
|
1402
1498
|
driver, a random 64-character volume name, and a destination the container's own
|
|
@@ -1444,26 +1540,30 @@ container running. Anything ambiguous — an unlabeled container claimed by more
|
|
|
1444
1540
|
than one project, an unreachable Docker daemon, a directory still mounted by a
|
|
1445
1541
|
running container — is reported and skipped rather than reclaimed. Containers
|
|
1446
1542
|
are identified by an exact canonical GitZone label envelope. An unambiguous
|
|
1447
|
-
registry claim is used only for older
|
|
1448
|
-
|
|
1449
|
-
fallback
|
|
1543
|
+
registry claim is used only for older Elasticsearch containers with no
|
|
1544
|
+
`git.zone.*` labels at all. NoSQLDB and ObjectStorage have no unlabeled
|
|
1545
|
+
predecessor fallback, and their data is reclaimable only with marker proof;
|
|
1546
|
+
partial, missing, or conflicting GitZone labels fail closed. Removal
|
|
1450
1547
|
revalidates and uses the container's immutable ID, never its mutable name, so
|
|
1451
1548
|
pruning cannot touch a same-name replacement. If Docker becomes unavailable,
|
|
1452
1549
|
registry claims are preserved as well as containers and data.
|
|
1453
1550
|
|
|
1454
|
-
Legacy MinIO
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1551
|
+
Legacy MinIO and mongod containers are reported as preserved migration
|
|
1552
|
+
resources and are never prune candidates. A legacy MinIO registry reference is
|
|
1553
|
+
kept permanently. A legacy mongod registry reference is dropped together with
|
|
1554
|
+
its project's registry entry once the project directory is gone and no
|
|
1555
|
+
container with that name remains, because it can then identify nothing; while
|
|
1556
|
+
such a container exists, the entry is kept so the container stays identifiable.
|
|
1557
|
+
`.nogit/miniodata`,
|
|
1558
|
+
`.nogit/mongodata`, and `.nogit/mongodb-migration` are deliberately outside the
|
|
1559
|
+
prune allowlist; current-project `status` reports their presence, while
|
|
1560
|
+
machine-wide prune leaves them untouched.
|
|
1458
1561
|
|
|
1459
1562
|
### MongoDB authentication
|
|
1460
1563
|
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
Docker's low default. `services start` reconciles legacy containers to this limit
|
|
1465
|
-
by recreating only the container while preserving the bind-mounted data directory.
|
|
1466
|
-
Authentication can be disabled per project for
|
|
1564
|
+
NoSQLDB runs with SCRAM-SHA-256 authentication enabled; the root user is
|
|
1565
|
+
`MONGODB_USER`/`MONGODB_PASS` in the `admin` database. Authentication can be
|
|
1566
|
+
disabled per project for
|
|
1467
1567
|
runtimes whose `node:crypto` cannot complete a SCRAM handshake (notably Deno):
|
|
1468
1568
|
|
|
1469
1569
|
```bash
|
|
@@ -1471,12 +1571,11 @@ gitzone services auth mongodb off
|
|
|
1471
1571
|
gitzone services start mongo
|
|
1472
1572
|
```
|
|
1473
1573
|
|
|
1474
|
-
This is opt-in and never implicit.
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
`gitzone services status` reports the mode.
|
|
1478
|
-
|
|
1479
|
-
localhost exception.
|
|
1574
|
+
This is opt-in and never implicit. The database is always published on
|
|
1575
|
+
`127.0.0.1` only, and the combination of no authentication with a non-local
|
|
1576
|
+
`MONGODB_HOST` is refused outright. Transactions continue to work, and
|
|
1577
|
+
`gitzone services status` reports the mode. Changing the mode recreates the
|
|
1578
|
+
container with the matching engine configuration.
|
|
1480
1579
|
|
|
1481
1580
|
The setting is recorded in `.smartconfig.json`, so it is committed and a fresh
|
|
1482
1581
|
clone or CI run reproduces it without any manual step:
|
|
@@ -1504,7 +1603,7 @@ authentication is enabled. Because a declaration affects everyone who clones the
|
|
|
1504
1603
|
repository, `services status` states where the setting came from:
|
|
1505
1604
|
|
|
1506
1605
|
```text
|
|
1507
|
-
⚠️ Auth: DISABLED
|
|
1606
|
+
⚠️ Auth: DISABLED, declared in .smartconfig.json (applies to every checkout)
|
|
1508
1607
|
```
|
|
1509
1608
|
|
|
1510
1609
|
An older CLI that predates `serviceOptions` ignores the key and starts MongoDB
|
package/ts/00_commitinfo_data.ts
CHANGED
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export const commitinfo = {
|
|
5
5
|
name: '@git.zone/cli',
|
|
6
|
-
version: '
|
|
6
|
+
version: '8.0.0',
|
|
7
7
|
description: 'A comprehensive CLI tool for enhancing and managing local development workflows with gitzone utilities, focusing on project setup, version control, code formatting, and template management.'
|
|
8
8
|
}
|
|
@@ -3,6 +3,7 @@ import * as helpers from './helpers.js';
|
|
|
3
3
|
import { logger } from '../gitzone.logging.js';
|
|
4
4
|
import {
|
|
5
5
|
getServiceDataDirectory,
|
|
6
|
+
isLegacyServiceContainerLabels,
|
|
6
7
|
markerProvesServiceDataDirectory,
|
|
7
8
|
readServiceDataMarker,
|
|
8
9
|
serviceBindOperation,
|
|
@@ -22,8 +23,6 @@ export interface IDockerUlimit {
|
|
|
22
23
|
|
|
23
24
|
export type TDockerUlimits = Record<string, IDockerUlimit>;
|
|
24
25
|
|
|
25
|
-
export type TDockerUlimitMatch = 'match' | 'mismatch' | 'unavailable';
|
|
26
|
-
|
|
27
26
|
export interface IDockerRunOptions {
|
|
28
27
|
name: string;
|
|
29
28
|
image: string;
|
|
@@ -41,6 +40,8 @@ export interface IDockerCreateArgvOptions extends Omit<IDockerRunOptions, 'comma
|
|
|
41
40
|
command?: readonly string[];
|
|
42
41
|
user?: string;
|
|
43
42
|
entrypoint?: string;
|
|
43
|
+
/** Docker network mode, e.g. `container:<64-hex id>` to share a service's namespace. */
|
|
44
|
+
network?: string;
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
export interface IDockerExecArgvOptions {
|
|
@@ -73,6 +74,12 @@ export interface IFencedBindOperationOptions extends IFencedBindOperationSpecifi
|
|
|
73
74
|
executionOptions: () => IDockerExecArgvOptions;
|
|
74
75
|
rollbackTimeoutMs?: number;
|
|
75
76
|
recoverablePredecessors?: readonly IFencedBindOperationSpecification[];
|
|
77
|
+
/** Container user; root (`0`) unless the operation must write as the invoking user. */
|
|
78
|
+
user?: string;
|
|
79
|
+
/** Exact network mode; `container:<64-hex id>` joins one service's namespace. */
|
|
80
|
+
network?: string;
|
|
81
|
+
/** Passed by name, so values never enter Docker's argv. */
|
|
82
|
+
environment?: Record<string, string>;
|
|
76
83
|
}
|
|
77
84
|
|
|
78
85
|
interface IFencedBindRuntimeOptions extends IFencedBindOperationOptions {
|
|
@@ -429,42 +436,6 @@ export const renderDockerUlimits = (ulimitsArg: TDockerUlimits = {}): string =>
|
|
|
429
436
|
return rendered;
|
|
430
437
|
};
|
|
431
438
|
|
|
432
|
-
export const matchDockerUlimits = (
|
|
433
|
-
inspectDataArg: unknown,
|
|
434
|
-
expectedArg: TDockerUlimits,
|
|
435
|
-
): TDockerUlimitMatch => {
|
|
436
|
-
if (!Array.isArray(inspectDataArg) || inspectDataArg.length !== 1) {
|
|
437
|
-
return 'unavailable';
|
|
438
|
-
}
|
|
439
|
-
const container = inspectDataArg[0] as {
|
|
440
|
-
HostConfig?: {
|
|
441
|
-
Ulimits?: Array<{ Name?: unknown; Soft?: unknown; Hard?: unknown }> | null;
|
|
442
|
-
};
|
|
443
|
-
};
|
|
444
|
-
if (!container?.HostConfig) {
|
|
445
|
-
return 'unavailable';
|
|
446
|
-
}
|
|
447
|
-
if (!Object.hasOwn(container.HostConfig, 'Ulimits')) {
|
|
448
|
-
return 'unavailable';
|
|
449
|
-
}
|
|
450
|
-
const actual = container.HostConfig.Ulimits ?? [];
|
|
451
|
-
if (!Array.isArray(actual)) {
|
|
452
|
-
return 'unavailable';
|
|
453
|
-
}
|
|
454
|
-
for (const [name, expected] of Object.entries(expectedArg)) {
|
|
455
|
-
assertDockerUlimit(name, expected);
|
|
456
|
-
const matchingName = actual.filter((entry) => entry?.Name === name);
|
|
457
|
-
if (
|
|
458
|
-
matchingName.length !== 1 ||
|
|
459
|
-
matchingName[0].Soft !== expected.soft ||
|
|
460
|
-
matchingName[0].Hard !== expected.hard
|
|
461
|
-
) {
|
|
462
|
-
return 'mismatch';
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
return 'match';
|
|
466
|
-
};
|
|
467
|
-
|
|
468
439
|
const isUnknownRecord = (valueArg: unknown): valueArg is Record<string, any> => {
|
|
469
440
|
return typeof valueArg === 'object' && valueArg !== null && !Array.isArray(valueArg);
|
|
470
441
|
};
|
|
@@ -478,6 +449,7 @@ interface IFencedBindInspection {
|
|
|
478
449
|
status: string;
|
|
479
450
|
exitCode: number;
|
|
480
451
|
user: string;
|
|
452
|
+
networkMode: string;
|
|
481
453
|
entrypoint: string[];
|
|
482
454
|
command: string[];
|
|
483
455
|
labels: Record<string, string>;
|
|
@@ -541,8 +513,13 @@ const parseFencedBindInspection = (
|
|
|
541
513
|
const inspected = parsed[0];
|
|
542
514
|
const config = inspected.Config;
|
|
543
515
|
const state = inspected.State;
|
|
516
|
+
const hostConfig = inspected.HostConfig;
|
|
544
517
|
const normalizedName = String(inspected.Name || '').replace(/^\//u, '');
|
|
545
518
|
const createdAtMs = Date.parse(String(inspected.Created || ''));
|
|
519
|
+
const networkMode =
|
|
520
|
+
isUnknownRecord(hostConfig) && typeof hostConfig.NetworkMode === 'string'
|
|
521
|
+
? hostConfig.NetworkMode
|
|
522
|
+
: '';
|
|
546
523
|
if (
|
|
547
524
|
typeof inspected.Id !== 'string' ||
|
|
548
525
|
!/^[a-f0-9]{64}$/u.test(inspected.Id) ||
|
|
@@ -591,6 +568,7 @@ const parseFencedBindInspection = (
|
|
|
591
568
|
status: state.Status,
|
|
592
569
|
exitCode: state.ExitCode,
|
|
593
570
|
user: config.User,
|
|
571
|
+
networkMode,
|
|
594
572
|
entrypoint: [...config.Entrypoint],
|
|
595
573
|
command: [...config.Cmd],
|
|
596
574
|
labels,
|
|
@@ -722,6 +700,9 @@ export class DockerContainer {
|
|
|
722
700
|
if (optionsArg.user) {
|
|
723
701
|
argv.push('--user', optionsArg.user);
|
|
724
702
|
}
|
|
703
|
+
if (optionsArg.network) {
|
|
704
|
+
argv.push('--network', optionsArg.network);
|
|
705
|
+
}
|
|
725
706
|
if (optionsArg.entrypoint) {
|
|
726
707
|
argv.push('--entrypoint', optionsArg.entrypoint);
|
|
727
708
|
}
|
|
@@ -759,7 +740,8 @@ export class DockerContainer {
|
|
|
759
740
|
if (
|
|
760
741
|
inspectionArg.name !== optionsArg.name ||
|
|
761
742
|
inspectionArg.image !== optionsArg.image ||
|
|
762
|
-
inspectionArg.user !== '0' ||
|
|
743
|
+
inspectionArg.user !== (optionsArg.user ?? '0') ||
|
|
744
|
+
(optionsArg.network !== undefined && inspectionArg.networkMode !== optionsArg.network) ||
|
|
763
745
|
inspectionArg.entrypoint.length !== 1 ||
|
|
764
746
|
inspectionArg.entrypoint[0] !== optionsArg.entrypoint ||
|
|
765
747
|
inspectionArg.command.length !== optionsArg.command.length ||
|
|
@@ -818,7 +800,8 @@ export class DockerContainer {
|
|
|
818
800
|
if (
|
|
819
801
|
inspectionArg.name !== expectedNameArg ||
|
|
820
802
|
inspectionArg.image !== optionsArg.image ||
|
|
821
|
-
inspectionArg.user !== '0' ||
|
|
803
|
+
inspectionArg.user !== (optionsArg.user ?? '0') ||
|
|
804
|
+
(optionsArg.network !== undefined && inspectionArg.networkMode !== optionsArg.network) ||
|
|
822
805
|
!operationMatches ||
|
|
823
806
|
!labelsMatch ||
|
|
824
807
|
!mountMatches
|
|
@@ -973,9 +956,11 @@ export class DockerContainer {
|
|
|
973
956
|
[plugins.path.resolve(runtimeOptions.hostPath)]: runtimeOptions.containerPath,
|
|
974
957
|
},
|
|
975
958
|
labels: runtimeOptions.labels,
|
|
976
|
-
user: '0',
|
|
959
|
+
user: runtimeOptions.user ?? '0',
|
|
977
960
|
entrypoint: runtimeOptions.entrypoint,
|
|
978
961
|
command: runtimeOptions.command,
|
|
962
|
+
...(runtimeOptions.network ? { network: runtimeOptions.network } : {}),
|
|
963
|
+
...(runtimeOptions.environment ? { environment: runtimeOptions.environment } : {}),
|
|
979
964
|
},
|
|
980
965
|
runtimeOptions.executionOptions(),
|
|
981
966
|
);
|
|
@@ -1373,6 +1358,18 @@ export class DockerContainer {
|
|
|
1373
1358
|
);
|
|
1374
1359
|
}
|
|
1375
1360
|
|
|
1361
|
+
/**
|
|
1362
|
+
* `removeDataDirectory` for a caller that already holds this service's data
|
|
1363
|
+
* operation lock (the lock is not re-entrant). Used by lifecycle rollback.
|
|
1364
|
+
*/
|
|
1365
|
+
public async removeDataDirectoryHoldingLock(
|
|
1366
|
+
hostPathArg: string,
|
|
1367
|
+
imageArg: string,
|
|
1368
|
+
optionsArg: IRemoveDataDirectoryOptions,
|
|
1369
|
+
): Promise<boolean> {
|
|
1370
|
+
return this.removeDataDirectoryLocked(hostPathArg, imageArg, optionsArg);
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1376
1373
|
private async removeDataDirectoryLocked(
|
|
1377
1374
|
hostPathArg: string,
|
|
1378
1375
|
imageArg: string,
|
|
@@ -1418,7 +1415,7 @@ export class DockerContainer {
|
|
|
1418
1415
|
);
|
|
1419
1416
|
}
|
|
1420
1417
|
|
|
1421
|
-
if (optionsArg.service
|
|
1418
|
+
if (optionsArg.service !== 'elasticsearch' && (canonicalExists || quarantineExists)) {
|
|
1422
1419
|
const marker = await readServiceDataMarker(projectPath);
|
|
1423
1420
|
if (
|
|
1424
1421
|
!markerProvesServiceDataDirectory(
|
|
@@ -1427,7 +1424,9 @@ export class DockerContainer {
|
|
|
1427
1424
|
optionsArg.service,
|
|
1428
1425
|
)
|
|
1429
1426
|
) {
|
|
1430
|
-
throw new Error(
|
|
1427
|
+
throw new Error(
|
|
1428
|
+
`Refusing ${optionsArg.service} data cleanup with unproven ownership: ${hostPath}`,
|
|
1429
|
+
);
|
|
1431
1430
|
}
|
|
1432
1431
|
}
|
|
1433
1432
|
const targetPaths = [hostPath, quarantinePath];
|
|
@@ -1435,9 +1434,19 @@ export class DockerContainer {
|
|
|
1435
1434
|
`label=git.zone.project-path=${projectPath}`,
|
|
1436
1435
|
`label=git.zone.service=${optionsArg.service}`,
|
|
1437
1436
|
];
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1437
|
+
// Predecessor containers (legacy mongod) carry the same service label but
|
|
1438
|
+
// never mount the canonical path; the mount check below still proves that.
|
|
1439
|
+
const listActiveServiceContainers = async (): Promise<IContainerInspectInfo[]> => {
|
|
1440
|
+
const ids = await this.listIds(serviceContainerFilters);
|
|
1441
|
+
if (ids.length === 0) {
|
|
1442
|
+
return [];
|
|
1443
|
+
}
|
|
1444
|
+
return (await this.inspectMany(ids)).filter(
|
|
1445
|
+
(container) => !isLegacyServiceContainerLabels(container.labels),
|
|
1446
|
+
);
|
|
1447
|
+
};
|
|
1448
|
+
let serviceContainers = await listActiveServiceContainers();
|
|
1449
|
+
if (serviceContainers.length > 0) {
|
|
1441
1450
|
const helperTargets = new Set<string>();
|
|
1442
1451
|
for (const container of serviceContainers) {
|
|
1443
1452
|
const helperTarget = targetPaths.find((targetPathArg) =>
|
|
@@ -1456,11 +1465,10 @@ export class DockerContainer {
|
|
|
1456
1465
|
getFencedBindOperationName(helperTarget),
|
|
1457
1466
|
);
|
|
1458
1467
|
}
|
|
1459
|
-
|
|
1460
|
-
if (
|
|
1461
|
-
const [container] = await this.inspectMany(serviceContainerIds);
|
|
1468
|
+
serviceContainers = await listActiveServiceContainers();
|
|
1469
|
+
if (serviceContainers.length > 0) {
|
|
1462
1470
|
throw new Error(
|
|
1463
|
-
`Refusing service data cleanup while container ${
|
|
1471
|
+
`Refusing service data cleanup while container ${serviceContainers[0].name} exists.`,
|
|
1464
1472
|
);
|
|
1465
1473
|
}
|
|
1466
1474
|
}
|
|
@@ -2,6 +2,7 @@ import * as plugins from '../plugins.js';
|
|
|
2
2
|
import { DockerContainer, type IContainerInspectInfo } from './classes.dockercontainer.js';
|
|
3
3
|
import { logger } from '../gitzone.logging.js';
|
|
4
4
|
import {
|
|
5
|
+
getLegacyMongoContainerLabels,
|
|
5
6
|
getServiceContainerLabels,
|
|
6
7
|
getServiceDataDirectory,
|
|
7
8
|
hasExactServiceContainerLabels,
|
|
@@ -23,7 +24,7 @@ export type {
|
|
|
23
24
|
} from './classes.globalregistrystore.js';
|
|
24
25
|
|
|
25
26
|
const registryServiceNames: Record<string, TServiceName> = {
|
|
26
|
-
|
|
27
|
+
nosqldb: 'mongodb',
|
|
27
28
|
objectstorage: 'objectstorage',
|
|
28
29
|
elasticsearch: 'elasticsearch',
|
|
29
30
|
};
|
|
@@ -70,6 +71,40 @@ export class GlobalRegistry {
|
|
|
70
71
|
});
|
|
71
72
|
}
|
|
72
73
|
|
|
74
|
+
/**
|
|
75
|
+
* Drop the legacy mongod container reference after a verified NoSQLDB
|
|
76
|
+
* migration removed that container. Compare-and-delete: a changed reference
|
|
77
|
+
* is refused rather than overwritten.
|
|
78
|
+
*/
|
|
79
|
+
public async clearLegacyMongoContainer(
|
|
80
|
+
projectPathArg: string,
|
|
81
|
+
expectedContainerNameArg: string,
|
|
82
|
+
): Promise<void> {
|
|
83
|
+
const projectPath = plugins.path.resolve(projectPathArg);
|
|
84
|
+
await this.store.transact((rawData) => {
|
|
85
|
+
const allData = assertCanonicalGlobalRegistryData(rawData);
|
|
86
|
+
const projects = { ...allData.projects };
|
|
87
|
+
const currentProject = projects[projectPath];
|
|
88
|
+
if (!currentProject?.legacy?.mongoContainer) {
|
|
89
|
+
return { result: undefined };
|
|
90
|
+
}
|
|
91
|
+
if (currentProject.legacy.mongoContainer !== expectedContainerNameArg) {
|
|
92
|
+
throw new Error(
|
|
93
|
+
`Refusing to clear a changed legacy MongoDB registry reference: ${projectPath}`,
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
const { legacy, ...projectWithoutLegacy } = currentProject;
|
|
97
|
+
projects[projectPath] = {
|
|
98
|
+
...projectWithoutLegacy,
|
|
99
|
+
...(legacy.minioContainer ? { legacy: { minioContainer: legacy.minioContainer } } : {}),
|
|
100
|
+
};
|
|
101
|
+
return {
|
|
102
|
+
result: undefined,
|
|
103
|
+
writeData: { schemaVersion: 2, projects },
|
|
104
|
+
};
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
73
108
|
/**
|
|
74
109
|
* Remove a project from the registry
|
|
75
110
|
*/
|
|
@@ -176,27 +211,25 @@ export class GlobalRegistry {
|
|
|
176
211
|
|
|
177
212
|
for (const [serviceKey, containerName] of Object.entries(project.containers)) {
|
|
178
213
|
if (containerName) {
|
|
179
|
-
|
|
180
|
-
|
|
214
|
+
const labeledService = registryServiceNames[serviceKey];
|
|
215
|
+
if (labeledService === 'objectstorage' || labeledService === 'mongodb') {
|
|
216
|
+
const inspection = await this.inspectRegisteredContainer(
|
|
181
217
|
project,
|
|
182
218
|
containerName,
|
|
183
219
|
);
|
|
184
|
-
if (!
|
|
220
|
+
if (!inspection) {
|
|
185
221
|
containerStatuses.push({ name: containerName, status: 'not_exists' });
|
|
186
222
|
continue;
|
|
187
223
|
}
|
|
188
224
|
const expectedLabels = getServiceContainerLabels({
|
|
189
225
|
projectPath: project.projectPath,
|
|
190
|
-
service:
|
|
191
|
-
dataPath: getServiceDataDirectory(project.projectPath,
|
|
226
|
+
service: labeledService,
|
|
227
|
+
dataPath: getServiceDataDirectory(project.projectPath, labeledService),
|
|
192
228
|
});
|
|
193
|
-
const owned = hasExactServiceContainerLabels(
|
|
194
|
-
objectStorage.labels,
|
|
195
|
-
expectedLabels,
|
|
196
|
-
);
|
|
229
|
+
const owned = hasExactServiceContainerLabels(inspection.labels, expectedLabels);
|
|
197
230
|
containerStatuses.push({
|
|
198
231
|
name: containerName,
|
|
199
|
-
status:
|
|
232
|
+
status: inspection.state,
|
|
200
233
|
ownership: owned ? 'owned' : 'conflict',
|
|
201
234
|
});
|
|
202
235
|
continue;
|
|
@@ -280,7 +313,7 @@ export class GlobalRegistry {
|
|
|
280
313
|
keyArg.startsWith('git.zone.'),
|
|
281
314
|
);
|
|
282
315
|
const registryOwned =
|
|
283
|
-
service
|
|
316
|
+
service === 'elasticsearch' &&
|
|
284
317
|
!hasGitZoneLabels &&
|
|
285
318
|
claims.length === 1 &&
|
|
286
319
|
claims[0].projectPath === projectPath &&
|
|
@@ -302,9 +335,72 @@ export class GlobalRegistry {
|
|
|
302
335
|
}
|
|
303
336
|
}
|
|
304
337
|
|
|
338
|
+
for (const project of Object.values(projects)) {
|
|
339
|
+
const legacyName = project.legacy?.mongoContainer;
|
|
340
|
+
if (!legacyName) {
|
|
341
|
+
continue;
|
|
342
|
+
}
|
|
343
|
+
try {
|
|
344
|
+
const stoppedLegacy = await this.stopLegacyMongoContainer(project, legacyName);
|
|
345
|
+
if (stoppedLegacy) {
|
|
346
|
+
stopped.push(legacyName);
|
|
347
|
+
}
|
|
348
|
+
} catch {
|
|
349
|
+
if (!failed.includes(legacyName)) {
|
|
350
|
+
failed.push(legacyName);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
305
355
|
return { stopped, failed };
|
|
306
356
|
}
|
|
307
357
|
|
|
358
|
+
/**
|
|
359
|
+
* Stop a proven-owned legacy mongod container by immutable id. Ownership is
|
|
360
|
+
* the exact legacy label envelope, or no GitZone labels plus exactly one
|
|
361
|
+
* registry claim. Stopping is the only mutation allowed here.
|
|
362
|
+
*/
|
|
363
|
+
private async stopLegacyMongoContainer(
|
|
364
|
+
projectArg: IRegisteredProject,
|
|
365
|
+
containerNameArg: string,
|
|
366
|
+
): Promise<boolean> {
|
|
367
|
+
return withServiceDataOperationLock(projectArg.projectPath, 'mongodb', async () => {
|
|
368
|
+
const projectPath = plugins.path.resolve(projectArg.projectPath);
|
|
369
|
+
const currentProjects = await this.getAllProjects();
|
|
370
|
+
const claims = Object.entries(currentProjects).filter(
|
|
371
|
+
([, registeredProjectArg]) =>
|
|
372
|
+
registeredProjectArg.legacy?.mongoContainer === containerNameArg ||
|
|
373
|
+
Object.values(registeredProjectArg.containers).includes(containerNameArg),
|
|
374
|
+
);
|
|
375
|
+
if (
|
|
376
|
+
claims.length !== 1 ||
|
|
377
|
+
plugins.path.resolve(claims[0][0]) !== projectPath ||
|
|
378
|
+
claims[0][1].legacy?.mongoContainer !== containerNameArg
|
|
379
|
+
) {
|
|
380
|
+
throw new Error('Legacy MongoDB registry claim is ambiguous or changed');
|
|
381
|
+
}
|
|
382
|
+
const inspection = await this.inspectRegisteredContainer(projectArg, containerNameArg);
|
|
383
|
+
if (!inspection) {
|
|
384
|
+
return false;
|
|
385
|
+
}
|
|
386
|
+
const labelOwned = hasExactServiceContainerLabels(
|
|
387
|
+
inspection.labels,
|
|
388
|
+
getLegacyMongoContainerLabels(projectPath),
|
|
389
|
+
);
|
|
390
|
+
const unlabeled = !Object.keys(inspection.labels).some((keyArg) =>
|
|
391
|
+
keyArg.startsWith('git.zone.'),
|
|
392
|
+
);
|
|
393
|
+
if (!labelOwned && !unlabeled) {
|
|
394
|
+
throw new Error('Legacy MongoDB container ownership conflict');
|
|
395
|
+
}
|
|
396
|
+
if (!inspection.running) {
|
|
397
|
+
return false;
|
|
398
|
+
}
|
|
399
|
+
await this.docker.execArgv(['stop', inspection.id], { timeoutMs: 60_000 });
|
|
400
|
+
return true;
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
|
|
308
404
|
private async inspectRegisteredContainer(
|
|
309
405
|
projectArg: IRegisteredProject,
|
|
310
406
|
containerNameArg: string,
|
|
@@ -318,7 +414,7 @@ export class GlobalRegistry {
|
|
|
318
414
|
);
|
|
319
415
|
if (inspections.length !== 1) {
|
|
320
416
|
throw new Error(
|
|
321
|
-
`Docker returned ambiguous
|
|
417
|
+
`Docker returned ambiguous container identity for ${projectArg.projectPath}.`,
|
|
322
418
|
);
|
|
323
419
|
}
|
|
324
420
|
return inspections[0];
|
|
@@ -400,7 +496,12 @@ export class GlobalRegistry {
|
|
|
400
496
|
// them. Re-read under all service locks so a concurrent start cannot
|
|
401
497
|
// appear between the Docker check and compare-delete.
|
|
402
498
|
const survivingContainers: string[] = [];
|
|
403
|
-
|
|
499
|
+
// A legacy mongod reference only matters while that container exists;
|
|
500
|
+
// its data lived inside the project directory, which is gone.
|
|
501
|
+
for (const containerName of [
|
|
502
|
+
...Object.values(currentProject.containers),
|
|
503
|
+
currentProject.legacy?.mongoContainer,
|
|
504
|
+
]) {
|
|
404
505
|
if (containerName && (await this.exactContainerExists(containerName))) {
|
|
405
506
|
survivingContainers.push(containerName);
|
|
406
507
|
}
|