From 702b814cfa79422f89110eb7fca6f907b13ba5d4 Mon Sep 17 00:00:00 2001 From: Brett Randall Date: Wed, 3 Oct 2018 09:00:27 +1000 Subject: [PATCH 1/3] Replaced deprecated MAINTAINER instruction with an equivalent LABEL. Signed-off-by: Brett Randall --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index cd8c5a6..444f858 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ FROM alpine:latest -MAINTAINER MessageBird +LABEL maintainer="support@messagebird.com" # Copy over the binary in the container. ADD bin/pushprom /usr/bin/ From 26ab331e25e0834e13eea7987ebd608aff9692d5 Mon Sep 17 00:00:00 2001 From: Brett Randall Date: Wed, 3 Oct 2018 13:22:38 +1000 Subject: [PATCH 2/3] Build pushprom in Docker. Signed-off-by: Brett Randall --- .dockerignore | 2 ++ Dockerfile | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..02787e9 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +Dockerfile +.travis.yml diff --git a/Dockerfile b/Dockerfile index 444f858..1a359cd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,20 @@ FROM alpine:latest LABEL maintainer="support@messagebird.com" -# Copy over the binary in the container. -ADD bin/pushprom /usr/bin/ +ENV GOPATH=/usr/local + +RUN apk add --no-cache musl-dev go git && \ + go get -u github.com/golang/dep/cmd/dep + +ADD . /usr/local/src/pushprom +WORKDIR /usr/local/src/pushprom + +RUN dep ensure -v && \ + go test && \ + GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build -ldflags "-s -w" -o "/usr/local/bin/pushprom" EXPOSE 9090 9091 # Run -CMD ["/usr/bin/pushprom"] - +CMD ["/usr/local/bin/pushprom"] From 8cd5592ec1c31456af76f9b70209f0bebf553c94 Mon Sep 17 00:00:00 2001 From: Brett Randall Date: Wed, 3 Oct 2018 13:24:28 +1000 Subject: [PATCH 3/3] Split Docker build to multi-phase: builder then a slim final image. Signed-off-by: Brett Randall --- Dockerfile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 1a359cd..e813061 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,5 @@ -FROM alpine:latest +# ##### builder stage ##### +FROM alpine:latest AS builder LABEL maintainer="support@messagebird.com" ENV GOPATH=/usr/local @@ -13,6 +14,10 @@ RUN dep ensure -v && \ go test && \ GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build -ldflags "-s -w" -o "/usr/local/bin/pushprom" +# ##### image stage ##### +FROM alpine:latest +COPY --from=builder /usr/local/bin/pushprom /usr/local/bin/pushprom + EXPOSE 9090 9091 # Run