docker-required

Personalize Dockerfiles

npm install docker-required
2 downloads in the last week
3 downloads in the last month

Problem

The point of a Dockerfile is to declare an executable specification for building a docker image. However, I've run into trouble when my dockerfile statements require values that are unique to an application instance, particularly API tokens and secrets.

This is no good because I want my Dockerfile to declare everything it needs to spin up its linux process. If it requires particular application tokens it should say so. Furthermore, I want to be able to commit this file into my repo without sharing these values with the world.

Solution

required is a command-line tool that generates a Dockerfile for you at build time. Rather than storing a Dockerfile in your repo, you commit a dockerfile template (Dockerfile.in). You then generate a personalized Dockefile by running the required command from the repo directory.

Usage

Take your existing Dockefile and replace personalized values with mustache-like template variables.

1. Templatize your Dockerfile:

Before

FROM ubuntu
ENV MIXPANEL_TOKEN PLACE_TOKEN_HERE

After

FROM ubuntu
ENV MIXPANEL_TOKEN {{ place_token_here }}

2. Define template variables:

Add a required.json file that defines the meaning of each template variable:

{
    "name": "myimage",
    "template": "./Dockerfile.in",
    "context": {
        "place_token_here": {
            "type": "credential",
            "repo": "api.mixpanel.com",
            "name": "token"
        }
    }
}

3. Simplify your deployment:

$ required -o ./Dockerfile
$ docker build -t=myimage .
$ docker run myimage

Required will prompt the user for values and instruct the user on how to obtain any values it can't fetch automatically (such as API tokens that require user-interactions with a web site):

Image

API Support

Required is currently aware of API credentials for:

  • Mixpanel
  • New Relic
  • Balanced
  • Github
  • Mailgun

If you use other APIs, please add an entry by editing db/apis.json and submitting a pull request.

Roadmap

I am trying to build out a web application toolchain on top of Docker that understands my web applications at a system level. A good test for this is to ask your toolchain to fork your application to create an adhoc feature branch. If it can do this by spinning up all the dependent services and isolate state from the mainline app then your toolchain has a pretty good understanding of your application. So forking/branching software systems is the next feature I am working toward.

Follow me for updates.. @EnosFeedler

License

(The MIT License)

Copyright (c) 2014 Jeff Kingyens

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

npm loves you