@nestjs-mod/docker-compose
Version:
Docker Compose is a tool for defining and running multi-container applications. It is the key to unlocking a streamlined and efficient development and deployment experience. (Generator docker-compose.yml for https://docs.docker.com/compose)
121 lines • 7.86 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.DockerComposeNats = void 0;
const common_1 = require("@nestjs-mod/common");
const case_anything_1 = require("case-anything");
const docker_compose_module_1 = require("../../docker-compose.module");
const docker_compose_utils_1 = require("../../docker-compose.utils");
const docker_compose_nats_constants_1 = require("./docker-compose-nats.constants");
const docker_compose_nats_settings_1 = require("./docker-compose-nats.settings");
exports.DockerComposeNats = (0, common_1.createNestModule)({
moduleName: docker_compose_nats_constants_1.DOCKER_COMPOSE_NATS_MODULE_NAME,
moduleDescription: 'NATS is an open source, lightweight and high-performance messaging system. It is ideal for distributed systems and supports modern cloud architectures and pub-sub, request-reply and queuing models. (Generator for nats in docker-compose.yml for https://www.npmjs.com/package/@nestjs-mod/docker-compose)',
globalEnvironmentsOptions: { skipValidation: true },
globalConfigurationOptions: { skipValidation: true },
staticConfigurationModel: docker_compose_nats_settings_1.DockerComposeNatsConfiguration,
staticEnvironmentsModel: docker_compose_nats_settings_1.DockerComposeNatsEnvironments,
wrapForRootAsync: (asyncModuleOptions) => {
if (!asyncModuleOptions) {
asyncModuleOptions = {};
}
if (asyncModuleOptions.staticConfiguration?.featureName) {
const FomatterClass = (0, common_1.getFeatureDotEnvPropertyNameFormatter)(asyncModuleOptions.staticConfiguration.featureName);
Object.assign(asyncModuleOptions, {
environmentsOptions: {
propertyNameFormatters: [new FomatterClass()],
name: asyncModuleOptions.staticConfiguration?.featureName,
},
});
}
return { asyncModuleOptions };
},
preWrapApplication: async ({ project, modules, current }) => {
if (!modules[common_1.NestModuleCategory.infrastructure]) {
modules[common_1.NestModuleCategory.infrastructure] = [];
}
const dockerComposeNatsModule = (0, common_1.createNestModule)({
project,
moduleName: docker_compose_nats_constants_1.DOCKER_COMPOSE_NATS_MODULE_NAME,
moduleDescription: 'NATS is an open source, lightweight and high-performance messaging system. It is ideal for distributed systems and supports modern cloud architectures and pub-sub, request-reply and queuing models. (Generator for nats in docker-compose.yml for https://www.npmjs.com/package/@nestjs-mod/docker-compose)',
moduleCategory: common_1.NestModuleCategory.infrastructure,
globalEnvironmentsOptions: { name: project?.name, skipValidation: (0, common_1.isInfrastructureMode)() },
globalConfigurationOptions: { name: project?.name, skipValidation: (0, common_1.isInfrastructureMode)() },
staticConfigurationModel: docker_compose_nats_settings_1.DockerComposeNatsConfiguration,
staticEnvironmentsModel: docker_compose_nats_settings_1.DockerComposeNatsEnvironments,
wrapForRootAsync: (asyncModuleOptions) => {
if (!asyncModuleOptions) {
asyncModuleOptions = {};
}
if (asyncModuleOptions.staticConfiguration?.featureName) {
const FomatterClass = (0, common_1.getFeatureDotEnvPropertyNameFormatter)(asyncModuleOptions.staticConfiguration.featureName);
Object.assign(asyncModuleOptions, {
environmentsOptions: {
propertyNameFormatters: [new FomatterClass()],
name: asyncModuleOptions.staticConfiguration?.featureName,
},
});
}
return { asyncModuleOptions };
},
imports: ({ contextName, project, staticConfiguration, staticEnvironments }) => {
const networks = (project?.name
? staticConfiguration?.networks?.map((n) => ({
...n,
name: (0, case_anything_1.kebabCase)([project?.name, n.name, 'network'].filter(Boolean).join('-')),
})) ?? [{ name: (0, case_anything_1.kebabCase)(`${project?.name}-network`), driver: 'bridge' }]
: staticConfiguration?.networks) ?? [];
if (networks?.length === 0) {
networks.push({ name: 'default-network', driver: 'bridge' });
}
const networkNames = networks?.map((n) => n.name);
const serviceName = (0, docker_compose_utils_1.getDockerComposeServiceName)(project?.name, docker_compose_utils_1.DockerComposeServiceType.Nats);
return [
common_1.ProjectUtils.forFeature({
featureModuleName: docker_compose_nats_constants_1.DOCKER_COMPOSE_NATS_MODULE_NAME,
contextName,
}),
docker_compose_module_1.DockerCompose.forFeature({
contextName,
featureModuleName: (0, case_anything_1.constantCase)(serviceName),
featureConfiguration: {
services: {
[serviceName]: {
image: staticConfiguration?.image,
container_name: serviceName,
volumes: [`${serviceName}-volume:/bitnami/nats/data`],
ports: [
`${staticConfiguration?.externalHttpPort}:8222`,
`${staticConfiguration?.externalClientPort}:4222`,
],
networks: networkNames,
environment: {
...(staticEnvironments?.natsEnableAuth
? { NATS_ENABLE_AUTH: staticEnvironments?.natsEnableAuth }
: {}),
...(staticEnvironments?.natsUsername ? { NATS_USERNAME: staticEnvironments?.natsUsername } : {}),
...(staticEnvironments?.natsPassword ? { NATS_PASSWORD: staticEnvironments?.natsPassword } : {}),
...(staticConfiguration.extraArgs ? { NATS_EXTRA_ARGS: staticConfiguration.extraArgs } : {}),
},
keysOfEnvironmentsWithStaticValue: [
'featureName',
'image',
'extraArgs',
'networks',
],
tty: true,
restart: 'always',
},
},
networks: networks.reduce((all, cur) => ({ ...all, [cur.name]: { driver: cur.driver } }), {}),
volumes: {
[`${serviceName}-volume`]: { name: `${serviceName}-volume` },
},
},
}),
];
},
}).DockerComposeNats;
modules[common_1.NestModuleCategory.infrastructure].push(dockerComposeNatsModule.forRootAsync(current.asyncModuleOptions));
},
}).DockerComposeNats;
//# sourceMappingURL=docker-compose-nats.module.js.map
;