2017-10-09 20:03:30 +08:00
|
|
|
#
|
2019-07-02 13:20:58 +08:00
|
|
|
# Build stage
|
2017-10-09 20:03:30 +08:00
|
|
|
#
|
2019-03-24 23:08:09 +08:00
|
|
|
FROM golang:1.12-alpine as build
|
2017-10-09 20:03:30 +08:00
|
|
|
|
2018-09-17 11:59:29 +08:00
|
|
|
# args
|
2019-08-18 16:32:23 +08:00
|
|
|
ARG version="1.0.2"
|
2019-07-02 13:20:58 +08:00
|
|
|
# add plugin import paths here separated by commas
|
2017-10-09 20:03:30 +08:00
|
|
|
ARG plugins=""
|
2019-07-02 13:20:58 +08:00
|
|
|
ARG telemetry="true"
|
2017-10-09 20:03:30 +08:00
|
|
|
|
2018-09-17 11:59:29 +08:00
|
|
|
# deps
|
2017-10-09 20:03:30 +08:00
|
|
|
RUN apk add --no-cache git
|
|
|
|
|
2019-07-02 13:20:58 +08:00
|
|
|
# build root
|
|
|
|
RUN mkdir /build
|
|
|
|
WORKDIR /build
|
|
|
|
ENV GO111MODULE=on
|
|
|
|
ENV CGO_ENABLED=0
|
2017-10-09 20:03:30 +08:00
|
|
|
|
|
|
|
# plugins
|
2019-07-02 13:20:58 +08:00
|
|
|
COPY go.mod plugger.go ./
|
|
|
|
RUN go run plugger.go -plugins="${plugins}" -telemetry="${telemetry}"
|
2017-10-09 20:03:30 +08:00
|
|
|
|
|
|
|
# build
|
2019-07-02 13:20:58 +08:00
|
|
|
RUN go build
|
2018-09-17 11:53:36 +08:00
|
|
|
RUN mv caddy /
|
2017-10-09 20:03:30 +08:00
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Compress Caddy with upx
|
|
|
|
#
|
|
|
|
FROM debian:stable as compress
|
2017-10-09 18:14:51 +08:00
|
|
|
|
2018-09-17 11:59:29 +08:00
|
|
|
ARG upx_version="3.94"
|
|
|
|
|
|
|
|
# dependencies
|
2017-10-09 18:14:51 +08:00
|
|
|
RUN apt-get update && apt install -y --no-install-recommends \
|
|
|
|
tar \
|
|
|
|
xz-utils \
|
|
|
|
curl \
|
|
|
|
ca-certificates
|
|
|
|
|
2017-10-09 20:46:45 +08:00
|
|
|
# get official upx binary
|
2017-10-09 18:14:51 +08:00
|
|
|
RUN curl --silent --show-error --fail --location -o - \
|
2018-09-17 11:59:29 +08:00
|
|
|
"https://github.com/upx/upx/releases/download/v${upx_version}/upx-${upx_version}-amd64_linux.tar.xz" \
|
2017-10-09 18:14:51 +08:00
|
|
|
| tar --no-same-owner -C /usr/bin/ -xJ \
|
2018-09-17 11:59:29 +08:00
|
|
|
--strip-components 1 upx-${upx_version}-amd64_linux/upx
|
2017-10-09 18:14:51 +08:00
|
|
|
|
2017-10-09 20:46:45 +08:00
|
|
|
# copy and compress
|
2018-09-17 11:53:36 +08:00
|
|
|
COPY --from=build /caddy /usr/bin/caddy
|
2017-10-09 18:14:51 +08:00
|
|
|
RUN /usr/bin/upx --ultra-brute /usr/bin/caddy
|
2017-10-09 20:46:45 +08:00
|
|
|
|
|
|
|
# test
|
2017-10-09 18:14:51 +08:00
|
|
|
RUN /usr/bin/caddy -version
|
|
|
|
|
|
|
|
|
2017-10-09 20:03:30 +08:00
|
|
|
#
|
|
|
|
# Final image
|
|
|
|
#
|
2017-10-09 18:14:51 +08:00
|
|
|
FROM scratch
|
|
|
|
|
2017-10-09 20:46:45 +08:00
|
|
|
# labels
|
2017-10-09 19:26:10 +08:00
|
|
|
LABEL org.label-schema.vcs-url="https://github.com/productionwentdown/caddy"
|
2017-10-09 20:14:04 +08:00
|
|
|
LABEL org.label-schema.version=${version}
|
2017-10-09 19:26:10 +08:00
|
|
|
LABEL org.label-schema.schema-version="1.0"
|
|
|
|
|
2018-09-17 11:59:29 +08:00
|
|
|
# copy binary and ca certs
|
2017-10-09 20:03:30 +08:00
|
|
|
COPY --from=compress /usr/bin/caddy /bin/caddy
|
|
|
|
COPY --from=compress /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
2017-10-09 20:46:45 +08:00
|
|
|
|
|
|
|
# copy default caddyfile
|
2017-10-09 18:48:28 +08:00
|
|
|
COPY Caddyfile /etc/Caddyfile
|
2017-10-09 18:14:51 +08:00
|
|
|
|
2017-10-09 20:46:45 +08:00
|
|
|
# set default caddypath
|
2017-10-09 18:48:28 +08:00
|
|
|
ENV CADDYPATH=/etc/.caddy
|
|
|
|
VOLUME /etc/.caddy
|
2017-10-09 18:14:51 +08:00
|
|
|
|
2017-10-09 20:46:45 +08:00
|
|
|
# serve from /srv
|
2017-10-09 18:48:28 +08:00
|
|
|
WORKDIR /srv
|
2019-08-18 16:32:23 +08:00
|
|
|
EXPOSE 2015
|
2017-10-09 18:14:51 +08:00
|
|
|
|
2018-09-01 16:32:39 +08:00
|
|
|
ENTRYPOINT ["/bin/caddy", "--conf", "/etc/Caddyfile", "--log", "stdout"]
|