summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Henderson <dhenderson@gmail.com>2017-06-15 11:14:37 -0400
committerDave Henderson <dhenderson@gmail.com>2017-06-15 11:14:37 -0400
commitaed4fce0fe96e25686dfc43be100c1bbfd3a3986 (patch)
treeaaee9359feea2efc6ee32f50e5b6d88082806618
parent08875b03a59dbd125bc084ed240b07f6ea8cd78b (diff)
Adding slim docker image variant, going back to multi-stage build in anticipation of 17.06 on DockerHub
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
-rw-r--r--.dockerignore4
-rw-r--r--Dockerfile81
-rw-r--r--Makefile7
-rwxr-xr-xhooks/build11
-rwxr-xr-xhooks/post_push3
5 files changed, 64 insertions, 42 deletions
diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 00000000..ecd90a63
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1,4 @@
+Dockerfile
+.vscode
+*.md
+bin/ \ No newline at end of file
diff --git a/Dockerfile b/Dockerfile
index ea7d4802..3d8d97b9 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,31 +1,26 @@
-# TODO: go back to multi-stage build once DockerHub auto-builds support it (probably June?)
-# FROM golang:1.8-alpine AS build
-#
-# RUN mkdir -p /go/src/github.com/hairyhenderson/gomplate
-# WORKDIR /go/src/github.com/hairyhenderson/gomplate
-# COPY . /go/src/github.com/hairyhenderson/gomplate
-#
-# RUN apk add --no-cache \
-# make \
-# git
-#
-# RUN make build
-#
-# FROM alpine:3.5
-#
-# ARG BUILD_DATE
-# ARG VCS_REF
-#
-# LABEL org.label-schema.build-date=$BUILD_DATE \
-# org.label-schema.vcs-ref=$VCS_REF \
-# org.label-schema.vcs-url="https://github.com/hairyhenderson/gomplate"
-#
-# COPY --from=build /go/src/github.com/hairyhenderson/gomplate/bin/gomplate /usr/bin/gomplate
-#
-# ENTRYPOINT [ "gomplate" ]
-#
-# CMD [ "--help" ]
-FROM golang:1.8-alpine
+FROM golang:1.8-alpine AS build
+
+RUN mkdir -p /go/src/github.com/hairyhenderson/gomplate
+WORKDIR /go/src/github.com/hairyhenderson/gomplate
+COPY . /go/src/github.com/hairyhenderson/gomplate
+
+RUN apk add --no-cache \
+ make \
+ git
+
+RUN make build
+
+FROM debian:jessie AS compress
+
+RUN apt-get update -qq
+RUN DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -yq curl xz-utils ca-certificates
+RUN curl -fsSL -o /tmp/upx.tar.xz https://github.com/upx/upx/releases/download/v3.94/upx-3.94-amd64_linux.tar.xz \
+ && tar Jxv -C /tmp --strip-components=1 -f /tmp/upx.tar.xz
+
+COPY --from=build /go/src/github.com/hairyhenderson/gomplate/bin/gomplate /gomplate
+RUN /tmp/upx --lzma /gomplate -o /gomplate-slim
+
+FROM alpine:3.6 AS gomplate
ARG BUILD_DATE
ARG VCS_REF
@@ -34,17 +29,25 @@ LABEL org.label-schema.build-date=$BUILD_DATE \
org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.vcs-url="https://github.com/hairyhenderson/gomplate"
-RUN mkdir -p /go/src/github.com/hairyhenderson/gomplate
-WORKDIR /go/src/github.com/hairyhenderson/gomplate
-COPY . /go/src/github.com/hairyhenderson/gomplate
+COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
+COPY --from=build /go/src/github.com/hairyhenderson/gomplate/bin/gomplate /gomplate
-RUN apk add --no-cache \
- make \
- git \
- && make build \
- && mv /go/src/github.com/hairyhenderson/gomplate/bin/gomplate /usr/bin/gomplate \
- && apk del make git
-
-ENTRYPOINT [ "gomplate" ]
+ENTRYPOINT [ "/gomplate" ]
CMD [ "--help" ]
+
+FROM alpine:3.6 AS gomplate-slim
+
+ARG BUILD_DATE
+ARG VCS_REF
+
+LABEL org.label-schema.build-date=$BUILD_DATE \
+ org.label-schema.vcs-ref=$VCS_REF \
+ org.label-schema.vcs-url="https://github.com/hairyhenderson/gomplate"
+
+COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
+COPY --from=compress /gomplate-slim /gomplate
+
+ENTRYPOINT [ "/gomplate" ]
+
+CMD [ "--help" ] \ No newline at end of file
diff --git a/Makefile b/Makefile
index 2f58d86e..87d2c547 100644
--- a/Makefile
+++ b/Makefile
@@ -9,6 +9,9 @@ VERSION ?= `git describe --abbrev=0 --tags $(git rev-list --tags --max-count=1)
COMMIT_FLAG := -X `go list ./version`.GitCommit=$(COMMIT)
VERSION_FLAG := -X `go list ./version`.Version=$(VERSION)
+GOOS ?= `go version | sed 's/^.*\ \([a-z0-9]*\)\/\([a-z0-9]*\)/\1/'`
+GOARCH ?= `go version | sed 's/^.*\ \([a-z0-9]*\)\/\([a-z0-9]*\)/\2/'`
+
platforms := linux-amd64 linux-386 linux-arm linux-arm64 darwin-amd64 solaris-amd64 windows-amd64.exe windows-386.exe
define gocross
@@ -43,6 +46,10 @@ compress-all:
$(call compress,linux,arm)
$(call compress,windows,amd64)
+compress: build
+ @upx $(PREFIX)/bin/$(PKG_NAME)$(call extension,$(GOOS)) \
+ -o $(PREFIX)/bin/$(PKG_NAME)-slim$(call extension,$(GOOS))
+
build-release: clean build-x compress-all
$(PREFIX)/bin/$(PKG_NAME)_%: $(shell find $(PREFIX) -type f -name '*.go' -not -path "$(PREFIX)/test/*")
diff --git a/hooks/build b/hooks/build
index 185f1c82..e880ff33 100755
--- a/hooks/build
+++ b/hooks/build
@@ -5,6 +5,13 @@
docker version
echo "Build hook running"
-docker build --build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
- --build-arg VCS_REF=`git rev-parse --short HEAD` \
+export BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"`
+export VCS_REF=`git rev-parse --short HEAD`
+docker build --build-arg BUILD_DATE=$BUILD_DATE \
+ --build-arg VCS_REF=$VCS_REF \
+ --target gomplate \
-t $IMAGE_NAME .
+docker build --build-arg BUILD_DATE=$BUILD_DATE \
+ --build-arg VCS_REF=$VCS_REF \
+ --target gomplate-slim \
+ -t $IMAGE_NAME:slim .
diff --git a/hooks/post_push b/hooks/post_push
index 767143d9..981bd891 100755
--- a/hooks/post_push
+++ b/hooks/post_push
@@ -5,5 +5,6 @@
if (git describe --abbrev=0 --exact-match &>/dev/null); then
tag=$(git describe --abbrev=0 --exact-match)
docker tag $IMAGE_NAME $DOCKER_REPO:$tag
- docker push $DOCKER_REPO:$tag
+ docker tag $IMAGE_NAME:slim $DOCKER_REPO:$tag-slim
+ docker push $DOCKER_REPO
fi