feat(mod_services): Add global service registry and global commands for managing project containers
This commit is contained in:
@@ -2,16 +2,19 @@ import * as plugins from './mod.plugins.js';
|
||||
import * as helpers from './helpers.js';
|
||||
import { ServiceConfiguration } from './classes.serviceconfiguration.js';
|
||||
import { DockerContainer } from './classes.dockercontainer.js';
|
||||
import { GlobalRegistry } from './classes.globalregistry.js';
|
||||
import { logger } from '../gitzone.logging.js';
|
||||
|
||||
export class ServiceManager {
|
||||
private config: ServiceConfiguration;
|
||||
private docker: DockerContainer;
|
||||
private enabledServices: string[] | null = null;
|
||||
private globalRegistry: GlobalRegistry;
|
||||
|
||||
constructor() {
|
||||
this.config = new ServiceConfiguration();
|
||||
this.docker = new DockerContainer();
|
||||
this.globalRegistry = GlobalRegistry.getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,6 +110,31 @@ export class ServiceManager {
|
||||
return this.enabledServices.includes(service);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this project with the global registry
|
||||
*/
|
||||
private async registerWithGlobalRegistry(): Promise<void> {
|
||||
const config = this.config.getConfig();
|
||||
const containers = this.config.getContainerNames();
|
||||
|
||||
await this.globalRegistry.registerProject({
|
||||
projectPath: process.cwd(),
|
||||
projectName: config.PROJECT_NAME,
|
||||
containers: {
|
||||
mongo: containers.mongo,
|
||||
minio: containers.minio,
|
||||
elasticsearch: containers.elasticsearch,
|
||||
},
|
||||
ports: {
|
||||
mongo: parseInt(config.MONGODB_PORT),
|
||||
s3: parseInt(config.S3_PORT),
|
||||
s3Console: parseInt(config.S3_CONSOLE_PORT),
|
||||
elasticsearch: parseInt(config.ELASTICSEARCH_PORT),
|
||||
},
|
||||
enabledServices: this.enabledServices || ['mongodb', 'minio', 'elasticsearch'],
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Start all enabled services
|
||||
*/
|
||||
@@ -127,6 +155,9 @@ export class ServiceManager {
|
||||
await this.startElasticsearch();
|
||||
first = false;
|
||||
}
|
||||
|
||||
// Register with global registry
|
||||
await this.registerWithGlobalRegistry();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -808,6 +839,15 @@ export class ServiceManager {
|
||||
if (!removed) {
|
||||
logger.log('note', ' No containers to remove');
|
||||
}
|
||||
|
||||
// Check if all containers are gone, then unregister from global registry
|
||||
const mongoExists = await this.docker.exists(containers.mongo);
|
||||
const minioExists = await this.docker.exists(containers.minio);
|
||||
const esExists = await this.docker.exists(containers.elasticsearch);
|
||||
|
||||
if (!mongoExists && !minioExists && !esExists) {
|
||||
await this.globalRegistry.unregisterProject(process.cwd());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user