Coder Social home page Coder Social logo

decomposerize's Introduction

composerize

Build Status npm Follow @mark_larah ShareVB on GitHub

http://composerize.com - Turns docker run commands into docker-compose.yml files and even merge with existing docker-compose.yml!

Looking for the reverse : http://decomposerize.com / Decomposerize

Want to convert from Docker compose file formats : http://composeverter.com / Composeverter

Demo

CLI

composerize can be run in the cli.

npm install composerize -g to install, and run as such:

$ composerize docker run -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock:ro --restart always --log-opt max-size=1g nginx

See composerize --help for more options.

How to use with node.js

Make sure to install the composerize package in your project by running:

npm install composerize

With the following code, you can easily integrate Composerize into your Node.js project and generate Docker Compose configurations from Docker run commands.

const composerize = require('composerize');

const dockerRunCommand = 'docker run -d -p 8080:80 --name my-web-app nginx:latest';

// Convert the Docker run command to a Docker Compose configuration
const composeConfig = composerize(dockerRunCommand);

console.log(composeConfig);

You can also merge docker run command(s) with an existing Docker Compose file content :

const composerize = require('composerize');

const dockerRunCommand = 'docker run -d -p 8080:80 --name my-web-app nginx:latest';

// An existing Docker Compose configuration as a string
const existingComposeConfig = `
version: '3'
services:
  existing-service:
    image: my-existing-image:latest
    ports:
      - '8000:80'
`;

// Convert the Docker run command to a Docker Compose configuration and merge with provided docker compose
const composeConfig = composerize(dockerRunCommand, existingComposeConfig);

console.log(composeConfig);

You can also choose which version of Docker compose V2, you target : 2.x, 3.x or Common Specification by specifying a third parameter composeVersion on convertDockerRunToCompose :

  • 'v2x'
  • 'v3x'
  • 'latest'
const composerize = require('composerize');

const dockerRunCommand = 'docker run -d -p 8080:80 --name my-web-app nginx:latest';

// Convert the Docker run command to a Docker Compose configuration for 2.x
const composeConfig = composerize(dockerRunCommand, null, 'v2x');

console.log(composeConfig);

You can also choose indentation level by specifying a fourth parameter indent on convertDockerRunToCompose :

  • 'v2x'
  • 'v3x'
  • 'latest'
const composerize = require('composerize');

const dockerRunCommand = 'docker run -d -p 8080:80 --name my-web-app nginx:latest';

// Convert the Docker run command to a Docker Compose configuration for 2.x
const composeConfig = composerize(dockerRunCommand, null, 'latest', 2);

console.log(composeConfig);

Contributing

  • Clone a fork of the repo and install the project dependencies by running yarn
  • Make your changes, and build the project by running make build
  • Test your changes with make test

Maintainers

decomposerize's People

Contributors

sharevb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

decomposerize's Issues

[bug] "volumes" field support is missing

@composerize I'm using the online version: https://ray.run/tools/docker-compose-to-docker-run

Do you want to request a feature or report a bug?

  • feature request
  • bug report

Please provide a sample input docker run command

If I input a simplified configuration, decomposerize returns docker run commands without docker volume command, which will failed to start containers without the needed volume:

version: "3"

volumes:
  polyfill-cache:
    driver: juicedata/juicefs
    driver_opts:
      name: polyfill-cache
      metaurl: postgres://postgres:${META_PASSWORD}@meta-server:5432/juicefs
      storage: ${STORAGE_TYPE}
      bucket: ${BUCKET}
      access-key: ${ACCESS_KEY}
      secret-key: ${SECRET_KEY}

services:
  meta-server:
    image: postgres
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_DB=juicefs
      - POSTGRES_PASSWORD=${META_PASSWORD}
    volumes:
      - ./data:/var/lib/postgresql/data/
    restart: always

  api-service:
    depends_on:
      - meta-server
    image: polyfiller/api-service
    environment:
      - NODE_ENV=production
    volumes:
      - polyfill-cache:/tmp/@wessberg/polyfiller
    restart: always

then input the whole original configuration, an error thrown:

version: "3"

