diff --git a/Dockerfile b/Dockerfile index 89e04a66..97ef11e3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,28 @@ -FROM golang:1.12 as builder +# use a builder image for building cloudflare +FROM golang:1.13.3 as builder ENV GO111MODULE=on ENV CGO_ENABLED=0 ENV GOOS=linux -WORKDIR /go/src/github.com/cloudflare/cloudflared/ -RUN apt-get update && apt-get install -y --no-install-recommends upx -# Run after `apt-get update` to improve rebuild scenarios -COPY . . -RUN make cloudflared -RUN upx --no-progress cloudflared -FROM gcr.io/distroless/base -COPY --from=builder /go/src/github.com/cloudflare/cloudflared/cloudflared /usr/local/bin/ +WORKDIR /go/src/github.com/cloudflare/cloudflared/ + +# copy our sources into the builder image +COPY . . + +# compile cloudflared +RUN make cloudflared + +# --- + +# use a distroless base image with glibc +FROM gcr.io/distroless/base-debian10:nonroot + +# copy our compiled binary +COPY --from=builder --chown=nonroot /go/src/github.com/cloudflare/cloudflared/cloudflared /usr/local/bin/ + +# run as non-privileged user +USER nonroot + +# command / entrypoint of container ENTRYPOINT ["cloudflared", "--no-autoupdate"] CMD ["version"]