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:
make test => go test ./...
make docker => docker build -t swipely/iam-docker .
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.
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 needingmake
to drive the process, everything happens indocker build
. Building even doesgo test
now too:I trimmed down the
Makefile
, but basically now all it does is:make test
=>go test ./...
make docker
=>docker build -t swipely/iam-docker .
A side effect of this PR is that
iam-docker
can now use Docker Hub's automated build system, at which point theMakefile
could probably be discarded entirely.