refactor(docker): optimize Dockerfile (#126)
* refactor(docker): optimize Dockerfile Remove obsolete upx binary compression Run as unprivileged user * Use go 1.13.3 * Use debian buster distroless
This commit is contained in:
parent
cc2a1d1204
commit
789ca6f6f4
31
Dockerfile
31
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 GO111MODULE=on
|
||||||
ENV CGO_ENABLED=0
|
ENV CGO_ENABLED=0
|
||||||
ENV GOOS=linux
|
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
|
WORKDIR /go/src/github.com/cloudflare/cloudflared/
|
||||||
COPY --from=builder /go/src/github.com/cloudflare/cloudflared/cloudflared /usr/local/bin/
|
|
||||||
|
# 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"]
|
ENTRYPOINT ["cloudflared", "--no-autoupdate"]
|
||||||
CMD ["version"]
|
CMD ["version"]
|
||||||
|
|
Loading…
Reference in New Issue