npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

docker-npm

v0.3.0

Published

A simple bash script to ease npm usage through docker

Downloads

1

Readme

dnpm

A simple bash script to ease npm usage through docker.

dnpm is mainly of use when needing to operate preliminary npm tasks before building a docker image. This is in particular necessary when you do not want to pollute the image to build with the building environment (for instance with credentials needed to get dependencies from private repositories). An alternative is to directly operate these tasks in the Dockerfile but this also means ensuring that nothing remains from the building environment which can sometimes be a cumbersome task even if it is quite well described in npm documentation (read the article through its end to realize that you will actually need to squash your image).

So the main point of dnpm is to ensure that your configuration and credentials are available within this preliminary build container. This is provided by read-only mounting the host user home directory and ensuring that part of the host user environment is also available within the container.

The only host volume that is not mounted read-only is the workdir which is the current project directory (the one with the package.json file) and hence should be protected by a versioning system like git.

The default image used by the dnpm container is mhart/alpine-node. This can be easily changed by using the -i option.

Installation

curl -L -O https://raw.githubusercontent.com/telecomsante/dnpm/master/dnpm

If a tagged revision of the tool is needed:

curl -L -O https://raw.githubusercontent.com/telecomsante/dnpm/TAG/dnpm

The bash script provided above is intended to work everywhere (posix compatibility), but if you like you can get it with npm:

npm install -g docker-npm
dnpm --help

Help

dnpm provides its own help page:

dnpm --help

Usage

dnpm can mainly be used to operate npm installs:

dnpm -w path/to/a/node/project "npm install"

For more complex situations involving bower and private git repositories, you might want to do things like:

dnpm -w path/to/a/node/project "apk add --no-cache git openssh" "npm install"

Password protected SSH keys

If your commands involve using an SSH key protected by a password, you can start an SSH agent container and add your SSH key this way:

docker run -d -v ssh:/ssh --name=ssh-agent whilp/ssh-agent:latest
docker run --rm -v ssh:/ssh -v $HOME:$HOME -it whilp/ssh-agent:latest ssh-add $HOME/.ssh/id_rsa

Then simply use the -s option of dnpm to take into account the ssh-agent:

dnpm -w path/to/a/node/project -s ssh "npm install"

Where ssh (the -s argument) is the docker volume used by the SSH agent container.

When node-gyp is needed

There seems to be no way to instruct node-gyp to change its devdir through an npm option or an environment variable (--nodedir is not an option as it also impacts the way npm reaches Node.js sources and heavily depends on the docker image used).

In order to work around this limitation dnpm binds temporarily ~/.node-gyp to a temporary folder in the container. This means that dnpm also ensures that the ~/.node-gyp folder exists. This is for now the only modification that dnpm might operate on the host user account.

node-gyp will probably need additional tools like python and other build tools, so for the default image (alpine-node):

dnpm -w path/to/a/node/project "apk add --no-cache build-base python" "npm install"

If you think installing all these tools takes too much time, you can use your own build image but do not forget that it has to be close to your deployment image (same operating system and Node.js revisions for instance):

dnpm -w path/to/a/node/project -i custom_image_name "npm install"

An example of an alpine-node image having all the build tools necessary for using node-gyp is erdii/nodejs-alpine-buildtools.

The alternate image must host a user having administration rights (without using su or sudo) as the entry point of dnpm needs to operate bind mounts within the container.

Also note that operating with a user other than root almost certainly means that its home directory will not be /root and that you will have to use the -h option.