swipely / iam-docker

Use different IAM roles for each Docker container on an EC2 instance
MIT License
211 stars 22 forks source link

Switch to a multi-stage build process #21

Closed willglynn closed 6 years ago

willglynn commented 6 years ago

Docker supports multi-stage builds. This PR changes iam-docker to use that feature.

The target image is still FROM scratch, so the output is just like it was before – but instead of needing make to drive the process, everything happens in docker build. Building even does go test now too:

$ docker build -t iam-docker .
Sending build context to Docker daemon  21.05MB
Step 1/12 : FROM golang:1-alpine AS builder
…
Step 7/12 : RUN go test -v ./...
…
Step 9/12 : FROM scratch
…
Successfully built 8eb65057d3d8
Successfully tagged iam-docker:latest

$ docker images | grep iam-docker
iam-docker                           latest              8eb65057d3d8        About a minute ago   9.23MB
swipely/iam-docker                   latest              272535b48f30        14 months ago        14MB

I trimmed down the Makefile, but basically now all it does is:

A side effect of this PR is that iam-docker can now use Docker Hub's automated build system, at which point the Makefile could probably be discarded entirely.

nahiluhmot commented 6 years ago

💯 This looks awesome, I wasn't aware of multistage builds until just now. Merge when ready.