npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gulp-docker-compose

v1.1.3

Published

Gulp <-> Docker Compose binding

Downloads

46

Readme

Gulp Docker Compose

Hey there ;) The binding between gulp and docker compose lies ahead.

Installation

Just make sure you have installed docker, docker-compose and node, and the current user is in the docker group in order to be able to run docker commands without sudo.

Usage

Typical gulpfile.js

const gulp = require('gulp');
const clean = require('gulp-clean');
const babel = require('gulp-babel');
const path = require('path');
const plumber = require('gulp-plumber');
const vfs = require('vinyl-fs');
const GulpDockerCompose = require('gulp-docker-compose').GulpDockerCompose;

const srcFolder = `${__dirname}/src/`;
const dstFolder = `${__dirname}/build/`;

// clean the previous build
gulp.task('clean', function() {
    return gulp.src(dstFolder, {read: false})
        .pipe(clean({force: true}));
});

// compile js
gulp.task('build', ['clean'], function() {
    // vfs follows symlinks
    return vfs.src(srcFolder+'/**/*.js')
        .pipe(plumber())
        .pipe(babel({
            presets: [
                ["env", {
                    "targets": {
                        "node": "4"
                    },
                    "modules": "commonjs",
                }],
            ]
        }))
        .pipe(vfs.dest(dstFolder));
});

var gulpDocker = new GulpDockerCompose(gulp, {
    serviceName: 'app',
    tasks: {
        run: {
            name: 'run',
            dependences: ['build'],
        },
        restart: {
            name: 'restart',
            dependences: ['build'],
        },
        watchYML: {
            name: 'watch-yml',
        },
    },
    extraArgs: {
        upOnRun: '--scale app=3',
        upOnYMLChange: '--scale app=3',
    },
    exposeCLICommands: true,
    exposeStdOut: false,
    exposeStdErr: true,
    projectFolder: __dirname,
});

gulp.task('watch', function() {
    gulp.watch([srcFolder+'/**/*'], ['build', 'restart']);
});
gulp.task('default', ['build', 'watch', 'watch-yml', 'run']);

Options and arguments

GulpDockerCompose takes 2 arguments:

  • gulp - the reference to gulp object to work with
  • options - an object of various options described below

Options

  • serviceName (optional) - the name of the service to build (typically, the one in docker-compose.yml which has build directive)
  • tasks (optional) - the list of tasks to create, an object with two keys: run - stands for run compose task, and restart - for restart
  • hangOnInt (optional, default: true) - when the Ctrl+C combo is pressed on gulp watch, it stops docker compose. If the option is set to false, it will not override process.on('SIGINT') handler, but in this case, the docker compose (started as a daemon) will not be terminated. You may call gulpDocker.stopDockerCompose() manually in this case.
  • exposeCLICommands (optional, default: false) - being set to true, allows applied docker-compose cli commands to be displayed
  • exposeStdOut (optional, default: false) - expose stdout of cli command
  • exposeStdErr (optional, default: true) - expose stderr of cli command
  • projectFolder (optional) - sets project current folder. Should be set and correct in order to use 'watchYML' task

Both tasks have the same format: an object with the following keys:

  • name - the name of the task (an alias #SERVICE_NAME# is available and will get replaced with the value of serviceName)
  • dependences - the list of tasks which should be executed before gulp enters this task

If no tasks block specified, they can be created with makeRunTask() and makeRestartTask() respectively like the following:

gulpDocker.makeRunTask('run:#SERVICE_NAME#', ['build']);
gulpDocker.makeRestartTask('restart:#SERVICE_NAME#', ['build']);

Typical docker-compose.yml

version: '3'

services:
  app:
    build: .
    depends_on:
          - "db"
    ports:
      - "3101:3012"
    environment:
      - DB_URL=mongodb://db:27017/mydatabase
      - PORT=3012
      - ROOT_URL=http://localhost
  db:
      image: "mongo"
      ports:
        - "3110:27017"

Note that the corresponding Dockerfile should be present inside the same folder in order to build the service.

Under the hood

In fact, the module only launches the following docker-compose commands:

On run and restart tasks:

docker-compose up -d --build

On docker-compose.yml file changed:

docker-compose up -d --remove-orphans

On Ctrl+C:

docker-compose stop

License

MIT

Enjoy ;)