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

node-dockerfile

v0.7.1

Published

A dockerfile composer using Node

Downloads

8

Readme

Node-dockerfile

NPM version Travis build status
A small library for programmatic generation of Dockerfiles using Node.

Node-dockerfile allows you to dynamically create Dockerfile files.
This library was designed to allow us to dynamically create docker images to assist deployment automation.

Written in TypeScript by Carl Winkler

Installation

npm install node-dockerfile --save

Example usage

import { Builder } from 'node-dockerfile'
const dockerfile = new Builder();

// Let's just add in a bunch of funky commands for a bit of fun
dockerfile
	.from("node:6")
	.newLine()
	.envs([
		{ key: 'NODE_ENV', value: 'developlement' },
		{ key: 'APP_ENV', value: 'dev' }
	])
	.comment("Clone and install dockerfile")
	.run([
		"apt-get install -y git",
		"git clone https://github.com/seikho/node-dockerfile /code/node-dockerfile"
 	])
	.newLine()
	.run(["cd /code/node-dockerfile", "npm install"]);
	.run("npm install -g http-server")
	.env('NODE_ENV', 'production')
	.newLine()
	.workDir("/code/node-dockerfile")
	.cmd("http-server");
	
// .write takes a callback which takes 'error' and 'content'.
// Content being the content of the generated filed.
const cb = function(err, content) {
	if (err) console.log("Failed to write: %s", err);
	else console.log("Successfully wrote the dockerfile!"); 
}
// .write takes 3 arguments: 'location', 'replaceExisting' and the callback above.

dockerfile.write(".", true, cb);

// If all goes well...
// Console: >> 'Successfully wrote to dockerfile!' 

API

from(image: string)

myFdockerfileile.from("ubuntu:latest");
// FROM ubuntu:latest  

maintainer(maintainerName: string)

dockerfile.maintainer("Carl Winkler");
// MAINTAINER Carl Winkler

run(instructions: string|string[])

dockerfile.run("apt-get intall -y curl");
// RUN apt-get install -y curl

// We can create multi-line run commands
dockerfile.run([
	"apt-get install -y git",
	"git clone https://github.com/seikho/node-dockerfile.git"
]);
/**
 * RUN apt-get install -y git \
 * && git clone https://github.com/seikho/node-dockerfile.git
 */

comment(comment: string) Adds a comment to the file

dockerfile.comment("This is a comment");
// # This is a comment

newLine() Adds a new line to the Dockerfile -- purely cosmetic

cmd(instructions: string|string[])

dockerfile.cmd("node --harmony index.js");
// CMD node --harmony index.js

dockerfile.cmd(["node", "--harmony", "index.js"]);
// '["node", "--harmony", "index.js"]'

label(key: string, label: string)

dockerfile.label("someLabel", "someValue");
// LABEL someLabel=someValue

expose(port: number)

dockerfile.expose(8080);
// EXPOSE 8080

arg(key: string, value: string)

dockerfile.arg("user", "docker");
// ARG user=docker

envs(pairs: Array<{ key: string, value: string }>)

dockerfile.envs([
		{ key: "DOCKER_CERT_PATH", value: "/root/.docker/" },
		{ key: "NODE_ENV", value: "DEVELOPMENT" }
	]);
// ENV DOCKER_CERT_PATH="/root/.docker/" \ NODE_ENV="development"

env(key: string, value: string)

dockerfile.env("DOCKER_CERT_PATH", "/root/.docker/");
// ENV DOCKER_CERT_PATH="/root/.docker/"

add(source: string, destination: string)

dockerfile.add("hom*", "/mydir");
// ADD hom* /mydir/

copy(source: string, destination: string)

// current working directory: /home/carl/projects/node-dockerfile
var dynamicPath = path.resolve("../my-library"); // /home/carl/projects/my-library
dockerfile.copy(dynamicPath, "/code/my-library");
// COPY /home/carl/projects/my-library /code/my-library

entryPoint(instructions: string|string[])

dockerfile.entryPoint("top -b");
// ENTRYPOINT top -b

dockerfile.entryPoint(["top","-b"]);
// ENTRYPOINT ["top", "-b"]

volume(volume: string)

dockerfile.volume("/some/volume");
// VOLUME /some/volume

workDir(path: string)

dockerfile.workDir("/some/volume");
// WORKDIR /some/volume

user(user: string)

dockerfile.user("carl");
// USER carl

onBuild(instructions: string)

dockerfile.onBuild("ADD . /app/src");
// ONBUILD ADD . /app/src

write(writeLocation: string, replaceExisting: boolean, callback: (error, content) => void))

dockerfile.write("../my-image", true, function(err, content) {
	if (err) doSomethingElse();
	else doSuccessFunction();
});

writeStream()

var fs = require('fs');

dockerfile.writeStream()
      .pipe(fs.createWriteStream('Dockerfile'));