Uses multi-stage builds to create images

follows along here loosely:

https://docs.docker.com/develop/develop-images/multistage-build/
https://blog.alexellis.io/mutli-stage-docker-builds/
This commit is contained in:
Stephen McQuay 2018-04-17 15:01:22 -07:00
parent 805db63c76
commit 04e200eb54
Signed by: sm
GPG Key ID: 4E4B72F479BA3CE5
3 changed files with 16 additions and 17 deletions

View File

@ -1,8 +1,13 @@
FROM golang:1.10.1 as build
WORKDIR /go/src/mcquay.me/lim
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -o /usr/local/bin/lim .
FROM alpine:latest FROM alpine:latest
RUN apk --no-cache add ca-certificates RUN apk --no-cache add ca-certificates
WORKDIR / WORKDIR /
COPY build/lim /bin/ COPY --from=build /usr/local/bin/lim /bin/
CMD ["/bin/sh", "-c", "cat /dev/urandom | /bin/lim 16b | xxd"] CMD ["/bin/sh", "-c", "cat /dev/urandom | /bin/lim 16b | xxd"]

View File

@ -1,7 +0,0 @@
FROM golang:1.10.1
WORKDIR /go/src/mcquay.me/lim
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -o /usr/local/bin/lim .

View File

@ -1,19 +1,20 @@
GOFILES := $(shell find . -type f | grep go$$ ) GOFILES := $(shell find . -type f | grep go$$ )
build/lim: build ${GOFILES} build/lim: build build/.docker-image ${GOFILES}
@docker build -t smcquay/lim:build . -f Dockerfile.build > /dev/null @echo "fetching binary from image"
@docker create --name ext smcquay/lim:build > /dev/null @docker create --name ext smcquay/lim:latest > /dev/null
@docker cp ext:/usr/local/bin/lim build/ > /dev/null @docker cp ext:/bin/lim build/ > /dev/null
@docker rm -f ext > /dev/null @docker rm -f ext > /dev/null
@docker image rm smcquay/lim:build > /dev/null @touch build/lim
build/.docker-image: ${GOFILES}
@echo "building docker image"
@docker build --no-cache -t smcquay/lim:latest . > /dev/null
@touch build/.docker-image
build: build:
@mkdir build @mkdir build
.PHONY: docker-image
docker-image: build/lim
@docker build --no-cache -t smcquay/lim:latest . > /dev/null
.PHONY: clean .PHONY: clean
clean: clean:
@rm -rf build @rm -rf build