Skip to content

generate Docker Micro Service project from a config object

Notifications You must be signed in to change notification settings

tecla5/docker-gen

Repository files navigation

Docker Micro Services generator

Generate a fully configured Docker Micro Services from a node-red project with sub-match nodes for hemera or seneca based services (using message publish/subscribe and pattern matching).

Such a Docker project can in turn be (re)-imported into node-red via node-red-import

Docker project generator service

Can be found in /service

The Dockerfile will instantiate an express server on port 3100 with a root / endpoint that listens to incoming data in request body and uses it as inputs argument for plop. The inputs should be a list of node-red nodes.

See fixtures/nodes.js for an example.

Commits

The /commits folder contains compare which can compare two node-red exports and determine which generated files have changed, calculate a file diff.

  • Add support for move?
  • Well, not really possible to move with generated content :)

The store can be used to store each file diff for comparison and travel across time, just like in git.

Currently the following Git APIs are (being) supported (see /commits/git:

Tests

Gitlab prepare commit

Test that git/gitlab/prepare.js prepares gitlab commit actions from commits/compare.js result.

ava git/gitlab/test/

Plop

See plop

Install plop binary

Install plop binary globally

npm install -g github:tecla5/plop

Docker compose

Using Docker Compose v3 schema

Deploy swarm mode

  deploy:
    mode: replicated
    replicas: 2
    labels: [APP=VOTING]
    placement:
      constraints: [node.role == worker]

Run

Generate an ./app Docker project for hemera

npm start using global plop binary

Alternatively npm run start:dev to use local plop in node_modules

Should remove any existing ./app folder and generate a new app project!

You can also pass options (minimist way) like this:

$ plop -l xa -s
[SUCCESS] add /app/docker-compose.yml

The plopfile main function (see below) will then be passed this opts argument: {l: 'xa', s: true } This can fx be used to customize the inputs file used, to override the default

$ plop -inputs fixtures/custom
[SUCCESS] add /app/docker-compose.yml

Run as library

Plop can now be run completely as a library, without any Terminal requirement.

node run.js

#!/usr/bin/env node

var run = require('./plop-run')
run()

Docker compose

When we manage to generate a valid docker-compose.yml file, we should be able to run it as a Docker micro service project via:

docker-compose up

TODO

Change Actions naming

  • list to forAll
  • item to forEach

Upgrade plop

merge with plop 0.6

Upgrade docker schema V3

Upgrade to docker-compose schema V3 with deploy section

    deploy:
      mode: replicated
      replicas: {{ swarmCount }}
      labels: [APP={{ dashCase name }}]
      placement:
        constraints: [node.role == worker]

Troubleshooting

ERROR: [FAILED] add File already exists

Try removing the generated app folder

$ rm -rf app

plopfile.js

The plopfile.js is used to define the inputs and how to generate the resulting Docker Micro Services project.

For development the inputs are currently hardcoded to be loaded from a file, but could also make an async call to a web service (exposed by node-red) to get the node data in the format required.

module.exports = (plop, opts = {}) => {
    let inputsPath = opts.inputs || './fixtures/single-service'
    let data = require(inputsPath)
    // ...
    inputs: (config) => {
      return data
    },

The actions are specified using simple plop action format with handlebars helpers.

// List of actions to take.
// Here we "add" new files from our templates.
actions: {
  list: [{
      type: "add",
      path: "app/services/{{dashCase name}}/.babelrc",
      templateFile: "plop-templates/babelrc.tpl"
    }, {
    // ...
    }],
  item: [{
    type: "add",
    path: "app/docker-compose.yml",
    templateFile: "plop-templates/docker-compose.yml.tpl"
  }]
  }
}

TODO

Add labels to conform with node-red-import

License

ISC

About

generate Docker Micro Service project from a config object

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published