faradayio / cage

Develop and deploy complex Docker applications
http://cage.faraday.io
Apache License 2.0
307 stars 26 forks source link

`Dockerfile` templating #56

Open emk opened 7 years ago

emk commented 7 years ago

What we would like upstream, in a perfect world

Original discussion here. We have two GoCD pipelines:

So when we're making official builds, we want:

FROM example/base:$GO_DEPENDENCY_LABEL_BASE

When we're developing locally, it's safe to use:

FROM example/base:latest

One obvious way to implement this would be:

ARG GO_DEPENDENCY_LABEL_BASE=latest
FROM example/base:${GO_DEPENDENCY_LABEL_BASE}

We could then invoke docker build with --build-arg GO_DEPENDENCY_LABEL_BASE=$GO_DEPENDENCY_LABEL_BASE when running under GoCD, allowing us to lock to specified base image.

What we could do in cage

We could support using Handlebars templates in Dockerfile.hbs, as follows:

FROM example/base:{{default env.GO_DEPENDENCY_LABEL_BASE 'latest'}}

We could then automatically pre-process any *.hbs file before building.

philippe-granet commented 7 years ago

You can now use build-time args (ARG) in FROM https://github.com/moby/moby/pull/31352

emk commented 7 years ago

Sweet! I definitely want to try this.