docker-preprocessor v0.1.0
docker-preprocessor
A general-purpose module for preprocessing using Docker.
Install
npm install --save-dev docker-preprocessor
Usage
docker-preprocessor
can be used for extremely complex (Emscripten, for C++ to
WebAssembly compilation) to very simple tasks (checking output of a Node.js
version). It is meant to be unopinionated and easy to fit into any preprocessor
toolchain.
file.txt
Hello, World!
preprocessor.js
import dockerPreprocessor from 'docker-preprocessor';
const options = {
image: 'node',
createOptions: {
Binds: ['/:/host'],
WorkingDir: '/src',
},
command: path => [
'sh',
'-c',
`
node \
-e \
" \
const { readFileSync, writeFileSync } = require('fs'); \
const content = readFileSync('/host${path}', { encoding: 'utf8' }).split('').reverse().join(''); \
writeFileSync('./result', content); \
" \
;
`,
],
paths: {
main: '/src/result',
},
};
const { content } = await dockerPreprocessor(options)('file.txt');
console.log(bufferOfContentsReversedByDockerContainer.toString('utf8')); // !dlroW ,olleH
Documentation
dockerPreprocessor(options)
options
<Object>
dockerOptions
<Object>
Options passed todockerode
's instantiation of aDocker
object.image
<string>
Image and tag string to create a Docker container with. Defaults to'ubuntu'
(which defaults to thelatest
tag).command
<Function>
A function that takes apath
string and returns an exec array. Thepath
string is provided bydockerPreprocessorRunner
. Defaults to() => ['bash']
.streams
<Writable>
,<Array>
AWritable
stream or an array ofWritable
streams to pipe to from a Docker container. Seedockerode
for a more in-depth explanation. Defaults toprocess.stdout
.[createOptions]
<Object>
Optional options used for container creation. Seedockerode
for a more in-depth explanation.[startOptions]
<Object>
Optional options used for container start. Seedockerode
for a more in-depth explanation.paths
<Object>
An object with paths to file locations within the Docker container to retrieve and return asBuffer
s.
Returns a function, dockerPreprocessorRunner
.
dockerPreprocessorRunner(filePath)
filePath
<string>
Path to a source file. This string is given to thecommand
function property given todockerPreprocessor
in its option object.
Returns a Promise
which resolves to a result
object.