@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
@@ -10,13 +10,24 @@ import { withInterProcessLock } from './classes.interprocesslock.js';
10
10
  * array shape must never change here.
11
11
  */
12
12
  export type TServiceName = 'mongodb' | 'objectstorage' | 'elasticsearch';
13
- export type TLegacyServiceName = 'minio';
13
+ export type TLegacyServiceName = 'minio' | 'mongo';
14
14
 
15
15
  export const serviceNames: TServiceName[] = ['mongodb', 'objectstorage', 'elasticsearch'];
16
16
 
17
17
  export const objectStorageImage =
18
18
  'code.foss.global/lossless.zone/objectstorage@sha256:43b60897eed17b54feb4e363808ce540ed1d9d27201871c5c8a869300d41e1b8';
19
19
 
20
+ /**
21
+ * NoSQLDB engine image serving the `mongodb` service:
22
+ * `code.foss.global/lossless.zone/database` 2.0.0 (@lossless.org/nosqldb
23
+ * 10.7.3), multi-arch index digest for linux/amd64 and linux/arm64.
24
+ */
25
+ export const noSqlDbImage =
26
+ 'code.foss.global/lossless.zone/database@sha256:8fed3bc2da051a6ce29906383ea37e3ae777e2a7373869effbd3093fc4a2a650';
27
+
28
+ /** The only image older GitZone releases ever ran the `mongodb` service with. */
29
+ export const legacyMongoImage = 'mongo:7.0';
30
+
20
31
  /** Owner recorded in markers and container labels. */
21
32
  export const serviceDataOwner = '@git.zone/cli';
22
33
 
@@ -27,6 +38,7 @@ export const serviceToolLabel = 'gitzone-services';
27
38
  export const serviceDataMarkerFile = '.gitzone-services.json';
28
39
  export const serviceDataMarkerSchemaVersion = 2;
29
40
  export const legacyMinioDataDirectoryName = 'miniodata';
41
+ export const legacyMongoDataDirectoryName = 'mongodata';
30
42
  export const serviceOperationLabel = 'git.zone.operation';
31
43
  export const serviceBindOperation = 'service-bind-operation';
32
44
 
@@ -36,7 +48,7 @@ export const serviceBindOperation = 'service-bind-operation';
36
48
  * refuses to touch anything that does not match it exactly.
37
49
  */
38
50
  export const serviceDataDirectoryNames: { [key in TServiceName]: string } = {
39
- mongodb: 'mongodata',
51
+ mongodb: 'nosqldbdata',
40
52
  objectstorage: 'objectstoragedata',
41
53
  elasticsearch: 'esdata',
42
54
  };
@@ -47,7 +59,7 @@ export const serviceDataDirectoryNames: { [key in TServiceName]: string } = {
47
59
  * the service ran, so its image is present locally.
48
60
  */
49
61
  export const serviceImages: { [key in TServiceName]: string } = {
50
- mongodb: 'mongo:7.0',
62
+ mongodb: noSqlDbImage,
51
63
  objectstorage: objectStorageImage,
52
64
  elasticsearch: 'elasticsearch:8.11.0',
53
65
  };
@@ -115,6 +127,25 @@ export const getLegacyMinioDataDirectory = (projectPathArg: string): string => {
115
127
  );
116
128
  };
117
129
 
130
+ /** Exact legacy MongoDB (mongod WiredTiger) path, retained as migration evidence. */
131
+ export const getLegacyMongoDataDirectory = (projectPathArg: string): string => {
132
+ return plugins.path.join(
133
+ plugins.path.resolve(projectPathArg),
134
+ '.nogit',
135
+ legacyMongoDataDirectoryName,
136
+ );
137
+ };
138
+
139
+ /** Exact legacy data path for a predecessor service. */
140
+ export const getLegacyServiceDataDirectory = (
141
+ projectPathArg: string,
142
+ serviceArg: TLegacyServiceName,
143
+ ): string => {
144
+ return serviceArg === 'minio'
145
+ ? getLegacyMinioDataDirectory(projectPathArg)
146
+ : getLegacyMongoDataDirectory(projectPathArg);
147
+ };
148
+
118
149
  /**
119
150
  * True only when `candidatePathArg` is exactly one of the canonical data
120
151
  * directories `gitzone services` creates for `projectPathArg`.
@@ -194,20 +225,21 @@ export const isValidServiceDataMarker = (markerArg: unknown): markerArg is IServ
194
225
  if (!Array.isArray(markerArg.legacyDataDirectories)) {
195
226
  return false;
196
227
  }
228
+ const seenLegacyServices = new Set<TLegacyServiceName>();
197
229
  for (const entry of markerArg.legacyDataDirectories) {
198
230
  if (
199
231
  !isPlainObject(entry) ||
200
232
  !hasOnlyKeys(entry, ['service', 'path', 'safeToPrune']) ||
201
- entry.service !== 'minio' ||
233
+ (entry.service !== 'minio' && entry.service !== 'mongo') ||
234
+ seenLegacyServices.has(entry.service) ||
202
235
  entry.safeToPrune !== false ||
203
236
  typeof entry.path !== 'string' ||
204
- plugins.path.resolve(entry.path) !== getLegacyMinioDataDirectory(projectPath)
237
+ plugins.path.resolve(entry.path) !==
238
+ getLegacyServiceDataDirectory(projectPath, entry.service)
205
239
  ) {
206
240
  return false;
207
241
  }
208
- }
209
- if (markerArg.legacyDataDirectories.length > 1) {
210
- return false;
242
+ seenLegacyServices.add(entry.service);
211
243
  }
212
244
  }
213
245
  return true;
@@ -320,6 +352,72 @@ export const recordServiceDataDirectory = async (
320
352
  );
321
353
  };
322
354
 
355
+ /**
356
+ * Record preserved predecessor data as migration evidence.
357
+ *
358
+ * Legacy entries are always `safeToPrune: false`; no GitZone command ever
359
+ * deletes a path recorded here. An invalid or foreign marker is refused rather
360
+ * than overwritten.
361
+ */
362
+ export const recordLegacyServiceDataDirectory = async (
363
+ projectPathArg: string,
364
+ serviceArg: TLegacyServiceName,
365
+ ): Promise<void> => {
366
+ const projectPath = plugins.path.resolve(projectPathArg);
367
+ await withInterProcessLock(
368
+ {
369
+ lockPath: getServiceDataMarkerLockPath(projectPath),
370
+ description: 'Service data marker',
371
+ },
372
+ async () => {
373
+ const markerPath = getServiceDataMarkerPath(projectPath);
374
+ const markerExists = await plugins.smartfs.file(markerPath).exists();
375
+ const existingMarker = await readServiceDataMarker(projectPath);
376
+ if (markerExists && !existingMarker) {
377
+ throw new Error(
378
+ `Refusing to overwrite invalid or foreign service data marker: ${markerPath}`,
379
+ );
380
+ }
381
+ const legacyPath = getLegacyServiceDataDirectory(projectPath, serviceArg);
382
+ if (
383
+ existingMarker?.legacyDataDirectories?.some(
384
+ (entry) => entry.service === serviceArg && entry.path === legacyPath,
385
+ )
386
+ ) {
387
+ return;
388
+ }
389
+ const legacyEntries: ILegacyServiceDataMarkerEntry[] = [
390
+ ...(existingMarker?.legacyDataDirectories || []).filter(
391
+ (entry) => entry.service !== serviceArg,
392
+ ),
393
+ { service: serviceArg, path: legacyPath, safeToPrune: false as const },
394
+ ].sort((entryA, entryB) => entryA.service.localeCompare(entryB.service));
395
+ await writeServiceDataMarker(projectPath, {
396
+ owner: serviceDataOwner,
397
+ kind: 'service-data',
398
+ schemaVersion: serviceDataMarkerSchemaVersion,
399
+ projectPath,
400
+ safeToPrune: true,
401
+ createdAt: existingMarker?.createdAt || new Date().toISOString(),
402
+ dataDirectories: existingMarker?.dataDirectories || [],
403
+ legacyDataDirectories: legacyEntries,
404
+ });
405
+ },
406
+ );
407
+ };
408
+
409
+ /** True when the marker records the exact legacy path as preserved evidence. */
410
+ export const markerRecordsLegacyDataDirectory = (
411
+ markerArg: IServiceDataMarker | undefined,
412
+ projectPathArg: string,
413
+ serviceArg: TLegacyServiceName,
414
+ ): boolean => {
415
+ const expectedPath = getLegacyServiceDataDirectory(projectPathArg, serviceArg);
416
+ return !!markerArg?.legacyDataDirectories?.some(
417
+ (entry) => entry.service === serviceArg && plugins.path.resolve(entry.path) === expectedPath,
418
+ );
419
+ };
420
+
323
421
  /**
324
422
  * Labels applied to every container `gitzone services` creates.
325
423
  *
@@ -375,6 +473,49 @@ export const isLegacyMinioContainerLabels = (labelsArg: {
375
473
  );
376
474
  };
377
475
 
476
+ /**
477
+ * A container created by an older GitZone release for the `mongodb` service.
478
+ *
479
+ * Its GitZone labels are exactly the canonical set, except that the data path
480
+ * is the legacy mongod directory. It is migration evidence, never an active
481
+ * NoSQLDB service container and never a prune candidate.
482
+ */
483
+ export const isLegacyMongoContainerLabels = (labelsArg: {
484
+ [key: string]: string;
485
+ }): boolean => {
486
+ const projectPath = labelsArg['git.zone.project-path'];
487
+ if (
488
+ labelsArg['git.zone.tool'] !== serviceToolLabel ||
489
+ labelsArg['git.zone.service'] !== 'mongodb' ||
490
+ typeof projectPath !== 'string' ||
491
+ !plugins.path.isAbsolute(projectPath)
492
+ ) {
493
+ return false;
494
+ }
495
+ return hasExactServiceContainerLabels(
496
+ labelsArg,
497
+ getLegacyMongoContainerLabels(projectPath),
498
+ );
499
+ };
500
+
501
+ /** The exact label envelope older releases put on `<project>-mongodb`. */
502
+ export const getLegacyMongoContainerLabels = (
503
+ projectPathArg: string,
504
+ ): { [key: string]: string } => {
505
+ return getServiceContainerLabels({
506
+ projectPath: projectPathArg,
507
+ service: 'mongodb',
508
+ dataPath: getLegacyMongoDataDirectory(projectPathArg),
509
+ });
510
+ };
511
+
512
+ /** Any predecessor-provider container: preserved evidence, never pruned. */
513
+ export const isLegacyServiceContainerLabels = (labelsArg: {
514
+ [key: string]: string;
515
+ }): boolean => {
516
+ return isLegacyMinioContainerLabels(labelsArg) || isLegacyMongoContainerLabels(labelsArg);
517
+ };
518
+
378
519
  /** Transient bind-operation containers are owned by their invocation, not by prune. */
379
520
  export const isServiceOperationHelperLabels = (labelsArg: {
380
521
  [key: string]: string;