From 2ed757a03891464d049535907505f4be26b4fb04 Mon Sep 17 00:00:00 2001 From: Andrew Schleifer Date: Fri, 17 Aug 2018 16:43:41 -0500 Subject: [PATCH] new build regime * use new makefile style, remove two previous build systems * multi-stage build for the tiniest image --- Dockerfile | 23 ++++++++------------ Makefile | 14 ++++++++++++ README.md | 2 +- build | 6 ------ docker/Dockerfile | 6 ------ docker/build.rb | 40 ----------------------------------- docker/build_image/Dockerfile | 11 ---------- docker/start.sh => start.sh | 2 +- 8 files changed, 25 insertions(+), 79 deletions(-) create mode 100644 Makefile delete mode 100755 build delete mode 100644 docker/Dockerfile delete mode 100644 docker/build.rb delete mode 100644 docker/build_image/Dockerfile rename docker/start.sh => start.sh (90%) diff --git a/Dockerfile b/Dockerfile index 0ff8851..03c39ff 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,11 @@ -FROM alpine:3.5 - -COPY docker/start.sh /bin/start.sh -CMD ["/bin/start.sh"] - +FROM golang:alpine as builder COPY main.go /go/src/github.com/discourse/discourse-auth-proxy/ +RUN apk add git +RUN cd /go/src/github.com/discourse/discourse-auth-proxy \ + && go get \ + && go build -RUN apk add --no-cache -t build-deps build-base git go mercurial \ - && export GOPATH=/go \ - && cd /go/src/github.com/discourse/discourse-auth-proxy \ - && go get \ - && go build -o /bin/discourse-auth-proxy \ - && apk del --purge build-deps \ - # Don't ask me why, but purging the go package leaves behind about - # 8MB of cruft in /usr/lib/go which we have to nuke by hand - && rm -rf /go /usr/lib/go +FROM alpine:latest +COPY --from=builder /go/bin/discourse-auth-proxy /bin/ +COPY start.sh /bin/start.sh +CMD ["/bin/start.sh"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..780df9b --- /dev/null +++ b/Makefile @@ -0,0 +1,14 @@ +IMAGE := discourse/auth-proxy +TAG := $(shell date -u +%Y%m%d.%H%M%S) + +.PHONY: default +default: push + @printf "${IMAGE}:${TAG} ready\n" + +.PHONY: push +push: build + docker push ${IMAGE}:${TAG} + +.PHONY: build +build: + docker build -t ${IMAGE}:${TAG} . diff --git a/README.md b/README.md index b00dc2b..1b9d448 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ Docker Image You may run using docker using ``` -docker run samsaffron/discourse-auth-proxy +docker run discourse/discourse-auth-proxy ``` Running will display configuration instructions diff --git a/build b/build deleted file mode 100755 index d69ce2a..0000000 --- a/build +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -set -e - -docker build --build-arg=http_proxy=$http_proxy -t discourse/auth-proxy . -docker push discourse/auth-proxy diff --git a/docker/Dockerfile b/docker/Dockerfile deleted file mode 100644 index cfb753a..0000000 --- a/docker/Dockerfile +++ /dev/null @@ -1,6 +0,0 @@ -FROM gliderlabs/alpine - -ADD build_image/discourse-auth-proxy /bin/discourse-auth-proxy -ADD start.sh /bin/start.sh - -CMD ["/bin/start.sh"] diff --git a/docker/build.rb b/docker/build.rb deleted file mode 100644 index 067085c..0000000 --- a/docker/build.rb +++ /dev/null @@ -1,40 +0,0 @@ -require 'pty' - -version = "1.0.0" -$nocache = false - -def run(command) - lines = [] - PTY.spawn(command) do |stdin, stdout, pid| - begin - stdin.each do |line| - lines << line - puts line - end - rescue Errno::EIO - # we are done - end - end - - lines -end - - -def build(path) - lines = run("cd #{path} && docker build #{$nocache ? "--no-cache" : ""} .") - lines[-1]["successfully built ".length..-1].strip -end - -img = build("build_image") -pwd = `pwd`.strip -run "docker run --rm -it -v #{pwd}/build_image:/shared #{img}" - -repo = "samsaffron/discourse-auth-proxy" -tag = "#{repo}:#{version}" -latest = "#{repo}:#{latest}" - -img = build(".") -run "docker tag -f #{img} #{tag}" -run "docker tag -f #{img} #{latest}" - - diff --git a/docker/build_image/Dockerfile b/docker/build_image/Dockerfile deleted file mode 100644 index 2f45932..0000000 --- a/docker/build_image/Dockerfile +++ /dev/null @@ -1,11 +0,0 @@ -FROM gliderlabs/alpine - -RUN apk --update add bash git go mercurial -RUN mkdir -p /gopath/src/github.com/discourse && cd /gopath/src/github.com/discourse && git clone https://github.com/discourse/discourse-auth-proxy -ENV GOPATH /gopath -RUN mkdir -p /gopath -RUN cd /gopath/src/github.com/discourse/discourse-auth-proxy && go get -RUN cd /gopath/src/github.com/discourse/discourse-auth-proxy && CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-w' . - -CMD cp /gopath/src/github.com/discourse/discourse-auth-proxy/discourse-auth-proxy /shared - diff --git a/docker/start.sh b/start.sh similarity index 90% rename from docker/start.sh rename to start.sh index 8a1fb84..c4a0494 100755 --- a/docker/start.sh +++ b/start.sh @@ -29,7 +29,7 @@ if [ -z "$GOOD" ]; then echo "SSO_URL=http://someurl" echo "HOST_PORT=3001" echo - echo "docker run -d --restart=always -e ORIGIN_URL=\$ORIGIN_URL -e PROXY_URL=http://0.0.0.0:80 -e SSO_SECRET=\$SSO_SECRET -e SSO_URL=\$SSO_URL -p \$HOST_PORT:80 samsaffron/discourse-auth-proxy" + echo "docker run -d --restart=always -e ORIGIN_URL=\$ORIGIN_URL -e PROXY_URL=http://0.0.0.0:80 -e SSO_SECRET=\$SSO_SECRET -e SSO_URL=\$SSO_URL -p \$HOST_PORT:80 discourse/discourse-auth-proxy" else exec /bin/discourse-auth-proxy fi