volumes:
  polyfill-cache:
    driver: juicedata/juicefs
    driver_opts:
      name: polyfill-cache
      metaurl: postgres://postgres:${META_PASSWORD}@meta-server:5432/juicefs
      storage: ${STORAGE_TYPE}
      bucket: ${BUCKET}
      access-key: ${ACCESS_KEY}
      secret-key: ${SECRET_KEY}

networks:
  polyfiller:

services:
  autoheal:
    image: willfarrell/autoheal:1.2.0
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    restart: always

  meta-server:
    depends_on:
      - autoheal
    image: postgres
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_DB=juicefs
      - POSTGRES_PASSWORD=${META_PASSWORD}
    volumes:
      - ./data:/var/lib/postgresql/data/
    networks:
      - polyfiller
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 3s
      retries: 5
    labels:
      - autoheal=true
    restart: always

  api-service:
    depends_on:
      - autoheal
      - meta-server
    image: polyfiller/api-service
    environment:
      - NODE_ENV=production
    volumes:
      - polyfill-cache:/tmp/@wessberg/polyfiller
    networks:
      - polyfiller
    healthcheck:
      test: ["CMD-SHELL", "curl -f http://localhost:3000/ || exit 1"]
      interval: 300000000s
      retries: 5
      start_period: 30s
    labels:
      - autoheal=true
    restart: always
    logging:
      driver: json-file
      options:
        max-size: 10m

  caddy:
    depends_on:
      - api-service
    image: caddy
    ports:
      - 80:80
      - 443:443
    networks:
      - polyfiller
    restart: always
    command: caddy reverse-proxy --from polyfiller.app --to api-service:3000

What is the current output?

docker run -e POSTGRES_USER=postgres -e POSTGRES_DB=juicefs -e POSTGRES_PASSWORD=${META_PASSWORD} -v ./data:/var/lib/postgresql/data/ --restart always postgres
docker run -e NODE_ENV=production -v polyfill-cache:/tmp/@wessberg/polyfiller --restart always polyfiller/api-service

or

A.forEach is not a function

What is the expected/desired output?

docker volume create --driver juicedata/juicefs \
  --opt name=polyfill-cache
  --opt metaurl=postgres://postgres:${META_PASSWORD}@meta-server:5432/juicefs
  --opt storage=${STORAGE_TYPE}
  --opt bucket=${BUCKET}
  --opt access-key=${ACCESS_KEY}
  --opt secret-key=${SECRET_KEY}
  polyfill-cache
docker run  -v ./data:/var/lib/postgresql/data/ \
  -e POSTGRES_USER=postgres
  -e POSTGRES_DB=juicefs
  -e POSTGRES_PASSWORD=${META_PASSWORD}
  --restart always
  postgres
docker run  -v polyfill-cache:/tmp/@wessberg/polyfiller \
  -e NODE_ENV=production
  --restart always
  polyfiller/api-service

[bug] "volumes

Do you want to request a feature or report a bug?

  • feature request
  • bug report

Please provide a sample input docker run command

nginx:
    ports:
        - '80:80'
    volumes:
        - '/var/run/docker.sock:/tmp/docker.sock:ro'
    image: nginx

What is the current output?*

some output

What is the expected/desired output?

some better output

Thanks for following this template and making decomposerize better for everyone else too!

Mappings are not supported for service environment, labels, and sysctls

Do you want to request a feature or report a bug?

  • feature request
  • bug report

Pretty self-explanatory, as per the Compose Specification some elements can be either an array or a mapping, the latter of which is not recognized by decomposerize.

Please provide a sample input docker run command

services:
  alpine:
    image: alpine
    environment:
      NODE_ENV: production
    labels:
      com.centurylinklabs.watchtower.enable: "false"
    sysctls:
      net.core.somaxconn: 1024
      net.ipv4.tcp_syncookies: 0

What is the current output?*

docker run -e "[object Object]" -l "[object Object]" --sysctl "[object Object]" alpine

What is the expected/desired output?

docker run -e NODE_ENV=production -l com.centurylinklabs.watchtower.enable=false --sysctl net.core.somaxconn=1024 --sysctl net.ipv4.tcp_syncookies=0 alpine

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.