-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile
64 lines (47 loc) · 1.78 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# --------------------------------------------------------------
FROM golang:1.14 as builder
RUN set -eux; \
apt-get update -y && \
apt-get install -y apt-utils upx;
# Replace Go with boringssl build.
RUN rm -Rf /usr/local/go && cd /usr/local && curl https://go-boringcrypto.storage.googleapis.com/go1.14.1b4.linux-amd64.tar.gz | tar xz;
RUN go version
# Create a non-root privilege account to build
RUN adduser --disabled-password --gecos "" -u 1000 golang && \
mkdir -p $GOPATH/src/workspace && \
chown -R golang:golang $GOPATH/src/workspace;
ENV GOPROXY=https://proxy.golang.org/
WORKDIR $GOPATH/src/workspace
# Clean go cache
RUN go clean --cache && go clean --modcache
# Drop privileges to build
USER golang
# Copy source
COPY --chown=golang:golang . .
# Build hardened binary
RUN go mod tidy && go mod vendor \
&& go build -buildmode=pie -tags netgo -installsuffix netgo --ldflags="-s -w" -o bin/caddy \
&& chmod +x bin/caddy
RUN ldd bin/caddy
# Compress binaries
RUN set -eux; \
upx -9 bin/* && \
chmod +x bin/*
# --------------------------------------------------------------
FROM gcr.io/distroless/base:latest
# Metadata
LABEL \
org.label-schema.build-date=$BUILD_DATE \
org.label-schema.name="CaddyServer" \
org.label-schema.description="Custom prepared caddy webserver" \
org.label-schema.url="https://go.zenithar.org/webserver" \
org.label-schema.vcs-url="https://github.com/Zenithar/go-webserver.git" \
org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.vendor="Thibault NORMAND" \
org.label-schema.version=$VERSION \
org.label-schema.schema-version="1.0" \
org.zenithar.licence="APL2"
COPY --from=builder --chown=root:root /go/src/workspace/bin/caddy /usr/bin/
USER nobody:nobody
ENTRYPOINT [ "/usr/bin/caddy" ]
CMD [ "-h" ]