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

dynamic-docker-compose

v1.0.5

Published

NPM package https://www.npmjs.com/package/dynamic-docker-compose

Downloads

3

Readme

NPM package https://www.npmjs.com/package/dynamic-docker-compose

dynamic-docker-compose

Nodejs docker-compose class.
Loads one or more docker-compose files and parses the yaml contained within.
When more than one file is supplyed the contents are merged on like keys. Yaml parsing is done with js-yaml. Object merging preformed by deepmerge

Usage jsdocs

Create an instance of the class like so.

import DockerComposeFile from 'dynamic-docker-compose';
const composeFile = new DockerComposeFile(`${__dirname}/docker-compose.yml`);
// or 
const yamlString = 
`
networks:
  proxy:
    driver: bridge
services:
  vpn:
    cap_add:
      - NET_ADMIN
    container_name: vpn
    environment:
      - REGION
      - OPENVPN_USER
      - VPNSP
    image: vpn
    networks:
      - proxy
    restart: always
    volumes:
      - ./vpn/volumes/gluton/:/gluetun
      - ./data:/data
version: '3'
`;
const composeFile = new DockerComposeFile(yamlString);

After you have created an instance of DockerComposeFile you can modify the YAML object using js-yaml.

Multiple files can be passed to the constructor

import DockerComposeFile from 'dynamic-docker-compose';
const composeFile = new DockerComposeFile(
  `${__dirname}/docker-compose1.yml`, 
  `${__dirname}/docker-compose2.yml`
);

Merging

The contents are merged on like keys.

Yaml version file.

# version.docker-compose.yml
version: '3'

Yaml network file.

# network.docker-compose.yml
networks:
  proxy:
    driver: bridge

Vpn service yaml file.

# vpn.docker-compose.yml
services:
  vpn:
    cap_add:
      - NET_ADMIN
    container_name: vpn
    environment:
      - REGION
      - OPENVPN_USER
      - VPNSP
    image: vpn
    networks:
      - proxy
    restart: always
    volumes:
      - ./vpn/volumes/gluton/:/gluetun
      - ./data:/data

Nodejs service yaml file.

# node-server.docker-compose.yml
services:
  node-server:
    container_name: node-server
    image: node
    networks:
      - proxy
    restart: always
import DockerComposeFile from 'dynamic-docker-compose';
const composeFile = new DockerComposeFile(
  `version.docker-compose.yml`, 
  `network.docker-compose.yml`,
  `vpn.docker-compose.yml`,
  `node-server.docker-compose.yml`
);

Outputing

composeFile.yaml;

will result in the following merged yaml file.

# node-server.docker-compose.yml
networks:
  proxy:
    driver: bridge
services:
  node-server:
    container_name: node-server
    image: node
    networks:
      - proxy
    restart: always
  vpn:
    cap_add:
      - NET_ADMIN
    container_name: vpn
    environment:
      - REGION
      - OPENVPN_USER
      - VPNSP
    image: vpn
    networks:
      - proxy
    restart: always
    volumes:
      - ./vpn/volumes/gluton/:/gluetun
      - ./data:/data
version: '3'

Mapping

DockerComposeFile can be mapped When template strings exist in the yaml file.
Template strings are in ${TEMPLATE_STRING} format.

# vpn.docker-compose.yml
services:
  ${VPN_NAME}:
    cap_add:
      - NET_ADMIN
    container_name: ${VPN_NAME}
    environment:
      - REGION=${REGION}
      - OPENVPN_USER
      - VPNSP
    image: vpn
    networks:
      - proxy
    restart: always
    volumes:
      - ./vpn/volumes/gluton/:/gluetun
      - ./data:/data
const composeFileTemplate = new DockerComposeFile(`vpn.docker-compose.yml`);
const composeFiles = composeFileTemplate.mapTemplate(
  ['VPN_NAME', ['vpn-west', 'vpn-seattle']],
  ['REGION', ['US_West', 'US_Seattle']],
);

This would create two DockerComposeFile instances.

# vpn.docker-compose.yml
services:
  vpn-west:
    cap_add:
      - NET_ADMIN
    container_name: vpn-west
    environment:
      - REGION=US_West
      - OPENVPN_USER
      - VPNSP
    image: vpn
    networks:
      - proxy
    restart: always
    volumes:
      - ./vpn/volumes/gluton/:/gluetun
      - ./data:/data
# vpn.docker-compose.yml
services:
  vpn-seattle:
    cap_add:
      - NET_ADMIN
    container_name: vpn-seattle
    environment:
      - REGION=US_Seattle
      - OPENVPN_USER
      - VPNSP
    image: vpn
    networks:
      - proxy
    restart: always
    volumes:
      - ./vpn/volumes/gluton/:/gluetun
      - ./data:/data

Those files can be merged afterwards by passing them to a new DockerComposeFile.

const composeFileTemplate = new DockerComposeFile(`vpn.docker-compose.yml`);
const composeFiles = composeFileTemplate.mapTemplate(
  ['VPN_NAME', ['vpn-west', 'vpn-seattle']],
  ['REGION', ['US_West', 'US_Seattle']],
);
const mergedMap = new DockerComposeFile(...composeFiles);