1.0.1 • Published 1 year ago

docker-compose-builder v1.0.1

Weekly downloads
1
License
ISC
Repository
github
Last release
1 year ago

Docker Compose Builder

This package enables you to define your docker compose fiel from code and let it generate a docker-compose.yml on the fly. This is especially usefull if you need to have a variable length of the same service. Now you can create container in a loop and add as many as you want.

Example

import { DockerCompose } from './docker-compose'
import { Environment } from './environment'
import { Service } from './service'
import { Volumes } from './volumes'

const environment = Environment.builder()
                    .withEnvironmentVariable('MINIO_ROOT_USER', 'admin')
                    .withEnvironmentVariable('MINIO_ROOT_PASSWORD', 'StronPassword')
                    .build()


const minio = Service.builder("minio")
                .withServiceName("minio")
                .withImage("minio/minio")
                .withEnvironment(environment)
                .withCommand('server --console-address ":9001" /data')
                .build()


const mongoDb = Service.builder("db")
                    .withServiceName("db")
                    .withImage("mongo:latest")
                    .withVolumes("mongo_storage:/data/db")
                    .build()
            
const volumes = Volumes.builder()
                .withVolume("minio_storage")
                .withVolume("mongo_storage")
                .build()

const compose = DockerCompose.builder()
        .withVersion("2")
        .withServices(minio, mongoDb)
        .withVolumes(volumes)
        .build()

compose.createDockerComposeFile('docker-compose.yaml')

Generates:

version: "2"
services:
  minio:
    container_name: minio
    image: minio/minio
    environment:
      - MINIO_ROOT_USER: admin
      - MINIO_ROOT_PASSWORD: StronPassword
    command: server --console-address ":9001" /data
  db:
    container_name: db
    image: mongo:latest
    volumes:
      - mongo_storage:/data/db
volumes:
  - minio_storage: {}
  - mongo_storage: {}
1.0.1

1 year ago

1.0.0

1 year ago

1.0.12

5 years ago

1.0.2

5 years ago