Skip to content

Instantly share code, notes, and snippets.

@paulschwoerer
Created March 12, 2020 23:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulschwoerer/6fbe5440e7b76b89ce1b8edca5d843d2 to your computer and use it in GitHub Desktop.
Save paulschwoerer/6fbe5440e7b76b89ce1b8edca5d843d2 to your computer and use it in GitHub Desktop.
FROM golang:1.14.0-alpine as builder
WORKDIR /src
RUN apk add --no-cache \
git \
ca-certificates
ARG CADDY_SOURCE_VERSION=pki
RUN git clone -b $CADDY_SOURCE_VERSION https://github.com/caddyserver/caddy.git --single-branch
WORKDIR /src/caddy/cmd/caddy
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
go build -trimpath -tags netgo -ldflags '-extldflags "-static" -s -w' -o /usr/bin/caddy
# Fetch the latest default welcome page and default Caddy config
FROM alpine:3.11.3 AS fetch-assets
RUN apk add --no-cache git
ARG DIST_COMMIT=4d5728e7a4452d31030336c8e3ad9a006e58af18
WORKDIR /src/dist
RUN git clone https://github.com/caddyserver/dist .
RUN git checkout $DIST_COMMIT
RUN cp config/Caddyfile /Caddyfile
RUN cp welcome/index.html /index.html
FROM alpine:3.11.3 AS alpine
COPY --from=builder /usr/bin/caddy /usr/bin/caddy
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs
COPY --from=fetch-assets /Caddyfile /etc/caddy/Caddyfile
COPY --from=fetch-assets /index.html /usr/share/caddy/index.html
ARG VCS_REF
ARG VERSION
LABEL org.opencontainers.image.revision=$VCS_REF
LABEL org.opencontainers.image.version=$VERSION
LABEL org.opencontainers.image.title=Caddy
LABEL org.opencontainers.image.description="a powerful, enterprise-ready, open source web server with automatic HTTPS written in Go"
LABEL org.opencontainers.image.url=https://caddyserver.com
LABEL org.opencontainers.image.documentation=https://github.com/caddyserver/caddy/wiki/v2:-Documentation
LABEL org.opencontainers.image.vendor="Light Code Labs"
LABEL org.opencontainers.image.licenses=Apache-2.0
LABEL org.opencontainers.image.source="https://github.com/caddyserver/caddy-docker"
EXPOSE 80
EXPOSE 443
EXPOSE 2019
CMD ["caddy", "run", "--config", "/etc/caddy/Caddyfile", "--adapter", "caddyfile"]
FROM scratch AS scratch
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs
COPY --from=builder /usr/bin/caddy /usr/bin/caddy
COPY --from=fetch-assets /Caddyfile /etc/caddy/Caddyfile
COPY --from=fetch-assets /index.html /usr/share/caddy/index.html
ARG VCS_REF
ARG VERSION
LABEL org.opencontainers.image.revision=$VCS_REF
LABEL org.opencontainers.image.version=$VERSION
LABEL org.opencontainers.image.title=Caddy
LABEL org.opencontainers.image.description="a powerful, enterprise-ready, open source web server with automatic HTTPS written in Go"
LABEL org.opencontainers.image.url=https://caddyserver.com
LABEL org.opencontainers.image.documentation=https://github.com/caddyserver/caddy/wiki/v2:-Documentation
LABEL org.opencontainers.image.vendor="Light Code Labs"
LABEL org.opencontainers.image.licenses=Apache-2.0
LABEL org.opencontainers.image.source="https://github.com/caddyserver/caddy-docker"
EXPOSE 80
EXPOSE 443
EXPOSE 2019
ENTRYPOINT ["caddy"]
CMD ["run", "--config", "/etc/caddy/Caddyfile", "--adapter", "caddyfile"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment