From 14e5bd98442e061c3675a43850559dbf250095c6 Mon Sep 17 00:00:00 2001 From: stefanprodan Date: Thu, 9 Jul 2020 20:21:30 +0300 Subject: [PATCH] Use Alpine as container image --- Dockerfile | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/Dockerfile b/Dockerfile index 74eb9d741..76d3051a4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,27 +1,30 @@ -# Build the manager binary FROM golang:1.13 as builder WORKDIR /workspace -# Copy the Go Modules manifests + +# copy modules manifests COPY go.mod go.mod COPY go.sum go.sum -# cache deps before building and copying source so that we don't need to re-download as much -# and so that source changes don't invalidate our downloaded layer + +# cache modules RUN go mod download -# Copy the go source +# copy source code COPY main.go main.go COPY api/ api/ COPY controllers/ controllers/ -# Build -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager main.go +# build +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o helm-controller main.go + +FROM alpine:3.12 + +RUN apk add --no-cache ca-certificates tini + +COPY --from=builder /workspace/helm-controller /usr/local/bin/ + +RUN addgroup -S controller && adduser -S -g controller controller -# Use distroless as minimal base image to package the manager binary -# Refer to https://github.com/GoogleContainerTools/distroless for more details -FROM gcr.io/distroless/static:nonroot -WORKDIR / -COPY --from=builder /workspace/manager . -USER nonroot:nonroot +USER controller -ENTRYPOINT ["/manager"] +ENTRYPOINT [ "/sbin/tini", "--", "helm-controller" ]