From 2943da00e2c4e68e75d42daa734de3ec6a751474 Mon Sep 17 00:00:00 2001 From: YAEGASHI Takeshi Date: Tue, 22 Jan 2019 02:49:41 +0900 Subject: [PATCH 1/3] Build a static binary Update Makefile to build a static binary by default. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 8447dfc..5571c56 100644 --- a/Makefile +++ b/Makefile @@ -43,7 +43,7 @@ dep: build: clean $(BINARY) $(BINARY): - $(GO) build -ldflags="-X main.VERSION=${VERSION}" -o $(BINARY) github.com/pusher/oauth2_proxy + CGO_ENABLED=0 $(GO) build -a -installsuffix cgo -ldflags="-X main.VERSION=${VERSION}" -o $@ github.com/pusher/oauth2_proxy .PHONY: test test: dep lint From cb41a91a65c865ca2c83e5a19ef5d17cdb15f84e Mon Sep 17 00:00:00 2001 From: YAEGASHI Takeshi Date: Tue, 22 Jan 2019 02:50:50 +0900 Subject: [PATCH 2/3] Docker build optimization Update Dockefile to get a much smaller footprint with alpine image. Optimize ordering of build steps to avoid needless downloads. Include CA certificates needed for practical use. --- Dockerfile | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index c3137f5..487d29b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,22 @@ FROM golang:1.11-stretch AS builder -WORKDIR /go/src/github.com/pusher/oauth2_proxy + +# Download tools +RUN wget -O $GOPATH/bin/dep https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64 +RUN chmod +x $GOPATH/bin/dep + +# Copy sources +WORKDIR $GOPATH/src/github.com/pusher/oauth2_proxy COPY . . # Fetch dependencies -RUN wget -O dep https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64 -RUN chmod +x dep -RUN mv dep $GOPATH/bin/dep RUN dep ensure --vendor-only -# Build image -RUN ./configure && make clean oauth2_proxy +# Build binary +RUN ./configure && make build -# Copy binary to debian -FROM debian:stretch +# Copy binary to alpine +FROM alpine:3.8 +RUN apk add --no-cache ca-certificates COPY --from=builder /go/src/github.com/pusher/oauth2_proxy/oauth2_proxy /bin/oauth2_proxy ENTRYPOINT ["/bin/oauth2_proxy"] From ccaa6e96cdd9bbcda44947726eb2c98c4ed8226c Mon Sep 17 00:00:00 2001 From: YAEGASHI Takeshi Date: Tue, 22 Jan 2019 02:53:00 +0900 Subject: [PATCH 3/3] Ignore Dockerfile.dev Dockerfile.dev is ignored by both git and docker for faster development cycle of docker build. --- .dockerignore | 1 + .gitignore | 7 +++++++ 2 files changed, 8 insertions(+) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..f3c61a6 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +Dockerfile.dev diff --git a/.gitignore b/.gitignore index 1f67dee..a5a3c2e 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,10 @@ _testmain.go # Editor swap/temp files .*.swp + +# Dockerfile.dev is ignored by both git and docker +# for faster development cycle of docker build +# cp Dockerfile Dockerfile.dev +# vi Dockerfile.dev +# docker build -f Dockerfile.dev . +Dockerfile.dev