From 6236ace439c27d20a219cc862fb21d8d45ae8f68 Mon Sep 17 00:00:00 2001 From: Vincent Composieux Date: Sat, 15 Jun 2019 02:06:08 +0200 Subject: [PATCH] Added upx to shrink docker image to ~2MB --- .travis.yml | 2 +- Dockerfile | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 22aff2b..fc3eb62 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,7 +21,7 @@ install: script: - go test -v -race ./... - - if [ "${LATEST}" = "true" ]; then gox -os="linux darwin windows" -arch="386 amd64" -osarch="linux/arm" -output="pihole_exporter-{{.OS}}-{{.Arch}}" -verbose ./...; fi + - if [ "${LATEST}" = "true" ]; then gox -ldflags "-s -w" -os="linux darwin windows" -arch="386 amd64" -osarch="linux/arm" -output="pihole_exporter-{{.OS}}-{{.Arch}}" -verbose ./...; fi deploy: provider: releases diff --git a/Dockerfile b/Dockerfile index c6d6d88..57aff4f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,17 +4,18 @@ WORKDIR /go/src/github.com/eko/pihole-exporter COPY . . RUN apk update && \ - apk --no-cache add git alpine-sdk + apk --no-cache add git alpine-sdk upx RUN GO111MODULE=on go mod vendor -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags '-w' -o binary ./ +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags '-s -w' -o go-binary ./ + +RUN upx -f --brute -o binary go-binary FROM scratch LABEL name="pihole-exporter" WORKDIR /root/ - COPY --from=builder /go/src/github.com/eko/pihole-exporter/binary pihole-exporter CMD ["./pihole-exporter"]