faradayio / cage

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

Multi-stage `Dockerfile` builds #57

Open emk opened 7 years ago

emk commented 7 years ago

There's an interesting pattern that shows up in several of our internal applications, especially those using Go or Rust. In particular, we have two Dockerfiles:

We may want to make this pattern "official", and provide support for handling it automatically when we invoke cage build.

A possible design

The design could be fairly simple. We might just add something like the following to an individual service:

label:
  io.fdy.cage.build_outputs: "/app/my_static_binary"

...or perhaps instead to config/sources.yml:

myimage:
  prebuild:
    dockerfile: "Dockerfile.prebuild"
    outputs:
      my_static_binary: "/app/my_static_binary"

Then we could simply define a Dockerfile.prebuild in the source directory.

emk commented 7 years ago

@dkastner votes for the source.yml-based design.

emk commented 6 years ago

This is now officially supported upstream! See https://docs.docker.com/engine/userguide/eng-image/multistage-build/

We want to support this, and it should work just fine for ordinary builds. cage test, however, might be a bit more complicated, and we need to think it through.

emk commented 6 years ago

Note that multi-stage builds require Docker 17.05, but ECS is still on 17.03: http://docs.aws.amazon.com/AmazonECS/latest/developerguide/container_agent_versions.html