Skip to content

Commit e9a00ec

Browse files
author
Mike Holloway
committed
move back to scratch image to reduce security footprint, remove UPX compression
1 parent f349a1d commit e9a00ec

File tree

2 files changed

+15
-56
lines changed

2 files changed

+15
-56
lines changed

Dockerfile

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ ARG DEBIAN_FRONTEND=noninteractive
1010
ARG caddy_version="v1.0.0"
1111
ARG plugins="cache,expires,git,jwt,prometheus,realip,reauth"
1212

13-
RUN apk add --no-cache --no-progress git
13+
RUN apk add --no-cache --no-progress git ca-certificates
1414

1515
# caddy
1616
RUN git clone https://github.com/mholt/caddy -b "${caddy_version}" /go/src/github.com/mholt/caddy \
@@ -38,46 +38,25 @@ RUN git clone https://github.com/cheekybits/genny /go/src/github.com/cheekybits/
3838
RUN git clone https://github.com/marten-seemann/qpack /go/src/github.com/marten-seemann/qpack
3939
RUN git clone https://github.com/marten-seemann/qtls /go/src/github.com/marten-seemann/qtls
4040

41+
42+
4143
# build with telemetry enabled
4244
RUN cd /go/src/github.com/mholt/caddy/caddy \
4345
&& sed -i 's/h2quic/http3/g' /go/src/github.com/mholt/caddy/caddyhttp/proxy/upstream_test.go \
4446
&& sed -i 's/h2quic/http3/g' /go/src/github.com/mholt/caddy/caddyhttp/proxy/reverseproxy_test.go \
4547
&& sed -i 's/h2quic/http3/g' /go/src/github.com/mholt/caddy/caddyhttp/proxy/proxy_test.go \
4648
&& sed -i 's/h2quic/http3/g' /go/src/github.com/mholt/caddy/caddyhttp/proxy/reverseproxy.go \
4749
&& sed -i 's/h2quic/http3/g' /go/src/github.com/mholt/caddy/caddyhttp/httpserver/server.go \
48-
&& go install
49-
#&& mv caddy /go/bin
50+
&& CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /go/bin/caddy
5051

5152
# test
5253
RUN /go/bin/caddy -version
5354
RUN /go/bin/caddy -plugins
5455

55-
#
56-
# Compress Caddy with UPX
57-
#
58-
FROM debian:stable as compress
59-
60-
# curl, tar
61-
RUN apt-get update && apt install -y --no-install-recommends \
62-
tar \
63-
xz-utils \
64-
curl \
65-
ca-certificates
66-
67-
# get official upx binary
68-
RUN curl --silent --show-error --fail --location -o - \
69-
"https://github.com/upx/upx/releases/download/v3.95/upx-3.95-amd64_linux.tar.xz" \
70-
| tar --no-same-owner -C /usr/bin/ -xJ \
71-
--strip-components 1 upx-3.95-amd64_linux/upx
72-
73-
# copy and compress
74-
COPY --from=build /go/bin/caddy /usr/bin/caddy
75-
RUN /usr/bin/upx --ultra-brute /usr/bin/caddy
76-
7756
#
7857
# Final image
7958
#
80-
FROM alpine:3.9.3
59+
FROM scratch
8160

8261
LABEL org.label-schema.build-date=$BUILD_DATE \
8362
org.label-schema.vcs-url="https://github.com/swarmstack/caddy.git" \
@@ -87,8 +66,8 @@ LABEL org.label-schema.build-date=$BUILD_DATE \
8766
MAINTAINER Mike Holloway <mikeholloway+swarmstack@gmail.com>
8867

8968
# copy caddy binary and ca certs
90-
COPY --from=compress /usr/bin/caddy /bin/caddy
91-
COPY --from=compress /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
69+
COPY --from=build /go/bin/caddy /bin/caddy
70+
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
9271

9372
# copy default caddyfile
9473
COPY Caddyfile /etc/Caddyfile

Dockerfile-no-stats

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ ARG DEBIAN_FRONTEND=noninteractive
1010
ARG caddy_version="v1.0.0"
1111
ARG plugins="cache,expires,git,jwt,prometheus,realip,reauth"
1212

13-
RUN apk add --no-cache --no-progress git
13+
RUN apk add --no-cache --no-progress git ca-certificates
1414

1515
# caddy
1616
RUN git clone https://github.com/mholt/caddy -b "${caddy_version}" /go/src/github.com/mholt/caddy \
@@ -38,46 +38,26 @@ RUN git clone https://github.com/cheekybits/genny /go/src/github.com/cheekybits/
3838
RUN git clone https://github.com/marten-seemann/qpack /go/src/github.com/marten-seemann/qpack
3939
RUN git clone https://github.com/marten-seemann/qtls /go/src/github.com/marten-seemann/qtls
4040

41-
# build without telemetry enabled
41+
42+
43+
# build with telemetry disabled
4244
RUN cd /go/src/github.com/mholt/caddy/caddy \
4345
&& sed -i 's/h2quic/http3/g' /go/src/github.com/mholt/caddy/caddyhttp/proxy/upstream_test.go \
4446
&& sed -i 's/h2quic/http3/g' /go/src/github.com/mholt/caddy/caddyhttp/proxy/reverseproxy_test.go \
4547
&& sed -i 's/h2quic/http3/g' /go/src/github.com/mholt/caddy/caddyhttp/proxy/proxy_test.go \
4648
&& sed -i 's/h2quic/http3/g' /go/src/github.com/mholt/caddy/caddyhttp/proxy/reverseproxy.go \
4749
&& sed -i 's/h2quic/http3/g' /go/src/github.com/mholt/caddy/caddyhttp/httpserver/server.go \
4850
&& sed -i 's/Telemetry = true/Telemetry = false/' /go/src/github.com/mholt/caddy/caddy/caddymain/run.go \
49-
&& go install
51+
&& CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /go/bin/caddy
5052

5153
# test
5254
RUN /go/bin/caddy -version
5355
RUN /go/bin/caddy -plugins
5456

55-
#
56-
# Compress Caddy with UPX
57-
#
58-
FROM debian:stable as compress
59-
60-
# curl, tar
61-
RUN apt-get update && apt install -y --no-install-recommends \
62-
tar \
63-
xz-utils \
64-
curl \
65-
ca-certificates
66-
67-
# get official upx binary
68-
RUN curl --silent --show-error --fail --location -o - \
69-
"https://github.com/upx/upx/releases/download/v3.95/upx-3.95-amd64_linux.tar.xz" \
70-
| tar --no-same-owner -C /usr/bin/ -xJ \
71-
--strip-components 1 upx-3.95-amd64_linux/upx
72-
73-
# copy and compress
74-
COPY --from=build /go/bin/caddy /usr/bin/caddy
75-
RUN /usr/bin/upx --ultra-brute /usr/bin/caddy
76-
7757
#
7858
# Final image
7959
#
80-
FROM alpine:3.9.3
60+
FROM scratch
8161

8262
LABEL org.label-schema.build-date=$BUILD_DATE \
8363
org.label-schema.vcs-url="https://github.com/swarmstack/caddy.git" \
@@ -87,8 +67,8 @@ LABEL org.label-schema.build-date=$BUILD_DATE \
8767
MAINTAINER Mike Holloway <mikeholloway+swarmstack@gmail.com>
8868

8969
# copy caddy binary and ca certs
90-
COPY --from=compress /usr/bin/caddy /bin/caddy
91-
COPY --from=compress /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
70+
COPY --from=build /go/bin/caddy /bin/caddy
71+
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
9272

9373
# copy default caddyfile
9474
COPY Caddyfile /etc/Caddyfile

0 commit comments

Comments
 (0)