@git.zone/cli 1.17.5 → 1.18.1

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.
@@ -26,6 +26,9 @@ export class ServiceManager {
26
26
  // Load or create configuration
27
27
  await this.config.loadOrCreate();
28
28
  logger.log('info', `📋 Project: ${this.config.getConfig().PROJECT_NAME}`);
29
+
30
+ // Validate and update ports if needed
31
+ await this.config.validateAndUpdatePorts();
29
32
  }
30
33
 
31
34
  /**
@@ -49,10 +52,42 @@ export class ServiceManager {
49
52
  break;
50
53
 
51
54
  case 'stopped':
52
- if (await this.docker.start(containers.mongo)) {
53
- logger.log('ok', ' Started ✓');
55
+ // Check if port mapping matches config
56
+ const mongoPortMappings = await this.docker.getPortMappings(containers.mongo);
57
+ if (mongoPortMappings && mongoPortMappings['27017'] !== config.MONGODB_PORT) {
58
+ logger.log('note', ' Port configuration changed, recreating container...');
59
+ await this.docker.remove(containers.mongo, true);
60
+ // Fall through to create new container
61
+ const success = await this.docker.run({
62
+ name: containers.mongo,
63
+ image: 'mongo:7.0',
64
+ ports: {
65
+ [`0.0.0.0:${config.MONGODB_PORT}`]: '27017'
66
+ },
67
+ volumes: {
68
+ [directories.mongo]: '/data/db'
69
+ },
70
+ environment: {
71
+ MONGO_INITDB_ROOT_USERNAME: config.MONGODB_USER,
72
+ MONGO_INITDB_ROOT_PASSWORD: config.MONGODB_PASS,
73
+ MONGO_INITDB_DATABASE: config.MONGODB_NAME
74
+ },
75
+ restart: 'unless-stopped',
76
+ command: '--bind_ip_all'
77
+ });
78
+
79
+ if (success) {
80
+ logger.log('ok', ' Recreated with new port ✓');
81
+ } else {
82
+ logger.log('error', ' Failed to recreate container');
83
+ }
54
84
  } else {
55
- logger.log('error', ' Failed to start');
85
+ // Ports match, just start the container
86
+ if (await this.docker.start(containers.mongo)) {
87
+ logger.log('ok', ' Started ✓');
88
+ } else {
89
+ logger.log('error', ' Failed to start');
90
+ }
56
91
  }
57
92
  break;
58
93
 
@@ -116,10 +151,60 @@ export class ServiceManager {
116
151
  break;
117
152
 
118
153
  case 'stopped':
119
- if (await this.docker.start(containers.minio)) {
120
- logger.log('ok', ' Started ✓');
154
+ // Check if port mapping matches config
155
+ const minioPortMappings = await this.docker.getPortMappings(containers.minio);
156
+ if (minioPortMappings &&
157
+ (minioPortMappings['9000'] !== config.S3_PORT ||
158
+ minioPortMappings['9001'] !== config.S3_CONSOLE_PORT)) {
159
+ logger.log('note', ' Port configuration changed, recreating container...');
160
+ await this.docker.remove(containers.minio, true);
161
+ // Fall through to create new container
162
+ const success = await this.docker.run({
163
+ name: containers.minio,
164
+ image: 'minio/minio',
165
+ ports: {
166
+ [config.S3_PORT]: '9000',
167
+ [config.S3_CONSOLE_PORT]: '9001'
168
+ },
169
+ volumes: {
170
+ [directories.minio]: '/data'
171
+ },
172
+ environment: {
173
+ MINIO_ROOT_USER: config.S3_ACCESSKEY,
174
+ MINIO_ROOT_PASSWORD: config.S3_SECRETKEY
175
+ },
176
+ restart: 'unless-stopped',
177
+ command: 'server /data --console-address ":9001"'
178
+ });
179
+
180
+ if (success) {
181
+ logger.log('ok', ' Recreated with new ports ✓');
182
+
183
+ // Wait for MinIO to be ready
184
+ await plugins.smartdelay.delayFor(3000);
185
+
186
+ // Create default bucket
187
+ await this.docker.exec(
188
+ containers.minio,
189
+ `mc alias set local http://localhost:9000 ${config.S3_ACCESSKEY} ${config.S3_SECRETKEY}`
190
+ );
191
+
192
+ await this.docker.exec(
193
+ containers.minio,
194
+ `mc mb local/${config.S3_BUCKET}`
195
+ );
196
+
197
+ logger.log('ok', ` Bucket '${config.S3_BUCKET}' created ✓`);
198
+ } else {
199
+ logger.log('error', ' Failed to recreate container');
200
+ }
121
201
  } else {
122
- logger.log('error', ' Failed to start');
202
+ // Ports match, just start the container
203
+ if (await this.docker.start(containers.minio)) {
204
+ logger.log('ok', ' Started ✓');
205
+ } else {
206
+ logger.log('error', ' Failed to start');
207
+ }
123
208
  }
124
209
  break;
125
210
 
@@ -233,6 +318,7 @@ export class ServiceManager {
233
318
  case 'running':
234
319
  logger.log('ok', '📦 MongoDB: 🟢 Running');
235
320
  logger.log('info', ` ├─ Container: ${containers.mongo}`);
321
+ logger.log('info', ` ├─ Port: ${config.MONGODB_PORT}`);
236
322
  logger.log('info', ` ├─ Connection: ${this.config.getMongoConnectionString()}`);
237
323
 
238
324
  // Show Compass connection string
@@ -242,10 +328,19 @@ export class ServiceManager {
242
328
  break;
243
329
  case 'stopped':
244
330
  logger.log('note', '📦 MongoDB: 🟡 Stopped');
245
- logger.log('info', ` └─ Container: ${containers.mongo}`);
331
+ logger.log('info', ` ├─ Container: ${containers.mongo}`);
332
+ logger.log('info', ` └─ Port: ${config.MONGODB_PORT}`);
246
333
  break;
247
334
  case 'not_exists':
248
335
  logger.log('info', '📦 MongoDB: ⚪ Not installed');
336
+ // Check port availability
337
+ const mongoPort = parseInt(config.MONGODB_PORT);
338
+ const mongoAvailable = await helpers.isPortAvailable(mongoPort);
339
+ if (!mongoAvailable) {
340
+ logger.log('error', ` └─ ⚠️ Port ${mongoPort} is in use by another process`);
341
+ } else {
342
+ logger.log('info', ` └─ Port ${mongoPort} is available`);
343
+ }
249
344
  break;
250
345
  }
251
346
 
@@ -261,10 +356,33 @@ export class ServiceManager {
261
356
  break;
262
357
  case 'stopped':
263
358
  logger.log('note', '📦 S3/MinIO: 🟡 Stopped');
264
- logger.log('info', ` └─ Container: ${containers.minio}`);
359
+ logger.log('info', ` ├─ Container: ${containers.minio}`);
360
+ logger.log('info', ` ├─ API Port: ${config.S3_PORT}`);
361
+ logger.log('info', ` └─ Console Port: ${config.S3_CONSOLE_PORT}`);
265
362
  break;
266
363
  case 'not_exists':
267
364
  logger.log('info', '📦 S3/MinIO: ⚪ Not installed');
365
+ // Check port availability
366
+ const s3Port = parseInt(config.S3_PORT);
367
+ const s3ConsolePort = parseInt(config.S3_CONSOLE_PORT);
368
+ const s3Available = await helpers.isPortAvailable(s3Port);
369
+ const consoleAvailable = await helpers.isPortAvailable(s3ConsolePort);
370
+
371
+ if (!s3Available || !consoleAvailable) {
372
+ if (!s3Available) {
373
+ logger.log('error', ` ├─ ⚠️ API Port ${s3Port} is in use`);
374
+ } else {
375
+ logger.log('info', ` ├─ API Port ${s3Port} is available`);
376
+ }
377
+ if (!consoleAvailable) {
378
+ logger.log('error', ` └─ ⚠️ Console Port ${s3ConsolePort} is in use`);
379
+ } else {
380
+ logger.log('info', ` └─ Console Port ${s3ConsolePort} is available`);
381
+ }
382
+ } else {
383
+ logger.log('info', ` ├─ API Port ${s3Port} is available`);
384
+ logger.log('info', ` └─ Console Port ${s3ConsolePort} is available`);
385
+ }
268
386
  break;
269
387
  }
270
388
  }
@@ -422,4 +540,44 @@ export class ServiceManager {
422
540
  logger.log('note', ' No data to clean');
423
541
  }
424
542
  }
543
+
544
+ /**
545
+ * Reconfigure services with new ports
546
+ */
547
+ public async reconfigure(): Promise<void> {
548
+ helpers.printHeader('Reconfiguring Services');
549
+
550
+ const containers = this.config.getContainerNames();
551
+
552
+ // Stop existing containers
553
+ logger.log('note', '🛑 Stopping existing containers...');
554
+
555
+ if (await this.docker.exists(containers.mongo)) {
556
+ await this.docker.stop(containers.mongo);
557
+ logger.log('ok', ' MongoDB stopped ✓');
558
+ }
559
+
560
+ if (await this.docker.exists(containers.minio)) {
561
+ await this.docker.stop(containers.minio);
562
+ logger.log('ok', ' S3/MinIO stopped ✓');
563
+ }
564
+
565
+ // Reconfigure ports
566
+ await this.config.reconfigurePorts();
567
+
568
+ // Ask if user wants to restart services
569
+ const smartinteract = new plugins.smartinteract.SmartInteract();
570
+ const response = await smartinteract.askQuestion({
571
+ name: 'restart',
572
+ type: 'confirm',
573
+ message: 'Do you want to start services with new ports?',
574
+ default: true
575
+ });
576
+
577
+ if (response.value) {
578
+ console.log();
579
+ await this.startMongoDB();
580
+ await this.startMinIO();
581
+ }
582
+ }
425
583
  }
@@ -48,6 +48,10 @@ export const run = async (argvArg: any) => {
48
48
  await handleClean(serviceManager);
49
49
  break;
50
50
 
51
+ case 'reconfigure':
52
+ await serviceManager.reconfigure();
53
+ break;
54
+
51
55
  case 'help':
52
56
  default:
53
57
  showHelp();
@@ -195,6 +199,7 @@ function showHelp() {
195
199
  logger.log('info', ' config Show current configuration');
196
200
  logger.log('info', ' compass Show MongoDB Compass connection string');
197
201
  logger.log('info', ' logs [service] Show logs (mongo|s3|all) [lines]');
202
+ logger.log('info', ' reconfigure Reassign ports and restart services');
198
203
  logger.log('info', ' remove Remove all containers');
199
204
  logger.log('info', ' clean Remove all containers and data ⚠️');
200
205
  logger.log('info', ' help Show this help message');