Tiny image to help you building your npm/bower based projects
4.3K
The docker images are available on the docker hub: https://hub.docker.com/r/jokesterfr/npm-builder
Available tags:
Images are based on the excellent mhart/alpine-node alpine linux node images.
This project aims at helping developpers to build their Node.js project within a docker environment, while they may build images for node versions which may differ from their system environment.
The idea is to provide a full-featured image with some system dependencies (such as ruby, sass and git) to perform package retrival and build. The execution image is let to your own Dockerfile build expertise.
You shall know there are limitations while executing npm install or bower install as a root user. We chose here to create a "data" user for this task.
If you use custom git+ssh:// uri schemes in your package.json or bower.json dependencies (standing for your internal packages), you need to provide ssh credentials to your docker container to retrieve them. Same if you use any internal npm repository (such as sinopia) you may need a .npmrc file with access tokens inside.
These credentials can be copied to your docker container scope, but they would remain in one layer (even if you add a RUN rm -rf .npmrc .ssh/) of your container, occasioning a security breach if you deliver your image as is (or use docker-squash). The solution for this is to build your npm/bower dependencies within a temporary container, remove the credentials, then build your image - ready for delivery.
docker run -it --rm -v ${PWD}:/data jokesterfr/npm-builder:latest npm install
package.jsonYou may like to add some scripts to your package.json like:
{
"scripts": {
"postinstall": "cd ./submodule && npm install",
"clean": "git clean -X -d -f",
"clean:devDependencies": "for a in `find -name package.json | grep -v \"node_modules\\|bower_components\" | sed -e \"s|/package.json||g\"`; do npm prune --production --prefix $submodule; done;",
"clean:credentials": "rm -rf .ssh/ .npmrc",
"build:credentials": "npm run build:sshconfig && npm run build:npmrc",
"build:npmrc": "cp ~/.npmrc .",
"build:sshconfig": "mkdir -p .ssh && cp ~/.ssh/id_rsa .ssh/ && echo \"Host git.domain.com\n\tUser git\n\tIdentityFile ~/.ssh/id_rsa\n\tStrictHostKeyChecking no\" > .ssh/config && chmod 600 .ssh/config",
"build:deps": "npm run build:credentials && docker run -it --rm -v ${PWD}:/data jokesterfr/npm-builder:latest sh -c 'npm i && npm run clean:credentials && npm run clean:devDependencies'",
"build:docker": "docker build -t namespace/$npm_package_name:latest -t namespace/$npm_package_name:$npm_package_version .",
"prebuild:docker": "npm run clean && npm run build:deps"
}
}
Then in one command line, you will be able to:
npm prune --production)# with npm installed on the host
npm run build:docker
# without npm on the host
mkdir -p .ssh
cp ~/.ssh/id_rsa .ssh/
echo "Host git.domain.com\n\tUser git\n\tIdentityFile ~/.ssh/id_rsa\n\tStrictHostKeyChecking no" > .ssh/config
chmod 600 .ssh/config
cp ~/.npmrc .
docker run -it --rm -v ${PWD}:/data jokesterfr/npm-builder:latest npm i
rm -rf .npmrc .ssh/
docker build -t namespace/package:latest -t namespace/package:v1.0.0 .
Please use the github issues tool. We try to keep the images as tiny as possible, but if you think we would need more tools (ie, that do not fit as devDependencies) feel free to submit a PR.
MIT
Content type
Image
Digest
Size
40 MB
Last updated
over 9 years ago
docker pull jokesterfr/npm-builder