Giter Club home page Giter Club logo

docker-compose-js's Introduction

docker-compose-js - Javascript API for docker-compose

This is a simple API wrapper for the docker-compose command line tool. Its primary purpose is to allow integration tests written in node.js to dynamically manipulate the docker-compose environment.

A larger example of the API used in this way is available in the integration tests for the Teraslice project

Installation

npm install @bahmanm/docker-compose-js

Usage

The API largely just mirrors the regular docker-compose commands such as up(), down(), start(), stop() and so on. At the present time all commands except 'logs' and 'events' have been implemented.

The API is Promise based using the Bluebird promises library.

The examples below show the common patterns for calls. Since this is a wrapper around the standard docker-compose command details on each operation can be found in the docker-compose documentation.

Note: Each function takes an object for keyword parameters as the last argument.

const DockerCompose = require('docker-compose-js');

const fooComposer = DockerCompose('docker-compose.yaml', {
  '-p', `foo-${genRandomString()}`,
  '--host', 'foo.thatplace.com'
});

fooComposer.up()
    .then(function() {
        return fooComposer.stop('test');
    })
    .then(function() {
        return fooComposer.kill('test', { s: 'SIGINT' });
    })
    .then(function() {
        return fooComposer.ps();
    })
    .then(console.log)
    .catch(function(error) {
        console.log(error);
    })
    .finally(function() {
        fooComposer.down();
    })

Example of scaling a particular task

const DockerCompose = require('docker-compose-js');

const fooComposer = DockerCompose('docker-compose.yaml');

fooComposer.up()
    .then(function(result) {
        return fooComposer.scale('test=2');
    })
    .then(function() {
        return fooComposer.ps();
    })
    .then(console.log)
    .catch(function(error) {
        console.log(error);
    })
    .finally(function() {
        return fooComposer.down();
    })

docker-compose-js's People

Contributors

bahmanm avatar kstaken avatar peterdemartini avatar

Watchers

 avatar  avatar  avatar

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.