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

@tolmasky/dockerscript

v1.0.3

Published

Write your Dockerfile in javascript!

Downloads

10

Readme

dockerscript

Write your Dockerfile in javascript!

Build Status

Install

npm install -g dockerscript

Example dockerfile.js

from('debian', 'wheezy')

maintainer('you', '[email protected]')

env('NGINX_VERSION', '1.7.11-1~wheezy')

run`
  apt-key adv --keyserver pgp.mit.edu --recv-keys 573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62 &&
  echo "deb http://nginx.org/packages/mainline/debian/ wheezy nginx" >> /etc/apt/sources.list &&
  apt-get update &&
  apt-get install -y ca-certificates nginx=$NGINX_VERSION &&
  rm -rf /var/lib/apt/lists/*
`

comment('forward request and error logs to docker log collector')

run`
  ln -sf /dev/stdout /var/log/nginx/access.log &&
  ln -sf /dev/stderr /var/log/nginx/error.log
`

volume('/var/cache/nginx')

expose(80, 443)

cmd("nginx", "-g", "daemon off;")

this turns into:

FROM debian:wheezy

MAINTAINER you <[email protected]>

ENV NGINX_VERSION=1.7.11-1~wheezy

RUN apt-key adv --keyserver pgp.mit.edu --recv-keys 573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62 && \
    echo "deb http://nginx.org/packages/mainline/debian/ wheezy nginx" >> /etc/apt/sources.list && \
    apt-get update && \
    apt-get install -y ca-certificates nginx=$NGINX_VERSION && \
    rm -rf /var/lib/apt/lists/*

# forward request and error logs to docker log collector
RUN ln -sf /dev/stdout /var/log/nginx/access.log && \
    ln -sf /dev/stderr /var/log/nginx/error.log

VOLUME /var/cache/nginx

EXPOSE 80 443

CMD ["nginx","-g","daemon off;"]

Usage

Run the dockerscript command or use the ds alias.

With no arguments, it looks for a dockerfile.js in the current directory and writes to Dockerfile in the current directory.

Your script will be passed through babel so you're free to use es6.

#Simple usage:
$ ls
dockerfile.js
$ ds
$ ls
Dockerfile  dockerfile.js

#If you want to write to a different file, do this:
$ ds mydockerfile.js Dockerfile

#If you want to write to stdout, do this:
$ ds -
FROM ubuntu
...

#If you want to keep error logs, do this:
$ ds input.js Dockerfile.test dockerscript_errors.log

Globals

The following global functions are available to your dockerscript files:

from(name, [tag])

maintainer(name, [email])

run(...commands)

You can use run five different ways:

run('ls '+dir)
run('ls -l '+dir)
run('ls', '-l', dir)
run(['ls', '-l', dir])
run`ls -l ${dir}`

Using template tags you can easily pass in multiple lines. The linebreaks will be escaped for you.

run`
  ls -l ${dir} &&
  touch ${dir}/somethingElse
`

cmd(...commands)

You can use cmd in all of the same ways that you can use run

expose(...ports)

You can specify one port, or multiple.

expose(80)
expose(80, 443)

env(key, value)

You can use env two ways:

env('NODE_VERSION', '0.12.0')
env({
  NODE_VERSION: '0.12.0',
  NPM_VERSION: '2.5.1'
})

add(src..., dest)

Don't worry about path whitespace, I got this.

copy(src..., dest)

Don't worry about path whitespace, I got this.

entrypoint(...commands)

Works just like run and cmd.

volume(...volumes)

Specify one or more.

user(username)

onbuild(callback)

Use it like this:

onbuild(function(){
  run('echo', 'done building!')
})

The callback function will not be called on build, it's just for structure.

Docker doesn't allow multiple onbuild commands, so if you put more than one thing in here it won't work.

include(path)

Grab a partial dockerscript file and include it. You can use this to break up your dockerfiles into manageable and reusable chunks.

Like require, the path is relative to the currently executing script. Unlike require, it does not return any exports. It's just for partials.

Why?

  • it's cool
  • it's trendy
  • it's turing complete
  • it lets you do some fun things
if (process.env.DOCKER_ENV == 'production') {
  include('./monitoring')
  add('./www', '/var/www')
} else if (process.env.DOCKER_ENV == 'development') {
  include('./debugger')
  volume('/var/www')
}

Contributing

Contributors will be rewarded with a lifetime supply of imaginary pizza. :pizza: :pizza: :pizza:

If you send me a pull request that's good, I'll probably merge it.

Please follow some simple guidelines:

  • Run tests with npm test
  • Write tests and put them in the test directory.
  • Don't be a jerk to anybody

If you need help with any of these things, let me know and I'll do my best to help you out.