1.20.1 • Published 6 months ago

@nestjs-mod/docker-compose v1.20.1

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

@nestjs-mod/docker-compose

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)

NPM version monthly downloads Telegram Discord

Installation

npm i --save @nestjs-mod/docker-compose

Modules

LinkCategoryDescription
DockerComposeinfrastructureDocker 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)
DockerComposeAuthorizerinfrastructureAuthorizer is an open-source authentication and authorization solution for your applications. Bring your database and have complete control over the user information. You can self-host authorizer instances and connect to supported databases. (Generator for https://authorizer.dev in docker-compose.yml for https://www.npmjs.com/package/@nestjs-mod/docker-compose)
DockerComposeMaildevinfrastructureMailDev 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)
DockerComposeMinioinfrastructureMinIO is a high-performance, S3 compatible object storage. (Generator for minio in docker-compose.yml for https://www.npmjs.com/package/@nestjs-mod/docker-compose)
DockerComposeNatsinfrastructureNATS 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)
DockerComposeNginxinfrastructureNginx is a web server that can also be used as a reverse proxy, load balancer, mail proxy and HTTP cache. (Generator for nginx in docker-compose.yml for https://www.npmjs.com/package/@nestjs-mod/docker-compose)
DockerComposePostgreSQLinfrastructurePostgreSQL (Postgres) is an open source object-relational database known for reliability and data integrity. ACID-compliant, it supports foreign keys, joins, views, triggers and stored procedures. (Generator for databases in docker-compose.yml for https://github.com/nestjs-mod/nestjs-mod-contrib/tree/master/libs/infrastructure/docker-compose)
DockerComposeRedisinfrastructureThe open-source, in-memory data store used by millions of developers as a cache, vector database, document database, streaming engine, and message broker. (Generator for redis in docker-compose.yml for https://www.npmjs.com/package/@nestjs-mod/docker-compose)
DockerComposeSsoinfrastructureSingle 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)

Modules descriptions

DockerCompose

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)

Use in NestJS-mod

An example you can see the full example here https://github.com/nestjs-mod/nestjs-mod-contrib/tree/master/apps/example-prisma-flyway or https://github.com/nestjs-mod/nestjs-mod-contrib/tree/master/apps/example-prisma.

import { PACKAGE_JSON_FILE, ProjectUtils, bootstrapNestApplication } from '@nestjs-mod/common';
import { DOCKER_COMPOSE_FILE, DockerCompose } from '@nestjs-mod/docker-compose';
import { join } from 'path';

export const flywayPrismaFeatureName = 'flyway-prisma';

const rootFolder = join(__dirname, '..', '..', '..');
const appFolder = join(rootFolder, 'apps', 'example-prisma-flyway');

bootstrapNestApplication({
  modules: {
    system: [
      ProjectUtils.forRoot({
        staticConfiguration: {
          applicationPackageJsonFile: join(
            appFolder
            PACKAGE_JSON_FILE
          ),
          packageJsonFile: join(rootFolder, PACKAGE_JSON_FILE),
          envFile: join(rootFolder, '.env'),
        },
      }),
    ],
    infrastructure: [
      DockerCompose.forRoot({
        configuration: {
          dockerComposeFileVersion: '3',
          dockerComposeFile: join(appFolder, DOCKER_COMPOSE_FILE),
        },
      }),
    ],
  },
});

After connecting the module to the application and npm run build and starting generation of documentation through npm run docs:infrastructure, you will have new files and scripts to run.

New scripts mostly package.json

{
  "scripts": {
    "_____docker-compose infra_____": "_____docker-compose infra_____",
    "docker-compose:start:example-prisma-flyway": "export COMPOSE_INTERACTIVE_NO_CLI=1 && docker compose -f ./apps/example-prisma-flyway/docker-compose.yml --compatibility up -d",
    "docker-compose:stop:example-prisma-flyway": "export COMPOSE_INTERACTIVE_NO_CLI=1 && docker compose -f ./apps/example-prisma-flyway/docker-compose.yml down"
  },
  "scriptsComments": {
    "docker-compose:start:example-prisma-flyway": [
      "Running the docker-compose infrastructure for example-prisma-flyway"
    ],
    "docker-compose:stop:example-prisma-flyway": [
      "Stopping the docker-compose infrastructure for example-prisma-flyway"
    ]
  }
}

Empty docker-compose file for application docker-compose.yml with real credenionals and add it to .gitignore file

# Do not modify this file, it is generated using the DockerCompose module included with NestJS-mod.
version: '3'

Empty docker-compose file for application docker-compose-example.yml with fake credenionals

# Do not modify this file, it is generated using the DockerCompose module included with NestJS-mod.
version: '3'

Shared providers

ManualDockerComposeFeatures

Configuration

KeyDescriptionConstraintsDefaultValue
dockerComposeFileMain file for docker-compose, the Compose specification establishes a standard for the definition of multi-container platform-agnostic applicationsisNotEmpty (dockerComposeFile should not be empty)--
prodDockerComposeFileMain file for prod docker-compose, the Compose specification establishes a standard for the definition of multi-container platform-agnostic applicationsoptional--
exampleDockerComposeFileExample file for docker-compose, the Compose specification establishes a standard for the definition of multi-container platform-agnostic applicationsoptional--
prodDockerComposeEnvFileDotenv file for prod docker-compose fileoptional--
dockerComposeFileVersionDocker-compose file version. @see https://docs.docker.com/compose/compose-file/compose-versioningisNotEmpty (dockerComposeFileVersion should not be empty)3-
beforeSaveExampleDockerComposeFileBefore save file for example docker-composeoptional--
beforeSaveDockerComposeFileBefore save main file for docker-composeoptional--
beforeSaveProdDockerComposeFileBefore save main file for prod docker-composeoptional--
beforeSaveDockerComposeEnvFileMethod before save dotenv file for docker-compose fileoptional--
beforeSaveProdDockerComposeEnvFileMethod before save dotenv file for prod docker-compose fileoptional--

Feature configuration

KeyDescriptionConstraintsDefaultValue
versionThe top-level version property is defined by the Compose Specification for backward compatibility. It is only informative. @see https://github.com/compose-spec/compose-spec/blob/master/04-version-and-name.mdoptional--
servicesA service is an abstract definition of a computing resource within an application which can be scaled or replaced independently from other components. @see https://github.com/compose-spec/compose-spec/blob/master/05-services.mdoptional--
networksNetworks are the layer that allow services to communicate with each other. @see https://github.com/compose-spec/compose-spec/blob/master/06-networks.mdoptional--
volumesVolumes are persistent data stores implemented by the container engine. @see https://github.com/compose-spec/compose-spec/blob/master/07-volumes.mdoptional--
secretsSecrets are a flavor of Configs focusing on sensitive data, with specific constraint for this usage. @see https://github.com/compose-spec/compose-spec/blob/master/09-secrets.mdoptional--
configsConfigs allow services to adapt their behaviour without the need to rebuild a Docker image. @see https://github.com/compose-spec/compose-spec/blob/master/08-configs.mdoptional--

Modules that use feature configuration

Feature module name: AUTHORIZER
KeyDescriptionConstraintsDefaultValue
versionThe top-level version property is defined by the Compose Specification for backward compatibility. It is only informative. @see https://github.com/compose-spec/compose-spec/blob/master/04-version-and-name.mdoptional--
servicesA service is an abstract definition of a computing resource within an application which can be scaled or replaced independently from other components. @see https://github.com/compose-spec/compose-spec/blob/master/05-services.mdoptional-{"authorizer":{"image":"lakhansamani/authorizer:1.3.8","container_name":"authorizer","ports":["8080:8080"],"networks":["default-network"],"environment":{"DATABASE_NAME":"authorizer","PORT":8080,"COOKIE_NAME":"authorizer","DISABLE_PLAYGROUND":true,"ACCESS_TOKEN_EXPIRY_TIME":"30m","IMAGE":"lakhansamani/authorizer:1.3.8","EXTERNAL_CLIENT_PORT":8080,"ENV":"production","RESET_PASSWORD_URL":"/reset-password","ROLES":"user,admin","DEFAULT_ROLES":"user","JWT_ROLE_CLAIM":"role","ORGANIZATION_NAME":"Authorizer","ORGANIZATION_LOGO":"Authorizer Logo","COUCHBASE_BUCKET":"authorizer","COUCHBASE_BUCKET_RAM_QUOTA":1000,"COUCHBASE_SCOPE":"_default"},"keysOfEnvironmentsWithStaticValue":["featureName","image","networks","dependsOnServiceNames","env"],"tty":true,"restart":"always","depends_on":{}}}
networksNetworks are the layer that allow services to communicate with each other. @see https://github.com/compose-spec/compose-spec/blob/master/06-networks.mdoptional-{"default-network":{"driver":"bridge"}}
volumesVolumes are persistent data stores implemented by the container engine. @see https://github.com/compose-spec/compose-spec/blob/master/07-volumes.mdoptional--
secretsSecrets are a flavor of Configs focusing on sensitive data, with specific constraint for this usage. @see https://github.com/compose-spec/compose-spec/blob/master/09-secrets.mdoptional--
configsConfigs allow services to adapt their behaviour without the need to rebuild a Docker image. @see https://github.com/compose-spec/compose-spec/blob/master/08-configs.mdoptional--

Modules that use feature configuration

Feature module name: MAILDEV
KeyDescriptionConstraintsDefaultValue
versionThe top-level version property is defined by the Compose Specification for backward compatibility. It is only informative. @see https://github.com/compose-spec/compose-spec/blob/master/04-version-and-name.mdoptional--
servicesA service is an abstract definition of a computing resource within an application which can be scaled or replaced independently from other components. @see https://github.com/compose-spec/compose-spec/blob/master/05-services.mdoptional-{"maildev":{"image":"maildev/maildev:2.2.1","container_name":"maildev","ports":["1025:1025","1080:1080"],"networks":["default-network"],"environment":{"MAILDEV_SMTP_PORT":1025,"MAILDEV_WEB_PORT":1080},"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"}}
networksNetworks are the layer that allow services to communicate with each other. @see https://github.com/compose-spec/compose-spec/blob/master/06-networks.mdoptional-{"default-network":{"driver":"bridge"}}
volumesVolumes are persistent data stores implemented by the container engine. @see https://github.com/compose-spec/compose-spec/blob/master/07-volumes.mdoptional--
secretsSecrets are a flavor of Configs focusing on sensitive data, with specific constraint for this usage. @see https://github.com/compose-spec/compose-spec/blob/master/09-secrets.mdoptional--
configsConfigs allow services to adapt their behaviour without the need to rebuild a Docker image. @see https://github.com/compose-spec/compose-spec/blob/master/08-configs.mdoptional--

Modules that use feature configuration

Feature module name: POSTGRE_SQL
KeyDescriptionConstraintsDefaultValue
versionThe top-level version property is defined by the Compose Specification for backward compatibility. It is only informative. @see https://github.com/compose-spec/compose-spec/blob/master/04-version-and-name.mdoptional--
servicesA service is an abstract definition of a computing resource within an application which can be scaled or replaced independently from other components. @see https://github.com/compose-spec/compose-spec/blob/master/05-services.mdoptional-{"postgre-sql":{"image":"bitnami/postgresql:15.5.0","container_name":"postgre-sql","volumes":["postgre-sql-volume:/bitnami/postgresql"],"ports":["5432:5432"],"networks":["default-network"],"healthcheck":{"test":["CMD-SHELL","pg_isready -U postgres"],"interval":"5s","timeout":"5s","retries":5},"tty":true,"restart":"always"}}
networksNetworks are the layer that allow services to communicate with each other. @see https://github.com/compose-spec/compose-spec/blob/master/06-networks.mdoptional-{"default-network":{"driver":"bridge"}}
volumesVolumes are persistent data stores implemented by the container engine. @see https://github.com/compose-spec/compose-spec/blob/master/07-volumes.mdoptional-{"postgre-sql-volume":{"name":"postgre-sql-volume"}}
secretsSecrets are a flavor of Configs focusing on sensitive data, with specific constraint for this usage. @see https://github.com/compose-spec/compose-spec/blob/master/09-secrets.mdoptional--
configsConfigs allow services to adapt their behaviour without the need to rebuild a Docker image. @see https://github.com/compose-spec/compose-spec/blob/master/08-configs.mdoptional--

Modules that use feature configuration

Feature module name: MINIO
KeyDescriptionConstraintsDefaultValue
versionThe top-level version property is defined by the Compose Specification for backward compatibility. It is only informative. @see https://github.com/compose-spec/compose-spec/blob/master/04-version-and-name.mdoptional--
servicesA service is an abstract definition of a computing resource within an application which can be scaled or replaced independently from other components. @see https://github.com/compose-spec/compose-spec/blob/master/05-services.mdoptional-{"minio":{"image":"bitnami/minio:2024.2.9","container_name":"minio","volumes":["minio-volume:/bitnami/minio/data"],"ports":["9000:9000","9001:9001"],"networks":["default-network"],"environment":{},"keysOfEnvironmentsWithStaticValue":["featureName","image","networks","nginxBucketsLocations","nginxConfigContent","nginxConfigFolder","nginxLogsFolder"],"healthcheck":{"test":["CMD-SHELL","mc","ready","local"],"interval":"5s","timeout":"5s","retries":5},"tty":true,"restart":"always"}}
networksNetworks are the layer that allow services to communicate with each other. @see https://github.com/compose-spec/compose-spec/blob/master/06-networks.mdoptional-{"default-network":{"driver":"bridge"}}
volumesVolumes are persistent data stores implemented by the container engine. @see https://github.com/compose-spec/compose-spec/blob/master/07-volumes.mdoptional-{"minio-volume":{"name":"minio-volume"}}
secretsSecrets are a flavor of Configs focusing on sensitive data, with specific constraint for this usage. @see https://github.com/compose-spec/compose-spec/blob/master/09-secrets.mdoptional--
configsConfigs allow services to adapt their behaviour without the need to rebuild a Docker image. @see https://github.com/compose-spec/compose-spec/blob/master/08-configs.mdoptional--

Modules that use feature configuration

Feature module name: NGINX
KeyDescriptionConstraintsDefaultValue
versionThe top-level version property is defined by the Compose Specification for backward compatibility. It is only informative. @see https://github.com/compose-spec/compose-spec/blob/master/04-version-and-name.mdoptional--
servicesA service is an abstract definition of a computing resource within an application which can be scaled or replaced independently from other components. @see https://github.com/compose-spec/compose-spec/blob/master/05-services.mdoptional-{"nginx":{"image":"nginx:alpine","container_name":"nginx","volumes":[],"ports":[],"networks":["default-network"],"tty":true,"restart":"always","depends_on":{}}}
networksNetworks are the layer that allow services to communicate with each other. @see https://github.com/compose-spec/compose-spec/blob/master/06-networks.mdoptional-{"default-network":{"driver":"bridge"}}
volumesVolumes are persistent data stores implemented by the container engine. @see https://github.com/compose-spec/compose-spec/blob/master/07-volumes.mdoptional--
secretsSecrets are a flavor of Configs focusing on sensitive data, with specific constraint for this usage. @see https://github.com/compose-spec/compose-spec/blob/master/09-secrets.mdoptional--
configsConfigs allow services to adapt their behaviour without the need to rebuild a Docker image. @see https://github.com/compose-spec/compose-spec/blob/master/08-configs.mdoptional--

Modules that use feature configuration

Feature module name: NATS
KeyDescriptionConstraintsDefaultValue
versionThe top-level version property is defined by the Compose Specification for backward compatibility. It is only informative. @see https://github.com/compose-spec/compose-spec/blob/master/04-version-and-name.mdoptional--
servicesA service is an abstract definition of a computing resource within an application which can be scaled or replaced independently from other components. @see https://github.com/compose-spec/compose-spec/blob/master/05-services.mdoptional-{"nats":{"image":"bitnami/nats:2.10.5","container_name":"nats","volumes":["nats-volume:/bitnami/nats/data"],"ports":["8222:8222","4222:4222"],"networks":["default-network"],"environment":{"NATS_EXTRA_ARGS":"-js"},"keysOfEnvironmentsWithStaticValue":["featureName","image","extraArgs","networks"],"tty":true,"restart":"always"}}
networksNetworks are the layer that allow services to communicate with each other. @see https://github.com/compose-spec/compose-spec/blob/master/06-networks.mdoptional-{"default-network":{"driver":"bridge"}}
volumesVolumes are persistent data stores implemented by the container engine. @see https://github.com/compose-spec/compose-spec/blob/master/07-volumes.mdoptional-{"nats-volume":{"name":"nats-volume"}}
secretsSecrets are a flavor of Configs focusing on sensitive data, with specific constraint for this usage. @see https://github.com/compose-spec/compose-spec/blob/master/09-secrets.mdoptional--
configsConfigs allow services to adapt their behaviour without the need to rebuild a Docker image. @see https://github.com/compose-spec/compose-spec/blob/master/08-configs.mdoptional--

Back to Top


DockerComposeAuthorizer

Authorizer is an open-source authentication and authorization solution for your applications. Bring your database and have complete control over the user information. You can self-host authorizer instances and connect to supported databases. (Generator for https://authorizer.dev in docker-compose.yml for https://www.npmjs.com/package/@nestjs-mod/docker-compose)

Use in NestJS-mod

An example of using Maildev, you can see the full example here https://github.com/nestjs-mod/nestjs-mod-contrib/tree/master/apps/example-authorizer/INFRASTRUCTURE.MD.

process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';

import { AuthorizerModule } from '@nestjs-mod/authorizer';
import {
  DefaultNestApplicationInitializer,
  DefaultNestApplicationListener,
  InfrastructureMarkdownReportGenerator,
  PACKAGE_JSON_FILE,
  ProjectUtils,
  bootstrapNestApplication,
  isInfrastructureMode,
} from '@nestjs-mod/common';
import { DOCKER_COMPOSE_FILE, DockerCompose, DockerComposeAuthorizer, DockerComposePostgreSQL } from '@nestjs-mod/docker-compose';
import { join } from 'path';
import { adminSecret } from './app/app.constants';
import { AppModule } from './app/app.module';

const rootFolder = join(__dirname, '..', '..', '..');
const appFolder = join(rootFolder, 'apps', 'example-authorizer');

bootstrapNestApplication({
  globalConfigurationOptions: { debug: true },
  globalEnvironmentsOptions: { debug: true },
  modules: {
    system: [
      ProjectUtils.forRoot({
        staticConfiguration: {
          applicationPackageJsonFile: join(__dirname, '..', '..', '..', 'apps/example-authorizer', PACKAGE_JSON_FILE),
          packageJsonFile: join(rootFolder, PACKAGE_JSON_FILE),
          envFile: join(rootFolder, 'apps', 'example-authorizer', '.env'),
        },
      }),
      DefaultNestApplicationInitializer.forRoot(),
      DefaultNestApplicationListener.forRoot({
        staticConfiguration: {
          // When running in infrastructure mode, the backend server does not start.
          mode: isInfrastructureMode() ? 'silent' : 'listen',
        },
      }),
    ],
    feature: [
      AuthorizerModule.forRootAsync({
        environments: {
          authorizerURL: 'http://localhost:8080',
          redirectURL: 'http://localhost:3000'
        }
      }),
      AppModule.forRoot()
    ],
    infrastructure: [
      InfrastructureMarkdownReportGenerator.forRoot({
        staticConfiguration: {
          markdownFile: join(appFolder, 'INFRASTRUCTURE.MD'),
          skipEmptySettings: true,
          style: 'pretty',
        },
      }),
      DockerCompose.forRoot({
        configuration: {
          dockerComposeFileVersion: '3',
          dockerComposeFile: join(appFolder, DOCKER_COMPOSE_FILE),
        },
      }),
      DockerComposePostgreSQL.forRoot({
        staticEnvironments: {
          rootDatabaseUrl: 'postgres://postgres:postgres_password@localhost:5432/postgres?schema=public'
        }
      }),
      DockerComposeAuthorizer.forRoot({
        staticEnvironments: {
          databaseType: 'postgres',
          databaseUrl: 'postgres://postgres:postgres_password@example-authorizer-postgre-sql:5432/postgres',
          databaseName: 'authorizer',
          adminSecret
        }
      }),
    ],
  },
});

After connecting the module to the application and npm run manual:prepare and starting generation of documentation through npm run docs:infrastructure:example-authorizer, you will have new files and scripts to run.

New scripts mostly package.json

Add database options to docker-compose file for application docker-compose.yml with real credenionals and add it to .gitignore file

# Do not modify this file, it is generated using the DockerCompose module included with NestJS-mod.
version: "3"
services:
  example-authorizer-postgre-sql:
    image: "bitnami/postgresql:15.5.0"
    container_name: "example-authorizer-postgre-sql"
    volumes:
      - "example-authorizer-postgre-sql-volume:/bitnami/postgresql"
    ports:
      - "5432:5432"
    networks:
      - "example-authorizer-network"
    healthcheck:
      test:
        - "CMD-SHELL"
        - "pg_isready -U postgres"
      interval: "5s"
      timeout: "5s"
      retries: 5
    tty: true
    restart: "always"
    environment:
      POSTGRESQL_USERNAME: "${EXAMPLE_AUTHORIZER_POSTGRE_SQL_POSTGRESQL_USERNAME}"
      POSTGRESQL_PASSWORD: "${EXAMPLE_AUTHORIZER_POSTGRE_SQL_POSTGRESQL_PASSWORD}"
      POSTGRESQL_DATABASE: "${EXAMPLE_AUTHORIZER_POSTGRE_SQL_POSTGRESQL_DATABASE}"
  example-authorizer-authorizer:
    image: "lakhansamani/authorizer:1.3.8"
    container_name: "example-authorizer-authorizer"
    ports:
      - "8080:8080"
    networks:
      - "example-authorizer-network"
    environment:
      DATABASE_TYPE: "${EXAMPLE_AUTHORIZER_AUTHORIZER_DATABASE_TYPE}"
      DATABASE_URL: "${EXAMPLE_AUTHORIZER_AUTHORIZER_DATABASE_URL}"
      DATABASE_NAME: "${EXAMPLE_AUTHORIZER_AUTHORIZER_DATABASE_NAME}"
      ADMIN_SECRET: "${EXAMPLE_AUTHORIZER_AUTHORIZER_ADMIN_SECRET}"
      PORT: "${EXAMPLE_AUTHORIZER_AUTHORIZER_PORT}"
      COOKIE_NAME: "${EXAMPLE_AUTHORIZER_AUTHORIZER_COOKIE_NAME}"
      DISABLE_PLAYGROUND: "${EXAMPLE_AUTHORIZER_AUTHORIZER_DISABLE_PLAYGROUND}"
      ACCESS_TOKEN_EXPIRY_TIME: "${EXAMPLE_AUTHORIZER_AUTHORIZER_ACCESS_TOKEN_EXPIRY_TIME}"
      IMAGE: "${EXAMPLE_AUTHORIZER_AUTHORIZER_IMAGE}"
      EXTERNAL_CLIENT_PORT: "${EXAMPLE_AUTHORIZER_AUTHORIZER_EXTERNAL_CLIENT_PORT}"
      ENV: "${EXAMPLE_AUTHORIZER_AUTHORIZER_ENV}"
      RESET_PASSWORD_URL: "${EXAMPLE_AUTHORIZER_AUTHORIZER_RESET_PASSWORD_URL}"
      ROLES: "${EXAMPLE_AUTHORIZER_AUTHORIZER_ROLES}"
      DEFAULT_ROLES: "${EXAMPLE_AUTHORIZER_AUTHORIZER_DEFAULT_ROLES}"
      JWT_ROLE_CLAIM: "${EXAMPLE_AUTHORIZER_AUTHORIZER_JWT_ROLE_CLAIM}"
      ORGANIZATION_NAME: "${EXAMPLE_AUTHORIZER_AUTHORIZER_ORGANIZATION_NAME}"
      ORGANIZATION_LOGO: "${EXAMPLE_AUTHORIZER_AUTHORIZER_ORGANIZATION_LOGO}"
      COUCHBASE_BUCKET: "${EXAMPLE_AUTHORIZER_AUTHORIZER_COUCHBASE_BUCKET}"
      COUCHBASE_BUCKET_RAM_QUOTA: "${EXAMPLE_AUTHORIZER_AUTHORIZER_COUCHBASE_BUCKET_RAM_QUOTA}"
      COUCHBASE_SCOPE: "${EXAMPLE_AUTHORIZER_AUTHORIZER_COUCHBASE_SCOPE}"
    tty: true
    restart: "always"
    depends_on: {}
networks:
  example-authorizer-network:
    driver: "bridge"
volumes:
  example-authorizer-postgre-sql-volume:
    name: "example-authorizer-postgre-sql-volume"

New environment variable

# example-authorizer-postgre-sql (generated)
EXAMPLE_AUTHORIZER_POSTGRE_SQL_POSTGRESQL_USERNAME=postgres
EXAMPLE_AUTHORIZER_POSTGRE_SQL_POSTGRESQL_PASSWORD=postgres_password
EXAMPLE_AUTHORIZER_POSTGRE_SQL_POSTGRESQL_DATABASE=postgres
# example-authorizer-authorizer (generated)
EXAMPLE_AUTHORIZER_AUTHORIZER_DATABASE_TYPE=postgres
EXAMPLE_AUTHORIZER_AUTHORIZER_DATABASE_URL=postgres://postgres:postgres_password@example-authorizer-postgre-sql:5432/postgres
EXAMPLE_AUTHORIZER_AUTHORIZER_DATABASE_NAME=authorizer
EXAMPLE_AUTHORIZER_AUTHORIZER_ADMIN_SECRET=adminSecret
EXAMPLE_AUTHORIZER_AUTHORIZER_PORT=8080
EXAMPLE_AUTHORIZER_AUTHORIZER_COOKIE_NAME=authorizer
EXAMPLE_AUTHORIZER_AUTHORIZER_DISABLE_PLAYGROUND=true
EXAMPLE_AUTHORIZER_AUTHORIZER_ACCESS_TOKEN_EXPIRY_TIME=30m
EXAMPLE_AUTHORIZER_AUTHORIZER_IMAGE=
EXAMPLE_AUTHORIZER_AUTHORIZER_EXTERNAL_CLIENT_PORT=8080
EXAMPLE_AUTHORIZER_AUTHORIZER_ENV=
EXAMPLE_AUTHORIZER_AUTHORIZER_RESET_PASSWORD_URL=/reset-password
EXAMPLE_AUTHORIZER_AUTHORIZER_ROLES=user,admin
EXAMPLE_AUTHORIZER_AUTHORIZER_DEFAULT_ROLES=user
EXAMPLE_AUTHORIZER_AUTHORIZER_JWT_ROLE_CLAIM=role
EXAMPLE_AUTHORIZER_AUTHORIZER_ORGANIZATION_NAME=Authorizer
EXAMPLE_AUTHORIZER_AUTHORIZER_ORGANIZATION_LOGO='Authorizer Logo'
EXAMPLE_AUTHORIZER_AUTHORIZER_COUCHBASE_BUCKET=authorizer
EXAMPLE_AUTHORIZER_AUTHORIZER_COUCHBASE_BUCKET_RAM_QUOTA=1000
EXAMPLE_AUTHORIZER_AUTHORIZER_COUCHBASE_SCOPE=_default
# EXAMPLE_AUTHORIZER_AUTHORIZER_DATABASE_URL (generated)
LOCALHOST_EXAMPLE_AUTHORIZER_AUTHORIZER_DATABASE_URL=postgres://postgres:postgres_password@localhost:5432/postgres

When launched in the infrastructure documentation generation mode, the module creates an .env file with a list of all required variables, as well as an example example.env, where you can enter example variable values.

Static environments

KeyDescriptionSourcesConstraintsDefaultValue
adminSecretSuper admin secret used to access the master dataobj['adminSecret'], process.env['ADMIN_SECRET']isNotEmpty (adminSecret should not be empty)--
databaseTypeWhich database you are using. Supported database types are postgres, mysql, planetscale, sqlite, sqlserver, mongodb, arangodb, yugabyte, mariadb, cassandradb, scylladb, couchbase, dynamodbobj['databaseType'], process.env['DATABASE_TYPE']isNotEmpty (databaseType should not be empty)--
databaseUrlDatabase connection string. In case of cluster url eg. for cassandra db, you can use comma separated IPsobj['databaseUrl'], process.env['DATABASE_URL']isNotEmpty (databaseUrl should not be empty)--
databaseNameName of database to connect to. This is useful in case of arangodb and mongodb. If not set, default value will be usedobj['databaseName'], process.env['DATABASE_NAME']optionalauthorizerauthorizer
redisUrlRedis URL where sessions can be persisted false sessions will be stored in memoryobj['redisUrl'], process.env['REDIS_URL']optional--
databasePortPort on which database connection should be made. This is used when DATABASE_URL is not mentioned. At the moment supported by cassandradbobj['databasePort'], process.env['DATABASE_PORT']optional--
databaseHostHost/IP on which database connection should be made. This is used when DATABASE_URL is not mentioned. At the moment supported by cassandradb typeobj['databaseHost'], process.env['DATABASE_HOST']optional--
databaseUsernameUsername for the database access with permission to create tables and records. At the moment supported by cassandradb, scylladb typeobj['databaseUsername'], process.env['DATABASE_USERNAME']optional--
databasePasswordPassword for the database access with permission to create tables and records. At the moment supported by cassandradb, scylladb typeobj['databasePassword'], process.env['DATABASE_PASSWORD']optional--
databaseCertBase64 encoded certificate string used to make SSL connection. At the moment supported by cassandradb,scylladb typeobj['databaseCert'], process.env['DATABASE_CERT']optional--
databaseCertKeyBase64 encoded key string used to make SSL connection. At the moment supported by cassandradb,scylladb typeobj['databaseCertKey'], process.env['DATABASE_CERT_KEY']optional--
databaseCaCertBase64 encoded CA certificate string used to make SSL connection. At the moment supported by cassandradb, scylladb typeobj['databaseCaCert'], process.env['DATABASE_CA_CERT']optional--
portPort on which server should be runningobj['port'], process.env['PORT']optional80808080
authorizerUrlDomain name of the server, eg https://authorizer.herokuapp.comobj['authorizerUrl'], process.env['AUTHORIZER_URL']optional--
cookieNameName of cookie to be set by serverobj['cookieName'], process.env['COOKIE_NAME']optionalauthorizerauthorizer
smtpHostSMTP host is used to send email verification emails and forgot password emails false If not set email sending can failobj['smtpHost'], process.env['SMTP_HOST']optional--
smtpPortSMTP Port is used along with SMTP hostobj['smtpPort'], process.env['SMTP_PORT']optional--
smtpUsernameUsername for your smtp providerobj['smtpUsername'], process.env['SMTP_USERNAME']optional--
smtpPasswordPassword for your smt providerobj['smtpPassword'], process.env['SMTP_PASSWORD']optional--
senderEmailEmail to be used in From section while sending emailsobj['senderEmail'], process.env['SENDER_EMAIL']optional--
senderNameEmail sender name that is displayed in the inbox instead of just showing the email addressobj['senderName'], process.env['SENDER_NAME']optional--
disablePlaygroundTo disable playgroundobj['disablePlayground'], process.env['DISABLE_PLAYGROUND']optionaltruetrue
accessTokenExpiryTimeTime interval for how long access token will be expired in 1h15m15s formatobj['accessTokenExpiryTime'], process.env['ACCESS_TOKEN_EXPIRY_TIME']optional30m30m
awsAccessKeyIdAWS access key used for connecting to dynamodb. Make sure access credentials has rights for dynamodb. Used with DATABASE_TYPE=dynamodbobj['awsAccessKeyId'], process.env['AWS_ACCESS_KEY_ID']optional--
awsSecretAccessKeyAWS secret access key used for connecting to dynamodb. Make sure access credentials has rights for dynamodb. Used with DATABASE_TYPE=dynamodbobj['awsSecretAccessKey'], process.env['AWS_SECRET_ACCESS_KEY']optional--
googleClientIdOAuth Google login client idobj['googleClientId'], process.env['GOOGLE_CLIENT_ID']optional--
googleClientSecretOAuth Google login client secretobj['googleClientSecret'], process.env['GOOGLE_CLIENT_SECRET']optional--
githubClientIdOAuth Github login client idobj['githubClientId'], process.env['GITHUB_CLIENT_ID']optional--
githubClientSecretOAuth Github login client secretobj['githubClientSecret'], process.env['GITHUB_CLIENT_SECRET']optional--
facebookClientIdOAuth Facebook login client idobj['facebookClientId'], process.env['FACEBOOK_CLIENT_ID']optional--
facebookClientSecretOAuth Facebook login client secretobj['facebookClientSecret'], process.env['FACEBOOK_CLIENT_SECRET']optional--
linkedinClientIdOAuth LinkedIn login client idobj['linkedinClientId'], process.env['LINKEDIN_CLIENT_ID']optional--
linkedinClientSecretOAuth LinkedIn login client secretobj['linkedinClientSecret'], process.env['LINKEDIN_CLIENT_SECRET']optional--
appleClientIdOAuth Apple login client idobj['appleClientId'], process.env['APPLE_CLIENT_ID']optional--
appleClientSecretOAuth Apple login client secretobj['appleClientSecret'], process.env['APPLE_CLIENT_SECRET']optional--
twitterClientIdOAuth Twitter login client idobj['twitterClientId'], process.env['TWITTER_CLIENT_ID']optional--
twitterClientSecretOAuth Twitter login client secretobj['twitterClientSecret'], process.env['TWITTER_CLIENT_SECRET']optional--
microsoftClientIdOAuth Microsoft login client idobj['microsoftClientId'], process.env['MICROSOFT_CLIENT_ID']optional--
microsoftClientSecretOAuth Microsoft login client secretobj['microsoftClientSecret'], process.env['MICROSOFT_CLIENT_SECRET']optional--
microsoftActiveDirectoryTenantIdMicrosoft Active Directory Tenant ID obtained from azure portalobj['microsoftActiveDirectoryTenantId'], process.env['MICROSOFT_ACTIVE_DIRECTORY_TENANT_ID']optional--
smtpLocalName-obj['smtpLocalName'], process.env['SMTP_LOCAL_NAME']optional--
jwtSecret-obj['jwtSecret'], process.env['JWT_SECRET']optional--
jwtPrivateKey-obj['jwtPrivateKey'], process.env['JWT_PRIVATE_KEY']optional--
jwtPublicKey-obj['jwtPublicKey'], process.env['JWT_PUBLIC_KEY']optional--
appUrl-obj['appUrl'], process.env['APP_URL']optional--
discordClientId-obj['discordClientId'], process.env['DISCORD_CLIENT_ID']optional--
discordClientSecret-obj['discordClientSecret'], process.env['DISCORD_CLIENT_SECRET']optional--
twitchClientId-obj['twitchClientId'], process.env['TWITCH_CLIENT_ID']optional--
twitchClientSecret-obj['twitchClientSecret'], process.env['TWITCH_CLIENT_SECRET']optional--
clientId-obj['clientId'], process.env['CLIENT_ID']optional--
clientSecret-obj['clientSecret'], process.env['CLIENT_SECRET']optional--
encryptionKey-obj['encryptionKey'], process.env['ENCRYPTION_KEY']optional--
isProd-obj['isProd'], process.env['IS_PROD']optional--
allowedOrigins-obj['allowedOrigins'], process.env['ALLOWED_ORIGINS']optional--
twilioApiKey-obj['twilioApiKey'], process.env['TWILIO_API_KEY']optional--
twilioApiSecret-obj['twilioApiSecret'], process.env['TWILIO_API_SECRET']optional--
twilioAccountSid-obj['twilioAccountSid'], process.env['TWILIO_ACCOUNT_SID']optional--
twilioSender-obj['twilioSender'], process.env['TWILIO_SENDER']optional--

Static configuration

KeyDescriptionConstraintsDefaultValue
imageDocker image nameoptionallakhansamani/authorizer:1.3.8-
featureNameFeature name for generate prefix to environments keysoptional--
networksNetwork, if not set networkNames have project name and driver=bridgeoptional--
externalClientPortExternal port for sharing containeroptional8080-
dependsOnServiceNamesDepends on servicesoptional--
envWhich env you are running your server in. Supported envs production, developmentoptionalproduction-
resetPasswordUrlReset password link, that can be used to send the correct forgot password linkoptional/reset-password-
disableBasicAuthenticationUsed to explicitly disable email and password based authenticationoptional--
disableEmailVerificationUsed to disable the email verification while signing upoptional--
disableMagicLinkLoginUsed to disable the password less login upoptional--
disableLoginPageUsed to disable the default login page that comes with authorizer instance. This is helpful when user is building their custom login pageoptional--
disableSignUpUsed to disable the sign up feature. It is useful when you want to have beta release of your product and invite only limited usersoptional--
rolesComma separated list of roles that your platform supportsoptionaluser,admin-
defaultRolesComma separated list of roles that acts as Default roles which you would like to assign to users while they signup /loginoptionaluser-
protectedRolesComma separated list of roles for which signup should be disabled. Example admin roles. This roles can only assigned manually via super admin like adminUpdateProfileoptional--
jwtRoleClaimClaim key that will be part of JWT tokenoptionalrole-
organizationNameName of organization that you want on default login pageoptionalAuthorizer-
organizationLogoLogo of organization that you want on default login pageoptionalAuthorizer Logo-
customAccessTokenScriptJavascript function to add extra keys to your JWT id token. This feature is developed using otto and only supports writing function in ES5. Check the sample hereoptional--
awsRegionAWS, region id, where dynamod db tables are to be created. Used with DATABASE_TYPE=dynamodboptional--
couchbaseBucketBucket used for couchbase database. Used with DATABASE_TYPE=couchbaseoptionalauthorizer-
couchbaseBucketRamQuotaRAM Quota for the bucket used for couchbase database. It has to be numeric value only. Used with DATABASE_TYPE=couchbaseoptional1000-
couchbaseScopeScope in which bucket is created. Used with DATABASE_TYPE=couchbaseoptional_default-
test-optional--
envPath-optional--
isEmailServiceEnabled-optional--
isSmsServiceEnabled-optional--
appCookieSecure-optional--
adminCookieSecure-optional--
jwtType-optional--
jwk-optional--
disableMobileBasicAuthentication-optional--
disableRedisForEnv-optional--
disableStrongPassword-optional--
enforceMultiFactorAuthentication-optional--
disableMultiFactorAuthentication-optional--
disableTotpLogin-optional--
disableMailOtpLogin-optional--
disablePhoneVerification-optional--
defaultAuthorizeResponseType-optional--
defaultAuthorizeResponseMode-optional--

Back to Top


DockerComposeMaildev

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)

Use in NestJS-mod

An example of using Maildev, you can see the full example here https://github.com/nestjs-mod/nestjs-mod-contrib/tree/master/apps/example-maildev.

process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';

import {
  DefaultNestApplicationInitializer,
  DefaultNestApplicationListener,
  InfrastructureMarkdownReportGenerator,
  PACKAGE_JSON_FILE,
  ProjectUtils,
  bootstrapNestApplication,
  isInfrastructureMode,
} from '@nestjs-mod/common';
import { DOCKER_COMPOSE_FILE, DockerCompose, DockerComposeMaildev } from '@nestjs-mod/docker-compose';
import { join } from 'path';
import { AppModule } from './app/app.module';

const rootFolder = join(__dirname, '..', '..', '..');
const appFolder = join(rootFolder, 'apps', 'example-maildev');

bootstrapNestApplication({
  globalConfigurationOptions: { debug: true },
  globalEnvironmentsOptions: { debug: true },
  modules: {
    system: [
      ProjectUtils.forRoot({
        staticConfiguration: {
          applicationPackageJsonFile: join(__dirname, '..', '..', '..', 'apps/example-maildev', PACKAGE_JSON_FILE),
          packageJsonFile: join(rootFolder, PACKAGE_JSON_FILE),
          envFile: join(rootFolder, '.env'),
        },
      }),
      DefaultNestApplicationInitializer.forRoot(),
      DefaultNestApplicationListener.forRoot({
        staticConfiguration: {
          // When running in infrastructure mode, the backend server does not start.
          mode: isInfrastructureMode() ? 'silent' : 'listen',
        },
      }),
    ],
    feature: [AppModule.forRoot()],
    infrastructure: [
      InfrastructureMarkdownReportGenerator.forRoot({
        staticConfiguration: {
          markdownFile: join(appFolder, 'INFRASTRUCTURE.MD'),
          skipEmptySettings: true,
          style: 'pretty',
        },
      }),
      DockerCompose.forRoot({
        configuration: {
          dockerComposeFileVersion: '3',
          dockerComposeFile: join(appFolder, DOCKER_COMPOSE_FILE),
        },
      }),
      DockerComposeMaildev.forRoot(),
    ],
  },
});

After connecting the module to the application and npm run build and starting generation of documentation through npm run docs:infrastructure, you will have new files and scripts to run.

New scripts mostly package.json

Add database options to docker-compose file for application docker-compose.yml with real credenionals and add it to .gitignore file

version: '3'
services:
  example-maildev-maildev:
    image: 'maildev/maildev:2.2.1'
    container_name: 'example-maildev-maildev'
    ports:
      - '1025:1025'
      - '1080:1080'
    networks:
      - 'example-maildev-network'
    environment:
      MAILDEV_SMTP_PORT: '1025'
      MAILDEV_WEB_PORT: '1080'
    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:
  example-maildev-network:
    driver: 'bridge'

New environment variable

# example-maildev-maildev (generated)
EXAMPLE_MAILDEV_MAILDEV_MAILDEV_SMTP_PORT=1025
EXAMPLE_MAILDEV_MAILDEV_MAILDEV_WEB_PORT=1080

When launched in the infrastructure documentation generation mode, the module creates an .env file with a list of all required variables, as well as an example example.env, where you can enter example variable values.

Static environments

KeyDescriptionSourcesConstraintsDefaultValue
maildevMailDirectoryDirectory for persisting mail.obj['maildevMailDirectory'], process.env['MAILDEV_MAIL_DIRECTORY']optional--
maildevHttpsSwitch from http to https protocol.obj['maildevHttps'], process.env['MAILDEV_HTTPS']optional--
maildevHttpsKeyThe file path to the ssl private key.obj['maildevHttpsKey'], process.env['MAILDEV_HTTPS_KEY']optional--
maildevHttpsCertThe file path to the ssl cert file.obj['maildevHttpsCert'], process.env['MAILDEV_HTTPS_CERT']optional--
maildevIpIP Address to bind SMTP service to, defaults to :: (any IPv4/v6).obj['maildevIp'], process.env['MAILDEV_IP']optional--
maildevOutgoingHostSMTP host for outgoing mail.obj['maildevOutgoingHost'], process.env['MAILDEV_OUTGOING_HOST']optional--
maildevOutgoingPortSMTP port for outgoing mail.obj['maildevOutgoingPort'], process.env['MAILDEV_OUTGOING_PORT']optional--
maildevOutgoingUserSMTP user for outgoing mail.obj['maildevOutgoingUser'], process.env['MAILDEV_OUTGOING_USER']optional--
maildevOutgoingPassSMTP password for outgoing mail.obj['maildevOutgoingPass'], process.env['MAILDEV_OUTGOING_PASS']optional-hidden
maildevOutgoingSecureUse SMTP SSL for outgoing mail.obj['maildevOutgoingSecure'], process.env['MAILDEV_OUTGOING_SECURE']optional--
maildevAutoRelayUse auto-relay mode. Optional relay email address.obj['maildevAutoRelay'], process.env['MAILDEV_AUTO_RELAY']optional--
maildevAutoRelayRulesFilter rules for auto relay mode.obj['maildevAutoRelayRules'], process.env['MAILDEV_AUTO_RELAY_RULES']optional--
maildevIncomingUserSMTP user for incoming mail.obj['maildevIncomingUser'], process.env['MAILDEV_INCOMING_USER']optional--
maildevIncomingPassSMTP password for incoming mail.obj['maildevIncomingPass'], process.env['MAILDEV_INCOMING_PASS']optional-hidden
maildevIncomingSecureUse SMTP SSL for incoming emails.obj['maildevIncomingSecure'], process.env['MAILDEV_INCOMING_SECURE']optional--
maildevIncomingCertCert file location for incoming SSL.obj['maildevIncomingCert'], process.env['MAILDEV_INCOMING_CERT']optional--
maildevIncomingKeyKey file location for incoming SSL.obj['maildevIncomingKey'], process.env['MAILDEV_INCOMING_KEY']optional--
maildevWebIpIP Address to bind HTTP service to, defaults to --ip.obj['maildevWebIp'], process.env['MAILDEV_WEB_IP']optional--
maildevWebUserHTTP user for GUI.obj['maildevWebUser'], process.env['MAILDEV_WEB_USER']optional--
maildevWebPassHTTP password for GUI.obj['maildevWebPass'], process.env['MAILDEV_WEB_PASS']optional-hidden
maildevBasePathnameBase path for URLs.obj['maildevBasePathname'], process.env['MAILDEV_BASE_PATHNAME']optional--
maildevDisableWebDisable the use of the web interface. Useful for unit testing.obj['maildevDisableWeb'], process.env['MAILDEV_DISABLE_WEB']optional--
maildevHideExtensionsComma separated list of SMTP extensions to NOT advertise (SMTPUTF8, PIPELINING, 8BITMIME).obj['maildevHideExtensions'], process.env['MAILDEV_HIDE_EXTENSIONS']optional--

Static configuration

KeyDescriptionConstraintsDefaultValue
imageDocker image nameoptionalmaildev/maildev:2.2.1-
featureNameFeature name for generate prefix to environments keysoptional--
networksNetwork, if not set networkNames have project name and driver=bridge.optional--
smtpPortSMTP port to catch mailoptional1025-
webPortPort to run the Web GUI.optional1080-

Back to Top


DockerComposeMinio

MinIO is a high-performance, S3 compatible object storage. (Generator for minio in docker-compose.yml for https://www.npmjs.com/package/@nestjs-mod/docker-compose)

Use in NestJS-mod

An example of using Minio, you can see the full example here https://github.com/nestjs-mod/nestjs-mod-contrib/tree/master/apps/example-minio and frontend on Angular here https://github.com/nestjs-mod/nestjs-mod-contrib/tree/master/apps/example-minio-angular.

import {
  DefaultNestApplicationInitializer,
  DefaultNestApplicationListener,
  InfrastructureMarkdownReportGenerator,
  PACKAGE_JSON_FILE,
  ProjectUtils,
  bootstrapNestApplication,
  isInfrastructureMode,
} from '@nestjs-mod/common';
import { join } from 'path';

import { DOCKER_COMPOSE_FILE, DockerCompose, DockerComposeMinio } from '@nestjs-mod/docker-compose';

const userFeatureName = 'minio-user';
const rootFolder = join(__dirname, '..', '..', '..');
const appFolder = join(rootFolder, 'apps', 'example-minio');

bootstrapNestApplication({
  globalConfigurationOptions: { debug: true },
  globalEnvironmentsOptions: { debug: true },
  modules: {
    system: [
      ProjectUtils.forRoot({
        staticConfiguration: {
          applicationPackageJsonFile: join(appFolder, PACKAGE_JSON_FILE),
          packageJsonFile: join(rootFolder, PACKAGE_JSON_FILE),
          envFile: join(rootFolder, '.env'),
        },
      }),
      DefaultNestApplicationInitializer.forRoot(),
      DefaultNestApplicationListener.forRoot({
        staticConfiguration: {
          // When running in infrastructure mode, the backend server does not start.
          mode: isInfrastructureMode() ? 'silent' : 'listen',
        },
      }),
    ],
    infrastructure: [
      InfrastructureMarkdownReportGenerator.forRoot({
        staticConfiguration: {
          markdownFile: join(appFolder, 'INFRASTRUCTURE.MD'),
          skipEmptySettings: true,
        },
      }),
      DockerCompose.forRoot({
        configuration: {
          dockerComposeFileVersion: '3',
          dockerComposeFile: join(appFolder, DOCKER_COMPOSE_FILE),
        },
      }),
      DockerComposeMinio.forRoot({
        staticConfiguration: {
          nginxPort: 1111,
          nginxFilesFolder: join(appFolder, 'ngnix'),
          featureName: userFeatureName,
        },
      }),
    ],
  },
});

After connecting the module to the application and npm run build and starting generation of documentation through npm run docs:infrastructure, you will have new files and scripts to run.

New scripts mostly package.json

Add database options to docker-compose file for application docker-compose.yml with real credenionals and add it to .gitignore file

version: '3'
services:
  example-minio-minio:
    image: 'bitnami/minio:2024.2.9'
    container_name: 'example-minio-minio'
    volumes:
      - 'example-minio-minio-volume:/bitnami/minio/data'
    ports:
      - '9000:9000'
      - '9001:9001'
    networks:
      - 'example-minio-network'
    environment:
      MINIO_ROOT_USER: 'minioadmin'
      MINIO_ROOT_PASSWORD: '6EcbcW66JsKvFrY2bZw6QGKjHhefca7Kgppq'
    healthcheck:
      test:
        - 'CMD-SHELL'
        - 'mc'
        - 'ready'
        - 'local'
      interval: '5s'
      timeout: '5s'
      retries: 5
    tty: true
    restart: 'always'
  example-minio-nginx:
    image: 'nginx:alpine'
    container_name: 'example-minio-nginx'
    volumes:
      - './ngnix/config:/etc/nginx/conf.d'
      - './ngnix/logs:/var/log/nginx/'
    ports:
      - '1111:1111'
    networks:
      - 'example-minio-network'
    tty: true
    restart: 'always'
    depends_on:
      example-minio-minio:
        condition: 'service_started'
networks:
  example-minio-network:
    driver: 'bridge'
volumes:
  example-minio-minio-volume:
    name: 'example-minio-minio-volume'

Add database options to docker-compose file for application docker-compose-example.yml with fake credenionals

# Do not modify this file, it is generated using the DockerCompose module included with NestJS-mod.
version: '3'
services:
  example-minio-minio:
    image: 'bitnami/minio:2024.2.9'
    container_name: 'example-minio-minio'
    volumes:
      - 'example-minio-minio-volume:/bitnami/minio/data'
    ports:
      - '9000:9000'
      - '9001:9001'
    networks:
      - 'example-minio-network'
    environment:
      MINIO_ROOT_USER: 'value_for_minio_root_user'
      MINIO_ROOT_PASSWORD: 'value_for_minio_root_password'
    healthcheck:
      test:
        - 'CMD-SHELL'
        - 'mc'
        - 'ready'
        - 'local'
      interval: '5s'
      timeout: '5s'
      retries: 5
    tty: true
    restart: 'always'
  example-minio-nginx:
    image: 'nginx:alpine'
    container_name: 'example-minio-nginx'
    volumes:
      - './ngnix/config:/etc/nginx/conf.d'
      - './ngnix/logs:/var/log/nginx/'
    ports:
      - '1111:1111'
    networks:
      - 'example-minio-network'
    tty: true
    restart: 'always'
    depends_on:
      example-minio-minio:
        condition: 'service_started'
networks:
  example-minio-network:
    driver: 'bridge'
volumes:
  example-minio-minio-volume:
    name: 'example-minio-minio-volume'

New environment variable

EXAMPLE_MINIO_MINIO_USER_MINIO_ROOT_USER=minioadmin
EXAMPLE_MINIO_MINIO_USER_MINIO_ROOT_PASSWORD=6EcbcW66JsKvFrY2bZw6QGKjHhefca7Kgppq

When launched in the infrastructure documentation generation mode, the module creates an .env file with a list of all required variables, as well as an example example.env, where you can enter example variable values.

Static environments

KeyDescriptionSourcesConstraintsDefaultValue
minioRootUserMinio root user.obj['minioRootUser'], process.env['MINIO_ROOT_USER']isNotEmpty (minioRootUser should not be empty)--
minioRootPasswordMinio root password.obj['minioRootPassword'], process.env['MINIO_ROOT_PASSWORD']isNotEmpty (minioRootPassword should not be empty)--

Static configuration

KeyDescriptionConstraintsDefaultValue
imageDocker image nameoptionalbitnami/minio:2024.2.9-
featureNameFeature name for generate prefix to environments keysoptional--
networksNetwork, if not set networkNames have project name and driver=bridge.optional--
externalPortExternal port for S3 API operations on the default MinIO server port.optional9000-
externalConsolePortExternal console for browser access on the MinIO Console port.optional9001-
nginxPortExternal port for proxy access over nginx (infrastructure, need for disable CORS errors)optional--
nginxConfigFolderFolder for store nginx config (infrastructure)optional--
nginxLogsFolderFolder for store nginx logs (infrastructure)optional--
nginxBucketsLocationsLocations for proxy to minio (infrastructure)optional files -
nginxConfigContentCustom nginx config content (infrastructure)optional--

Back to Top


DockerComposeNats

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)

Static environments

KeyDescriptionSourcesConstraintsDefaultValue
natsEnableAuthEnable Authentication.obj['natsEnableAuth'], process.env['NATS_ENABLE_AUTH']optional--
natsUsernameUsername credential for client connections.obj['natsUsername'], process.env['NATS_USERNAME']optional--
natsPasswordPassword credential for client connections.obj['natsPassword'], process.env['NATS_PASSWORD']optional--

Static configuration

KeyDescriptionConstraintsDefaultValue
imageDocker image name.optionalbitnami/nats:2.10.5-
featureNameFeature name for generate prefix to environments keysoptional--
networksNetwork, if not set networkNames have project name and driver=bridge.optional--
externalClientPortExternal client port for sharing container.optional4222-
externalHttpPortExternal http port for sharing container.optional8222-
extraArgsExtra arguments.optional-js-

Back to Top


DockerComposeNginx

Nginx is a web server that can also be used as a reverse proxy, load balancer, mail proxy and HTTP cache. (Generator for nginx in docker-compose.yml for https://www.npmjs.com/package/@nestjs-mod/docker-compose)

Static configuration

KeyDescriptionConstraintsDefaultValue
imageDocker image nameoptionalnginx:alpine-
configContentConfig contentisNotEmpty (configContent should not be empty)--
configFolderConfig folder for map volume to /etc/nginx/conf.disNotEmpty (configFolder should not be empty)--
logsFolderLogs folder for map volume to /var/log/nginx/optional--
dependsOnServiceNamesDepends on servicesoptional--
portsPortsoptional--
networksNetwork, if not set networkNames have project name and driver=bridge.optional--

Back to Top


DockerComposePostgreSQL

PostgreSQL (Postgres) is an open source object-relational database known for reliability and data integrity. ACID-compliant, it supports foreign keys, joins, views, triggers and stored procedures. (Generator for databases in docker-compose.yml for https://github.com/nestjs-mod/nestjs-mod-contrib/tree/master/libs/infrastructure/docker-compose)

Use in NestJS-mod

An example you can see the full example here https://github.com/nestjs-mod/nestjs-mod-contrib/tree/master/apps/example-prisma-flyway or https://github.com/nestjs-mod/nestjs-mod-contrib/tree/master/apps/example-prisma.

import {
  DefaultNestApplicationInitializer,
  DefaultNestApplicationListener,
  PACKAGE_JSON_FILE,
  ProjectUtils,
  bootstrapNestApplication,
} from '@nestjs-mod/common';
import { DOCKER_COMPOSE_FILE, DockerCompose, DockerComposePostgreSQL } from '@nestjs-mod/docker-compose';
import { join } from 'path';

export const flywayPrismaFeatureName = 'flyway-prisma';

const rootFolder = join(__dirname, '..', '..', '..');
const appFolder = join(rootFolder, 'apps', 'example-prisma-flyway');

bootstrapNestApplication({
  modules: {
    system: [
      ProjectUtils.forRoot({
        staticConfiguration: {
          applicationPackageJsonFile: join(appFolder, PACKAGE_JSON_FILE),
          packageJsonFile: join(rootFolder, PACKAGE_JSON_FILE),
          envFile: join(rootFolder, '.env'),
        },
      }),
      DefaultNestApplicationInitializer.forRoot(),
      DefaultNestApplicationListener.forRoot({
        staticConfiguration: {
          // When running in infrastructure mode, the backend server does not start.
          mode: isInfrastructureMode() ? 'silent' : 'listen',
        },
      }),
    ],
    infrastructure: [
      DockerCompose.forRoot({
        configuration: {
          dockerComposeFileVersion: '3',
          dockerComposeFile: join(appFolder, DOCKER_COMPOSE_FILE),
        },
      }),
      DockerComposePostgreSQL.forRoot(),
      DockerComposePostgreSQL.forFeature({
        featureModuleName: flywayPrismaFeatureName,
      }),
    ],
  },
});

After connecting the module to the application and npm run build and starting generation of documentation through npm run docs:infrastructure, you will have new files and scripts to run.

New scripts mostly package.json

{
  "scripts": {
    "_____db_____": "_____db_____",
    "db:create": "./node_modules/.bin/nx run-many -t=db-create"
  },
  "scriptsComments": {
    "db:create": ["Creation all databases of applications and modules"]
  }
}

Additional commands in the nx application project.json

{
  "targets": {
    "db-create": {
      "executor": "nx:run-commands",
      "options": {
        "commands": [
          "./node_modules/.bin/pg-create-db --force-change-username=true --force-change-password=true --root-database-url=${EXAMPLE_PRISMA_FLYWAY_ROOT_DATABASE_URL} --app-database-url=${EXAMPLE_PRISMA_FLYWAY_FLYWAY_PRISMA_DATABASE_URL}"
        ],
        "parallel": false,
        "envFile": "./.env",
        "color": true
      }
    }
  }
}

Add database options to docker-compose file for application docker-compose.yml with real credenionals and add it to .gitignore file

version: '3'
services:
  example-prisma-flyway-postgre-sql:
    image: bitnami/postgresql:15.5.0
    container_name: example-prisma-flyway-postgre-sql
    volumes:
      - example-prisma-flyway-postgre-sql-volume:/bitnami/postgresql
    ports:
      - 5432:5432
    networks:
      - example-prisma-flyway-network
    healthcheck:
      test:
        - CMD-SHELL
        - pg_isready -U postgres
      interval: 5s
      timeout: 5s
      retries: 5
    tty: true
    restart: always
    environment:
      POSTGRESQL_USERNAME: postgres
      POSTGRESQL_PASSWORD: postgres_password
      POSTGRESQL_DATABASE: postgres
networks:
  example-prisma-flyway-network:
    driver: bridge
volumes:
  example-prisma-flyway-postgre-sql-volume:
    name: example-prisma-flyway-postgre-sql-volume

Add database options to docker-compose file for application docker-compose-example.yml with fake credenionals

# Do not modify this file, it is generated using the DockerCompose module included with NestJS-mod.
version: '3'
services:
  example-prisma-flyway-postgre-sql:
    image: bitnami/postgresql:15.5.0
    container_name: example-prisma-flyway-postgre-sql
    volumes:
      - example-prisma-flyway-postgre-sql-volume:/bitnami/postgresql
    ports:
      - 5432:5432
    networks:
      - example-prisma-flyway-network
    healthcheck:
      test:
        - CMD-SHELL
        - pg_isready -U postgres
      interval: 5s
      timeout: 5s
      retries: 5
    tty: true
    restart: always
    environment:
      POSTGRESQL_USERNAME: value_for_postgresql_username
      POSTGRESQL_PASSWORD: value_for_postgresql_password
      POSTGRESQL_DATABASE: value_for_postgresql_database
networks:
  example-prisma-flyway-network:
    driver: bridge
volumes:
  example-prisma-flyway-postgre-sql-volume:
    name: example-prisma-flyway-postgre-sql-volume

Static environments

KeyDescriptionSourcesConstraintsDefaultValue
rootDatabaseUrlConnection string for PostgreSQL with root credentials (example: postgres://postgres:postgres_password@localhost:5432/postgres?schema=public, username must be "postgres")obj['rootDatabaseUrl'], process.env['ROOT_DATABASE_URL']isNotEmpty (rootDatabaseUrl should not be empty)--

Static configuration

KeyDescriptionConstraintsDefaultValue
imageDocker image nameoptionalbitnami/postgresql:15.5.0-
networksNetwork, if not set networkNames have project name and driver=bridge.optional--
externalPortExternal port for sharing container.optional5432-
nxProjectJsonFileApplication or library project.json-file (nx)*optional
1.18.1

7 months ago

1.18.0

7 months ago

1.16.2

10 months ago

1.18.2

7 months ago

1.19.0

6 months ago

1.17.2

10 months ago

1.17.1

10 months ago

1.17.0

10 months ago

1.19.3

6 months ago

1.19.2

6 months ago

1.19.1

6 months ago

1.17.3

9 months ago

1.20.1

6 months ago

1.20.0

6 months ago

1.16.1

1 year ago

1.16.0

1 year ago

1.15.0

1 year ago

1.15.2

1 year ago

1.15.1

1 year ago

1.14.1

2 years ago

1.14.0

2 years ago

1.13.1

2 years ago

1.13.0

2 years ago

1.11.2

2 years ago

1.12.0

2 years ago

1.11.1

2 years ago

1.11.0

2 years ago

1.10.3

2 years ago

1.10.2

2 years ago

1.10.1

2 years ago

1.9.1

2 years ago

1.9.4

2 years ago

1.9.3

2 years ago

1.9.2

2 years ago

1.10.0

2 years ago

1.9.0

2 years ago

1.8.2

2 years ago

1.8.3

2 years ago

1.8.1

2 years ago

1.8.0

2 years ago

1.7.0

2 years ago

1.6.1

2 years ago

1.6.0

2 years ago

1.5.0

2 years ago

1.4.0

2 years ago

1.3.2

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.2.0

2 years ago

1.2.1

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago