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)

180 lines 12.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DockerComposeMaildev = 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_maildev_constants_1 = require("./docker-compose-maildev.constants"); const docker_compose_maildev_settings_1 = require("./docker-compose-maildev.settings"); exports.DockerComposeMaildev = (0, common_1.createNestModule)({ moduleName: docker_compose_maildev_constants_1.DOCKER_COMPOSE_MAILDEV_MODULE_NAME, moduleDescription: 'MailDev is a simple way to test your projects generated email during development, with an easy to use web interface that runs on your machine. (Generator for maildev in docker-compose.yml for https://www.npmjs.com/package/@nestjs-mod/docker-compose)', globalEnvironmentsOptions: { skipValidation: true }, globalConfigurationOptions: { skipValidation: true }, staticConfigurationModel: docker_compose_maildev_settings_1.DockerComposeMaildevConfiguration, staticEnvironmentsModel: docker_compose_maildev_settings_1.DockerComposeMaildevEnvironments, 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 dockerComposeMaildevModule = (0, common_1.createNestModule)({ project, moduleName: docker_compose_maildev_constants_1.DOCKER_COMPOSE_MAILDEV_MODULE_NAME, moduleDescription: 'MailDev is a simple way to test your projects generated email during development, with an easy to use web interface that runs on your machine. (Generator for maildev 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_maildev_settings_1.DockerComposeMaildevConfiguration, staticEnvironmentsModel: docker_compose_maildev_settings_1.DockerComposeMaildevEnvironments, 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.Maildev); return [ common_1.ProjectUtils.forFeature({ featureModuleName: docker_compose_maildev_constants_1.DOCKER_COMPOSE_MAILDEV_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?.smtpPort}:${staticConfiguration?.smtpPort}`, `${staticConfiguration?.webPort}:${staticConfiguration?.webPort}`, ], networks: networkNames, environment: { ...(staticConfiguration.smtpPort ? { MAILDEV_SMTP_PORT: staticConfiguration.smtpPort } : {}), ...(staticConfiguration.webPort ? { MAILDEV_WEB_PORT: staticConfiguration.webPort } : {}), ...(staticEnvironments.maildevMailDirectory ? { MAILDEV_MAIL_DIRECTORY: staticEnvironments.maildevMailDirectory } : {}), ...(staticEnvironments.maildevHttps ? { MAILDEV_HTTPS: staticEnvironments.maildevHttps } : {}), ...(staticEnvironments.maildevHttpsKey ? { MAILDEV_HTTPS_KEY: staticEnvironments.maildevHttpsKey } : {}), ...(staticEnvironments.maildevHttpsCert ? { MAILDEV_HTTPS_CERT: staticEnvironments.maildevHttpsCert } : {}), ...(staticEnvironments.maildevIp ? { MAILDEV_IP: staticEnvironments.maildevIp } : {}), ...(staticEnvironments.maildevOutgoingHost ? { MAILDEV_OUTGOING_HOST: staticEnvironments.maildevOutgoingHost } : {}), ...(staticEnvironments.maildevOutgoingPort ? { MAILDEV_OUTGOING_PORT: staticEnvironments.maildevOutgoingPort } : {}), ...(staticEnvironments.maildevOutgoingPass ? { MAILDEV_OUTGOING_PASS: staticEnvironments.maildevOutgoingPass } : {}), ...(staticEnvironments.maildevOutgoingSecure ? { MAILDEV_OUTGOING_SECURE: staticEnvironments.maildevOutgoingSecure } : {}), ...(staticEnvironments.maildevAutoRelay ? { MAILDEV_AUTO_RELAY: staticEnvironments.maildevAutoRelay } : {}), ...(staticEnvironments.maildevAutoRelayRules ? { MAILDEV_AUTO_RELAY_RULES: staticEnvironments.maildevAutoRelayRules } : {}), ...(staticEnvironments.maildevIncomingUser ? { MAILDEV_INCOMING_USER: staticEnvironments.maildevIncomingUser } : {}), ...(staticEnvironments.maildevIncomingPass ? { MAILDEV_INCOMING_PASS: staticEnvironments.maildevIncomingPass } : {}), ...(staticEnvironments.maildevIncomingSecure ? { MAILDEV_INCOMING_SECURE: staticEnvironments.maildevIncomingSecure } : {}), ...(staticEnvironments.maildevIncomingCert ? { MAILDEV_INCOMING_CERT: staticEnvironments.maildevIncomingCert } : {}), ...(staticEnvironments.maildevIncomingKey ? { MAILDEV_INCOMING_KEY: staticEnvironments.maildevIncomingKey } : {}), ...(staticEnvironments.maildevWebIp ? { MAILDEV_WEB_IP: staticEnvironments.maildevWebIp } : {}), ...(staticEnvironments.maildevWebUser ? { MAILDEV_WEB_USER: staticEnvironments.maildevWebUser } : {}), ...(staticEnvironments.maildevWebPass ? { MAILDEV_WEB_PASS: staticEnvironments.maildevWebPass } : {}), ...(staticEnvironments.maildevBasePathname ? { MAILDEV_BASE_PATHNAME: staticEnvironments.maildevBasePathname } : {}), ...(staticEnvironments.maildevDisableWeb ? { MAILDEV_DISABLE_WEB: staticEnvironments.maildevDisableWeb } : {}), ...(staticEnvironments.maildevHideExtensions ? { MAILDEV_HIDE_EXTENSIONS: staticEnvironments.maildevHideExtensions } : {}), }, keysOfEnvironmentsWithStaticValue: [ 'featureName', 'image', 'networks', 'smtpPort', 'webPort', ], healthcheck: { test: 'wget -O - http://localhost:${MAILDEV_WEB_PORT}${MAILDEV_BASE_PATHNAME}/healthz || exit 1', interval: '10s', timeout: '5s', retries: 5, }, tty: true, restart: 'always', }, }, networks: networks.reduce((all, cur) => ({ ...all, [cur.name]: { driver: cur.driver } }), {}), }, }), ]; }, }).DockerComposeMaildev; modules[common_1.NestModuleCategory.infrastructure].push(dockerComposeMaildevModule.forRootAsync(current.asyncModuleOptions)); }, }).DockerComposeMaildev; //# sourceMappingURL=docker-compose-maildev.module.js.map