UNPKG

@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)

142 lines 8.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DockerComposeSso = 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_sso_configuration_1 = require("./docker-compose-sso.configuration"); const docker_compose_sso_constants_1 = require("./docker-compose-sso.constants"); const docker_compose_sso_environments_1 = require("./docker-compose-sso.environments"); exports.DockerComposeSso = (0, common_1.createNestModule)({ moduleName: docker_compose_sso_constants_1.DOCKER_COMPOSE_SSO_MODULE_NAME, moduleDescription: 'Single Sign-On on NestJS and Angular with webhooks and social authorization. (Generator for https://github.com/nestjs-mod/nestjs-mod-sso in docker-compose.yml for https://www.npmjs.com/package/@nestjs-mod/docker-compose)', globalEnvironmentsOptions: { skipValidation: true }, globalConfigurationOptions: { skipValidation: true }, staticConfigurationModel: docker_compose_sso_configuration_1.DockerComposeSsoConfiguration, staticEnvironmentsModel: docker_compose_sso_environments_1.DockerComposeSsoEnvironments, 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 dockerComposeSsoModule = (0, common_1.createNestModule)({ project, moduleName: docker_compose_sso_constants_1.DOCKER_COMPOSE_SSO_MODULE_NAME, moduleDescription: 'Single Sign-On on NestJS and Angular with webhooks and social authorization. (Generator for https://github.com/nestjs-mod/nestjs-mod-sso 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_sso_configuration_1.DockerComposeSsoConfiguration, staticEnvironmentsModel: docker_compose_sso_environments_1.DockerComposeSsoEnvironments, 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.SingleSignOn); return [ common_1.ProjectUtils.forFeature({ featureModuleName: docker_compose_sso_constants_1.DOCKER_COMPOSE_SSO_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, ports: [`${staticConfiguration?.externalClientPort}:${staticEnvironments?.singleSignOnPort}`], networks: networkNames, excludeContainerNameFromEnvironmentName: true, environment: { ...Object.entries({ ...staticEnvironments, ...staticConfiguration }).reduce((all, [key, value]) => ({ ...all, [(0, case_anything_1.constantCase)(key)]: value, }), {}), }, keysOfEnvironmentsWithStaticValue: [ 'featureName', 'image', 'networks', 'dependsOnServiceNames', 'env', ], tty: true, restart: 'always', depends_on: Object.entries(staticConfiguration.dependsOnServiceNames || {}) .map(([serviceName, condition]) => { const keys = Object.keys(process.env); if (serviceName) { for (const key of keys) { serviceName = String(serviceName).replace(new RegExp(`%${key}%`, 'ig'), process.env[key] || ''); } } // todo: fix type // eslint-disable-next-line @typescript-eslint/no-explicit-any return [serviceName, condition]; }) .map(([serviceName, condition]) => ({ [(0, docker_compose_utils_1.getDockerComposeServiceName)(project?.name, serviceName)]: { condition }, })) .reduce((all, cur) => ({ ...all, ...cur }), {}), }, }, networks: networks.reduce((all, cur) => ({ ...all, [cur.name]: { driver: cur.driver } }), {}), }, }), ]; }, }).DockerComposeSso; modules[common_1.NestModuleCategory.infrastructure].push(dockerComposeSsoModule.forRootAsync(current.asyncModuleOptions)); }, }).DockerComposeSso; //# sourceMappingURL=docker-compose-sso.module.js.map