-
-
Save colkito/3b0537ccd77f6a0c60debfc1f0445d0d 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
// 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:8.10'; | |
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), | |
{}, | |
() => {}, | |
); | |
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