@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
|
@@ -109,11 +109,16 @@ export interface IServiceConfig {
|
|
|
109
109
|
MONGODB_PASS: string;
|
|
110
110
|
MONGODB_URL: string;
|
|
111
111
|
/**
|
|
112
|
-
* When false,
|
|
113
|
-
* loopback only. Opt-in, for runtimes whose `node:crypto` cannot
|
|
114
|
-
* SCRAM handshake (notably Deno). Defaults to true.
|
|
112
|
+
* When false, the NoSQLDB engine runs without authentication. It is always
|
|
113
|
+
* published on loopback only. Opt-in, for runtimes whose `node:crypto` cannot
|
|
114
|
+
* complete a SCRAM handshake (notably Deno). Defaults to true.
|
|
115
115
|
*/
|
|
116
116
|
MONGODB_AUTH_ENABLED: boolean;
|
|
117
|
+
/**
|
|
118
|
+
* Password of the NoSQLDB engine's management UI. Generated per project,
|
|
119
|
+
* never printed, and never published: the UI port stays inside the container.
|
|
120
|
+
*/
|
|
121
|
+
MONGODB_ADMIN_PASSWORD: string;
|
|
117
122
|
S3_HOST: string;
|
|
118
123
|
S3_PORT: string;
|
|
119
124
|
S3_UI_PORT: string;
|
|
@@ -139,6 +144,7 @@ const runtimeStringFields: Array<keyof IServiceConfig> = [
|
|
|
139
144
|
'MONGODB_USER',
|
|
140
145
|
'MONGODB_PASS',
|
|
141
146
|
'MONGODB_URL',
|
|
147
|
+
'MONGODB_ADMIN_PASSWORD',
|
|
142
148
|
'S3_HOST',
|
|
143
149
|
'S3_PORT',
|
|
144
150
|
'S3_UI_PORT',
|
|
@@ -226,8 +232,9 @@ export class ServiceConfiguration {
|
|
|
226
232
|
// value, so a fresh checkout reproduces the declared setup.
|
|
227
233
|
await this.applyDeclaredServiceOptions();
|
|
228
234
|
|
|
229
|
-
// Only
|
|
230
|
-
// configuration is authoritative and is reconciled on
|
|
235
|
+
// Only Elasticsearch retains legacy port synchronization. NoSQLDB and
|
|
236
|
+
// ObjectStorage configuration is authoritative and is reconciled on their
|
|
237
|
+
// guarded start paths.
|
|
231
238
|
await this.syncPortsFromDocker();
|
|
232
239
|
|
|
233
240
|
return this.config;
|
|
@@ -272,7 +279,7 @@ export class ServiceConfiguration {
|
|
|
272
279
|
}
|
|
273
280
|
|
|
274
281
|
/**
|
|
275
|
-
* Whether
|
|
282
|
+
* Whether the NoSQLDB engine should enforce authentication. Defaults to true; only an
|
|
276
283
|
* explicit `false` in `.nogit/env.json` disables it.
|
|
277
284
|
*/
|
|
278
285
|
public isMongoAuthEnabled(): boolean {
|
|
@@ -283,7 +290,7 @@ export class ServiceConfiguration {
|
|
|
283
290
|
* Build MONGODB_URL from the current fields.
|
|
284
291
|
*
|
|
285
292
|
* Credentials are omitted entirely when auth is disabled, so the stored URL
|
|
286
|
-
* never advertises a username that
|
|
293
|
+
* never advertises a username that the engine would not accept.
|
|
287
294
|
*/
|
|
288
295
|
private buildMongoUrl(): string {
|
|
289
296
|
const credentials = this.isMongoAuthEnabled()
|
|
@@ -302,7 +309,7 @@ export class ServiceConfiguration {
|
|
|
302
309
|
}
|
|
303
310
|
|
|
304
311
|
/**
|
|
305
|
-
* Refuse an unauthenticated
|
|
312
|
+
* Refuse an unauthenticated database that would be reachable off-host.
|
|
306
313
|
*
|
|
307
314
|
* Disabling auth is only defensible while the database is bound to loopback.
|
|
308
315
|
* Rather than trusting the operator to keep MONGODB_HOST local, this fails
|
|
@@ -321,6 +328,32 @@ export class ServiceConfiguration {
|
|
|
321
328
|
}
|
|
322
329
|
}
|
|
323
330
|
|
|
331
|
+
/** Reject NoSQLDB's prohibited defaults and credential reuse before Docker mutation. */
|
|
332
|
+
public assertNoSqlDbCredentialsAreSafe(): void {
|
|
333
|
+
const config = this.config;
|
|
334
|
+
if (
|
|
335
|
+
typeof config.MONGODB_ADMIN_PASSWORD !== 'string' ||
|
|
336
|
+
config.MONGODB_ADMIN_PASSWORD.length === 0
|
|
337
|
+
) {
|
|
338
|
+
throw new Error('MONGODB_ADMIN_PASSWORD must be a non-empty string in .nogit/env.json.');
|
|
339
|
+
}
|
|
340
|
+
if (config.MONGODB_ADMIN_PASSWORD === 'admin') {
|
|
341
|
+
throw new Error(
|
|
342
|
+
'NoSQLDB refuses the default admin password. Set a non-default MONGODB_ADMIN_PASSWORD in .nogit/env.json.',
|
|
343
|
+
);
|
|
344
|
+
}
|
|
345
|
+
if (config.MONGODB_ADMIN_PASSWORD === config.MONGODB_PASS) {
|
|
346
|
+
throw new Error(
|
|
347
|
+
'MONGODB_ADMIN_PASSWORD must be separate from MONGODB_PASS in .nogit/env.json.',
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
if (this.isMongoAuthEnabled() && config.MONGODB_PASS === 'admin') {
|
|
351
|
+
throw new Error(
|
|
352
|
+
'NoSQLDB refuses the default root password. Set a non-default MONGODB_PASS in .nogit/env.json.',
|
|
353
|
+
);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
324
357
|
/** Reject ObjectStorage's prohibited defaults and credential reuse before Docker mutation. */
|
|
325
358
|
public assertObjectStorageCredentialsAreSafe(): void {
|
|
326
359
|
const config = this.config;
|
|
@@ -480,6 +513,7 @@ export class ServiceConfiguration {
|
|
|
480
513
|
MONGODB_PASS: mongoPass,
|
|
481
514
|
MONGODB_URL: `mongodb://${mongoUser}:${mongoPass}@${mongoHost}:${mongoPortStr}/${mongoName}?authSource=admin`,
|
|
482
515
|
MONGODB_AUTH_ENABLED: true,
|
|
516
|
+
MONGODB_ADMIN_PASSWORD: plugins.crypto.randomBytes(24).toString('base64url'),
|
|
483
517
|
S3_HOST: s3Host,
|
|
484
518
|
S3_PORT: s3PortStr,
|
|
485
519
|
S3_UI_PORT: s3UiPort.toString(),
|
|
@@ -683,7 +717,8 @@ export class ServiceConfiguration {
|
|
|
683
717
|
*/
|
|
684
718
|
public getContainerNames() {
|
|
685
719
|
return {
|
|
686
|
-
|
|
720
|
+
nosqldb: `${this.config.PROJECT_NAME}-nosqldb`,
|
|
721
|
+
legacyMongo: `${this.config.PROJECT_NAME}-mongodb`,
|
|
687
722
|
objectstorage: `${this.config.PROJECT_NAME}-objectstorage`,
|
|
688
723
|
legacyMinio: `${this.config.PROJECT_NAME}-minio`,
|
|
689
724
|
elasticsearch: `${this.config.PROJECT_NAME}-elasticsearch`
|
|
@@ -698,7 +733,7 @@ export class ServiceConfiguration {
|
|
|
698
733
|
*/
|
|
699
734
|
public getDataDirectories() {
|
|
700
735
|
return {
|
|
701
|
-
|
|
736
|
+
nosqldb: getServiceDataDirectory(process.cwd(), 'mongodb'),
|
|
702
737
|
objectstorage: getServiceDataDirectory(process.cwd(), 'objectstorage'),
|
|
703
738
|
elasticsearch: getServiceDataDirectory(process.cwd(), 'elasticsearch')
|
|
704
739
|
};
|
|
@@ -711,22 +746,6 @@ export class ServiceConfiguration {
|
|
|
711
746
|
const containers = this.getContainerNames();
|
|
712
747
|
let updated = false;
|
|
713
748
|
|
|
714
|
-
// Check MongoDB container
|
|
715
|
-
const mongoStatus = await this.docker.getStatus(containers.mongo);
|
|
716
|
-
if (mongoStatus !== 'not_exists') {
|
|
717
|
-
const portMappings = await this.docker.getPortMappings(containers.mongo);
|
|
718
|
-
// legacy containers map 27017; replica-set containers map port:port
|
|
719
|
-
const dockerPort =
|
|
720
|
-
portMappings && (portMappings['27017'] ?? Object.values(portMappings)[0]);
|
|
721
|
-
if (dockerPort) {
|
|
722
|
-
if (this.config.MONGODB_PORT !== dockerPort) {
|
|
723
|
-
logger.log('note', `📍 Syncing MongoDB port from Docker: ${dockerPort}`);
|
|
724
|
-
this.config.MONGODB_PORT = dockerPort;
|
|
725
|
-
updated = true;
|
|
726
|
-
}
|
|
727
|
-
}
|
|
728
|
-
}
|
|
729
|
-
|
|
730
749
|
// Check Elasticsearch container
|
|
731
750
|
const esStatus = await this.docker.getStatus(containers.elasticsearch);
|
|
732
751
|
if (esStatus !== 'not_exists') {
|
|
@@ -755,22 +774,12 @@ export class ServiceConfiguration {
|
|
|
755
774
|
let updated = false;
|
|
756
775
|
const containers = this.getContainerNames();
|
|
757
776
|
|
|
758
|
-
// Check if
|
|
759
|
-
|
|
777
|
+
// Check if the container exists - if it does, its port is fine. NoSQLDB and
|
|
778
|
+
// ObjectStorage ports are validated on their guarded start paths, after
|
|
779
|
+
// legacy state has been handled: a legacy MongoDB container legitimately
|
|
780
|
+
// holds MONGODB_PORT until its data has been migrated.
|
|
760
781
|
const esExists = await this.docker.exists(containers.elasticsearch);
|
|
761
782
|
|
|
762
|
-
// Only check port availability if containers don't exist
|
|
763
|
-
if (!mongoExists) {
|
|
764
|
-
const mongoPort = parseInt(this.config.MONGODB_PORT);
|
|
765
|
-
if (!(await helpers.isPortAvailable(mongoPort))) {
|
|
766
|
-
logger.log('note', `⚠️ MongoDB port ${mongoPort} is in use, finding new port...`);
|
|
767
|
-
const newPort = await helpers.getRandomAvailablePort();
|
|
768
|
-
this.config.MONGODB_PORT = newPort.toString();
|
|
769
|
-
logger.log('ok', `✅ New MongoDB port: ${newPort}`);
|
|
770
|
-
updated = true;
|
|
771
|
-
}
|
|
772
|
-
}
|
|
773
|
-
|
|
774
783
|
if (!esExists) {
|
|
775
784
|
const esPort = parseInt(this.config.ELASTICSEARCH_PORT);
|
|
776
785
|
if (!(await helpers.isPortAvailable(esPort))) {
|
|
@@ -790,6 +799,21 @@ export class ServiceConfiguration {
|
|
|
790
799
|
return updated;
|
|
791
800
|
}
|
|
792
801
|
|
|
802
|
+
/** Validate the NoSQLDB host port only after legacy/conflict checks pass. */
|
|
803
|
+
public async validateNoSqlDbPort(): Promise<boolean> {
|
|
804
|
+
const mongoPort = parseInt(this.config.MONGODB_PORT);
|
|
805
|
+
if (await helpers.isPortAvailable(mongoPort)) {
|
|
806
|
+
return false;
|
|
807
|
+
}
|
|
808
|
+
logger.log('note', `⚠️ NoSQLDB port ${mongoPort} is in use, finding new port...`);
|
|
809
|
+
const newPort = await helpers.getRandomAvailablePort();
|
|
810
|
+
this.config.MONGODB_PORT = newPort.toString();
|
|
811
|
+
logger.log('ok', `✅ New NoSQLDB port: ${newPort}`);
|
|
812
|
+
this.updateDerivedFields();
|
|
813
|
+
await this.saveConfig();
|
|
814
|
+
return true;
|
|
815
|
+
}
|
|
816
|
+
|
|
793
817
|
/** Validate ObjectStorage host ports only after legacy/conflict checks pass. */
|
|
794
818
|
public async validateObjectStoragePorts(): Promise<boolean> {
|
|
795
819
|
let updated = false;
|
|
@@ -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: '
|
|
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:
|
|
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) !==
|
|
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;
|