Created
August 30, 2016 00:51
-
-
Save jokeyrhyme/d57097a491aa5ecaf27532d057d72461 to your computer and use it in GitHub Desktop.
execute `npm` within a Docker container, within the host's working directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
// ideal for use with AWS Lambda and native Node.js modules | |
// requires Docker: https://docs.docker.com/engine/installation/ | |
/* | |
Usage: | |
node docker-npm.js install | |
node docker-npm.js rebuild | |
*/ | |
const childProcess = require('child_process') | |
const nodejsImage = 'node:4.3' | |
const innerWorkingDir = '/src' | |
const dockerArgs = [ | |
'run', '-i', | |
'-v', `${process.cwd()}:${innerWorkingDir}`, | |
'-w', innerWorkingDir, | |
nodejsImage, 'npm' | |
] | |
const npmArgs = process.argv.slice(2) | |
const cp = childProcess.execFile( | |
'docker', | |
dockerArgs.concat(npmArgs), | |
{}, | |
(err, stdout, stderr) => {} | |
) | |
cp.stderr.on('data', (data) => console.error(data)) | |
cp.stdout.on('data', (data) => console.log(data)) | |
cp.on('close', (code) => process.exit(code)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment