Comparing version 3.3.1 to 3.3.2
{ | ||
"name": "devlab", | ||
"version": "3.3.1", | ||
"version": "3.3.2", | ||
"description": "Node utility for running containerized tasks", | ||
@@ -31,3 +31,3 @@ "keywords": [ | ||
"test:cover": "istanbul cover _mocha test/src/**/*.spec.js", | ||
"test:watch": "nodemon --exec \"npm run test:cover || exit 1\"", | ||
"test:watch": "nodemon --exec \"mocha test/src/**/*.spec.js || exit 1\"", | ||
"e2e": "node test/system/run.js", | ||
@@ -34,0 +34,0 @@ "lint": "standard --fix --verbose" |
@@ -55,21 +55,12 @@ const _ = require('redash') | ||
/** | ||
* Formats task by replacing line breaks with double-ampersands | ||
* @param {string} task The task command(s) | ||
* @returns {string} Formatted task | ||
*/ | ||
formatTask: (task) => task | ||
.replace(/(?:\r\n|\r|\n)/g, ' && ') | ||
.replace(' && && ', ' && ') | ||
.replace(/ &&\s*$/m, ''), | ||
/** | ||
* Returns array of execution commands | ||
* @param {object} cfg Config object for instance | ||
* @returns {array} Array of execution tasks | ||
* @returns {string} Execution script | ||
*/ | ||
getExec: (cfg) => { | ||
const cmd = [ 'sh', '-c' ] | ||
const before = cfg.before ? `${cfg.before} && ` : '' | ||
const after = cfg.after ? ` && ${cfg.after}` : '' | ||
const sh = '#!/bin/sh\nset -e;\n' | ||
const before = cfg.before ? `${cfg.before}\n` : '' | ||
const after = cfg.after ? `\n${cfg.after}` : '' | ||
// Custom exec, just run native task | ||
if (cfg.exec) return cmd.concat([command.formatTask(before + cfg.exec + after)]) | ||
if (cfg.exec) return sh + before + cfg.exec + after | ||
// Ensure tasks exist | ||
@@ -91,5 +82,5 @@ if (!cfg.tasks) throw new Error('No tasks are defined') | ||
}), | ||
_.join(' && ') | ||
_.join('\n') | ||
])(cfg.run) | ||
return cmd.concat([command.formatTask(before + run + after)]) | ||
return sh + before + run + after | ||
}, | ||
@@ -109,3 +100,3 @@ /** | ||
* @param {boolean} primary If this is primary, i.e. not a service container | ||
* @returns {array} Arguments for docker command | ||
* @returns {object|array} Arguments for docker command | ||
*/ | ||
@@ -115,3 +106,3 @@ get: (cfg, name, primary = false) => { | ||
const cwd = process.cwd() | ||
let args = primary ? [ 'run', '--rm', '-it', '-v', `${cwd}:${cwd}`, '-w', cwd, '--privileged' ] : [ 'run', '-d', '--privileged' ] | ||
let args = primary ? [ 'run', '--rm', '-it', '-v', `${cwd}:${cwd}`, '-v', '/tmp/devlab.sh:/devlabExec', '-w', cwd, '--privileged' ] : [ 'run', '-d', '--privileged' ] | ||
args = args.concat(_.flatten([ | ||
@@ -122,5 +113,5 @@ command.getArgs(cfg), | ||
cfg.from, | ||
primary ? command.getExec(cfg) : [] | ||
primary ? [ 'sh', '/devlabExec' ] : [] | ||
])) | ||
return args | ||
return primary ? { args, cmd: command.getExec(cfg) } : args | ||
} | ||
@@ -127,0 +118,0 @@ } |
const _ = require('redash') | ||
const Promise = require('bluebird') | ||
const fs = require('fs') | ||
const args = require('./args') | ||
@@ -10,2 +12,4 @@ const config = require('./config') | ||
Promise.promisifyAll(fs) | ||
global.instanceId = require('shortid').generate() | ||
@@ -20,3 +24,3 @@ | ||
* Gets config by merging parsed arguments with config object and returns command | ||
* instructions for primaary instance and services | ||
* instructions for primaary instance and services. | ||
* @returns {object} Command instructions | ||
@@ -56,5 +60,5 @@ */ | ||
runCommand: (cfg) => { | ||
output.success(`Running command: ${_.last(cfg.primary)}`) | ||
output.success('Running Task') | ||
output.line() | ||
return proc.run(cfg.primary) | ||
return proc.run(cfg.primary.args) | ||
.then(() => { | ||
@@ -78,4 +82,5 @@ output.line() | ||
const cfg = instance.getConfig() | ||
// Check orphans, start services, then run command | ||
return utils.checkOrphans() | ||
// Write the primary command to tmp script | ||
return fs.writeFileAsync('/tmp/devlab.sh', cfg.primary.cmd, { mode: '0o777' }) | ||
.then(() => utils.checkOrphans()) | ||
.then(() => instance.startServices(cfg)) | ||
@@ -82,0 +87,0 @@ .then(instance.runCommand) |
29868
559
6