From b70e868a2df94133c6a2210b57e0c61beb74525e Mon Sep 17 00:00:00 2001 From: Jan Grewe Date: Sun, 25 Nov 2018 17:51:57 +0100 Subject: [PATCH 1/6] use multi-stage build for Docker images, decreasing the size by >80% --- Dockerfile.magneticod | 12 ++++++------ Dockerfile.magneticow | 7 +++++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Dockerfile.magneticod b/Dockerfile.magneticod index 6d60a65..4c3361a 100644 --- a/Dockerfile.magneticod +++ b/Dockerfile.magneticod @@ -2,7 +2,7 @@ # Start from a Debian image with the latest version of Go installed # and a workspace (GOPATH) configured at /go. -FROM golang:1.10 +FROM golang:1.10 AS build # Copy the local package files to the container's workspace. ADD ./Gopkg.toml /go/src/github.com/boramalper/magnetico/ @@ -20,9 +20,9 @@ RUN make test-persistence RUN make test-magneticod RUN make magneticod -# Run the outyet command by default when the container starts. -ENTRYPOINT ["/go/bin/magneticod"] -CMD [] +FROM alpine:latest +WORKDIR / +COPY --from=build /go/bin/magneticod /magneticod -# Document that the service listens on port 8080. -EXPOSE 8080 +# Run the outyet command by default when the container starts. +ENTRYPOINT ["/magneticod"] diff --git a/Dockerfile.magneticow b/Dockerfile.magneticow index dbea944..6f0ce23 100644 --- a/Dockerfile.magneticow +++ b/Dockerfile.magneticow @@ -20,9 +20,12 @@ RUN make test-persistence RUN make test-magneticow RUN make magneticow +FROM alpine:latest +WORKDIR / +COPY --from=build /go/bin/magneticow /magneticow + # Run the outyet command by default when the container starts. -ENTRYPOINT ["/go/bin/magneticow"] -CMD [] +ENTRYPOINT ["/magneticow"] # Document that the service listens on port 8080. EXPOSE 8080 From f9d61467478d6357afbfbbd0cfb986861c11f241 Mon Sep 17 00:00:00 2001 From: Jan Grewe Date: Sun, 25 Nov 2018 17:54:31 +0100 Subject: [PATCH 2/6] fix: label multicow build stage correctly --- Dockerfile.magneticow | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile.magneticow b/Dockerfile.magneticow index 6f0ce23..05cc796 100644 --- a/Dockerfile.magneticow +++ b/Dockerfile.magneticow @@ -2,7 +2,7 @@ # Start from a Debian image with the latest version of Go installed # and a workspace (GOPATH) configured at /go. -FROM golang:1.10 +FROM golang:1.10 AS build # Copy the local package files to the container's workspace. ADD ./Gopkg.toml /go/src/github.com/boramalper/magnetico/ From 38179c271be356b3eaa17661047fbbc49132b23c Mon Sep 17 00:00:00 2001 From: Jan Grewe Date: Sun, 25 Nov 2018 18:23:40 +0100 Subject: [PATCH 3/6] Fix errors about go-bindata when building magneticow --- Makefile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 45389c1..71bd3cf 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,13 @@ .PHONY: test format magneticod magneticow ensure test-magneticod test-magneticow test-persistence image image-magneticow image-magneticod -all: test magneticod magneticow +all: ensure test magneticod magneticow magneticod: go install --tags fts5 "-ldflags=-s -w" github.com/boramalper/magnetico/cmd/magneticod magneticow: # TODO: minify files! - go-bindata -o="cmd/magneticow/bindata.go" -prefix="cmd/magneticow/data/" cmd/magneticow/data/... + go-bindata -o="cmd/magneticow/bindata.go" -prefix="cmd/magneticow/data/" -pkg="main" cmd/magneticow/data/... go install --tags fts5 "-ldflags=-s -w" github.com/boramalper/magnetico/cmd/magneticow image-magneticod: @@ -21,11 +21,13 @@ image: image-magneticod image-magneticow # Download dependencies ensure: dep ensure -v + go get -u github.com/jteeuwen/go-bindata/... test-magneticod: go test github.com/boramalper/magnetico/cmd/magneticod/... test-magneticow: + go-bindata -o="cmd/magneticow/bindata.go" -prefix="cmd/magneticow/data/" -pkg="main" cmd/magneticow/data/... go test github.com/boramalper/magnetico/cmd/magneticow/... test-persistence: From 11202f1b24d4b7de17bb9c121011e9211b59a044 Mon Sep 17 00:00:00 2001 From: Jan Grewe Date: Sun, 25 Nov 2018 18:46:49 +0100 Subject: [PATCH 4/6] build with alpine, so that it runs in alpine --- Dockerfile.magneticod | 4 +++- Dockerfile.magneticow | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Dockerfile.magneticod b/Dockerfile.magneticod index 4c3361a..3370dad 100644 --- a/Dockerfile.magneticod +++ b/Dockerfile.magneticod @@ -2,7 +2,9 @@ # Start from a Debian image with the latest version of Go installed # and a workspace (GOPATH) configured at /go. -FROM golang:1.10 AS build +FROM golang:1.10-alpine AS build + +RUN apk add --no-cache build-base curl git # Copy the local package files to the container's workspace. ADD ./Gopkg.toml /go/src/github.com/boramalper/magnetico/ diff --git a/Dockerfile.magneticow b/Dockerfile.magneticow index 05cc796..66cfba7 100644 --- a/Dockerfile.magneticow +++ b/Dockerfile.magneticow @@ -2,7 +2,9 @@ # Start from a Debian image with the latest version of Go installed # and a workspace (GOPATH) configured at /go. -FROM golang:1.10 AS build +FROM golang:1.10-alpine AS build + +RUN apk add --no-cache build-base curl git # Copy the local package files to the container's workspace. ADD ./Gopkg.toml /go/src/github.com/boramalper/magnetico/ From 889d7c95d208ff3a37e0142a1a361a645fbeed65 Mon Sep 17 00:00:00 2001 From: "Bora M. Alper" Date: Sun, 30 Dec 2018 10:42:10 +0100 Subject: [PATCH 5/6] Update Makefile Co-Authored-By: jangrewe --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 71bd3cf..eeb7607 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ image: image-magneticod image-magneticow # Download dependencies ensure: dep ensure -v - go get -u github.com/jteeuwen/go-bindata/... + go get -u github.com/kevinburke/go-bindata/... test-magneticod: go test github.com/boramalper/magnetico/cmd/magneticod/... From 6cea6ae9d9fe6e6b0c68712aac7ec7ea69e7efc3 Mon Sep 17 00:00:00 2001 From: Jan Grewe Date: Sun, 30 Dec 2018 11:06:01 +0100 Subject: [PATCH 6/6] Don't run tests when building Docker images. Use maintained go-bindata. --- Dockerfile.magneticod | 2 -- Dockerfile.magneticow | 2 -- Makefile | 1 + 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/Dockerfile.magneticod b/Dockerfile.magneticod index 3370dad..103357d 100644 --- a/Dockerfile.magneticod +++ b/Dockerfile.magneticod @@ -18,8 +18,6 @@ ADD ./cmd/magneticod /go/src/github.com/boramalper/magnetico/cmd/magneticod RUN curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh WORKDIR /go/src/github.com/boramalper/magnetico/ RUN make ensure -RUN make test-persistence -RUN make test-magneticod RUN make magneticod FROM alpine:latest diff --git a/Dockerfile.magneticow b/Dockerfile.magneticow index 66cfba7..933dcda 100644 --- a/Dockerfile.magneticow +++ b/Dockerfile.magneticow @@ -18,8 +18,6 @@ ADD ./cmd/magneticow /go/src/github.com/boramalper/magnetico/cmd/magneticow RUN curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh WORKDIR /go/src/github.com/boramalper/magnetico/ RUN make ensure -RUN make test-persistence -RUN make test-magneticow RUN make magneticow FROM alpine:latest diff --git a/Makefile b/Makefile index 65fab64..7b926b4 100644 --- a/Makefile +++ b/Makefile @@ -22,6 +22,7 @@ image: image-magneticod image-magneticow # Download dependencies ensure: dep ensure -v + go get -u github.com/kevinburke/go-bindata/... vet: go vet github.com/boramalper/magnetico/...