From 614cae70180d3a93db35f626a36cf3b281361114 Mon Sep 17 00:00:00 2001 From: Elton de Souza Date: Tue, 6 Oct 2020 23:29:44 -0400 Subject: [PATCH 1/2] Reduce container size by 4x * using UPX * using -s -w to strip debug flags in prod --- Dockerfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index a19bc5a..ef9abfa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,6 +3,8 @@ ### FROM golang:1.14-alpine AS builder +RUN apk update && apk add upx + ARG component=${component:-key-retrieval} ARG branch ARG revision @@ -10,7 +12,7 @@ ARG revision ENV GO111MODULE=on ENV USER=covidshield ENV UID=10001 -ENV GOLDFLAGS="-X github.com/CovidShield/server/pkg/server.branch=${branch} -X github.com/CovidShield/server/pkg/server.revision=${revision}" +ENV GOLDFLAGS="-s -w -X github.com/CovidShield/server/pkg/server.branch=${branch} -X github.com/CovidShield/server/pkg/server.revision=${revision}" WORKDIR /go/src/github.com/CovidShield/server @@ -25,7 +27,7 @@ RUN adduser \ COPY . . -RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="${GOLDFLAGS}" -o server ./cmd/${component} +RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="${GOLDFLAGS}" -o server ./cmd/${component} && upx server ### # Step 2 - Build From 8e0739d95819fa5f3f195e5abc27d9e2e9f5d9b5 Mon Sep 17 00:00:00 2001 From: Elton de Souza Date: Wed, 7 Oct 2020 00:07:31 -0400 Subject: [PATCH 2/2] Fix DL3018 and DL3019 --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index ef9abfa..7e5618c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ ### FROM golang:1.14-alpine AS builder -RUN apk update && apk add upx +RUN apk add --no-cache upx=3.96-r0 ARG component=${component:-key-retrieval} ARG branch