@git.zone/cli 7.4.1 → 8.1.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.
Files changed (39) hide show
  1. package/dist_ts/00_commitinfo_data.js +1 -1
  2. package/dist_ts/mod_services/classes.dockercontainer.d.ts +13 -2
  3. package/dist_ts/mod_services/classes.dockercontainer.js +40 -40
  4. package/dist_ts/mod_services/classes.globalregistry.d.ts +12 -0
  5. package/dist_ts/mod_services/classes.globalregistry.js +96 -13
  6. package/dist_ts/mod_services/classes.globalregistrystore.d.ts +7 -1
  7. package/dist_ts/mod_services/classes.globalregistrystore.js +6 -6
  8. package/dist_ts/mod_services/classes.legacymongomigration.d.ts +239 -0
  9. package/dist_ts/mod_services/classes.legacymongomigration.js +970 -0
  10. package/dist_ts/mod_services/classes.serviceconfiguration.d.ts +112 -15
  11. package/dist_ts/mod_services/classes.serviceconfiguration.js +274 -62
  12. package/dist_ts/mod_services/classes.servicedatamarker.d.ts +42 -1
  13. package/dist_ts/mod_services/classes.servicedatamarker.js +101 -8
  14. package/dist_ts/mod_services/classes.servicemanager.d.ts +99 -33
  15. package/dist_ts/mod_services/classes.servicemanager.js +652 -384
  16. package/dist_ts/mod_services/classes.servicepruner.js +27 -20
  17. package/dist_ts/mod_services/index.js +62 -13
  18. package/dist_ts/mod_services/mod.plugins.d.ts +2 -1
  19. package/dist_ts/mod_services/mod.plugins.js +4 -2
  20. package/dist_ts_migration/002.runtime-config.d.ts +1 -1
  21. package/dist_ts_migration/002.runtime-config.js +8 -2
  22. package/dist_ts_migration/003.service-data-marker.js +125 -30
  23. package/dist_ts_migration/004.global-registry.js +30 -8
  24. package/package.json +1 -1
  25. package/readme.md +197 -32
  26. package/ts/00_commitinfo_data.ts +1 -1
  27. package/ts/mod_services/classes.dockercontainer.ts +58 -50
  28. package/ts/mod_services/classes.globalregistry.ts +115 -14
  29. package/ts/mod_services/classes.globalregistrystore.ts +16 -6
  30. package/ts/mod_services/classes.legacymongomigration.ts +1308 -0
  31. package/ts/mod_services/classes.serviceconfiguration.ts +387 -69
  32. package/ts/mod_services/classes.servicedatamarker.ts +149 -8
  33. package/ts/mod_services/classes.servicemanager.ts +877 -454
  34. package/ts/mod_services/classes.servicepruner.ts +27 -19
  35. package/ts/mod_services/index.ts +81 -12
  36. package/ts/mod_services/mod.plugins.ts +4 -1
  37. package/ts_migration/002.runtime-config.ts +8 -1
  38. package/ts_migration/003.service-data-marker.ts +168 -29
  39. package/ts_migration/004.global-registry.ts +38 -7
@@ -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
- mongo: 'mongodb',
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
- if (serviceKey === 'objectstorage') {
180
- const objectStorage = await this.inspectRegisteredContainer(
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 (!objectStorage) {
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: 'objectstorage',
191
- dataPath: getServiceDataDirectory(project.projectPath, 'objectstorage'),
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: objectStorage.state,
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 !== 'objectstorage' &&
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 ObjectStorage identity for ${projectArg.projectPath}.`,
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
- for (const containerName of Object.values(currentProject.containers)) {
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
  }
@@ -5,7 +5,8 @@ export interface IRegisteredProject {
5
5
  projectPath: string;
6
6
  projectName: string;
7
7
  containers: {
8
- mongo?: string;
8
+ /** NoSQLDB container serving the `mongodb` service. */
9
+ nosqldb?: string;
9
10
  objectstorage?: string;
10
11
  elasticsearch?: string;
11
12
  };
@@ -18,6 +19,11 @@ export interface IRegisteredProject {
18
19
  legacy?: {
19
20
  /** Preserved migration evidence. Never passed to an active lifecycle operation. */
20
21
  minioContainer?: string;
22
+ /**
23
+ * Legacy mongod container of the `mongodb` service. Only the NoSQLDB
24
+ * migration may stop or remove it, after proving exact ownership.
25
+ */
26
+ mongoContainer?: string;
21
27
  };
22
28
  enabledServices: string[];
23
29
  lastActive: number;
@@ -146,12 +152,12 @@ export const assertCanonicalGlobalRegistryData = (
146
152
  const rawPorts = rawProject.ports;
147
153
  assertAllowedKeys(
148
154
  rawContainers,
149
- ['mongo', 'objectstorage', 'elasticsearch'],
155
+ ['nosqldb', 'objectstorage', 'elasticsearch'],
150
156
  `project ${projectPath} containers`,
151
157
  );
152
158
  assertOptionalStrings(
153
159
  rawContainers,
154
- ['mongo', 'objectstorage', 'elasticsearch'],
160
+ ['nosqldb', 'objectstorage', 'elasticsearch'],
155
161
  `project ${projectPath}.containers`,
156
162
  );
157
163
  assertAllowedKeys(
@@ -170,13 +176,17 @@ export const assertCanonicalGlobalRegistryData = (
170
176
  `Global services registry project ${projectPath} has invalid legacy evidence.`,
171
177
  );
172
178
  }
173
- assertAllowedKeys(rawProject.legacy, ['minioContainer'], `project ${projectPath} legacy`);
179
+ assertAllowedKeys(
180
+ rawProject.legacy,
181
+ ['minioContainer', 'mongoContainer'],
182
+ `project ${projectPath} legacy`,
183
+ );
174
184
  assertOptionalStrings(
175
185
  rawProject.legacy,
176
- ['minioContainer'],
186
+ ['minioContainer', 'mongoContainer'],
177
187
  `project ${projectPath}.legacy`,
178
188
  );
179
- if (!rawProject.legacy.minioContainer) {
189
+ if (!rawProject.legacy.minioContainer && !rawProject.legacy.mongoContainer) {
180
190
  throw new Error(
181
191
  `Global services registry project ${projectPath} has empty legacy evidence.`,
182
192
  );