diff --git a/Dockerfile b/Dockerfile index c7fcdd5..05b7587 100755 --- a/Dockerfile +++ b/Dockerfile @@ -1,39 +1,43 @@ FROM docker.jcg.re/base-alpine MAINTAINER Jan Christian Grünhage +ARG CLONE_URL=github.com/mholt/caddy +ARG BRANCH=tags/v0.10.10 + ENV GOPATH=/gopath \ - CADDY_REPO_OWNER=mholt \ - CADDY_REPO_NAME=caddy \ - CADDY_BRANCH=tags/v0.10.10 \ - CADDYPATH=/caddy \ - UID=192 \ - GID=192 + UID=192 \ + GID=192 -ADD plugins.txt /plugins +ADD plugins.txt /plugins -RUN apk upgrade --update \ - && apk add build-base su-exec libcap go git \ - && mkdir -p $GOPATH/src/github.com/$CADDY_REPO_OWNER \ - && cd $GOPATH/src/github.com/$CADDY_REPO_OWNER \ - && git clone https://github.com/$CADDY_REPO_OWNER/$CADDY_REPO_NAME \ - && cd $CADDY_REPO_NAME \ - && git checkout $CADDY_BRANCH \ - && cd caddy/caddymain \ - && export line="$(grep -n "// This is where other plugins get plugged in (imported)" < run.go | sed 's/^\([0-9]\+\):.*$/\1/')" \ - && head -n ${line} run.go > newrun.go \ - && cat /plugins >> newrun.go \ - && line=`expr $line + 1` \ - && tail -n +${line} run.go >> newrun.go \ - && rm -f run.go \ - && mv newrun.go run.go \ - && go get github.com/$CADDY_REPO_OWNER/$CADDY_REPO_NAME/... \ - && mv $GOPATH/bin/caddy /usr/bin \ - && setcap cap_net_bind_service=+ep /usr/bin/caddy \ - && apk del --purge build-base go \ - && mkdir $CADDYPATH \ - && rm -rf $GOPATH /var/cache/apk/* /plugins +RUN apk upgrade --update \ + && apk add \ + build-base \ + su-exec \ + libcap \ + go \ + git \ + bash \ + && mkdir -p ${GOPATH}/src/${CLONE_URL} \ + && cd $GOPATH/src/${CLONE_URL} \ + && git clone https://${CLONE_URL} . \ + && git checkout ${BRANCH} \ + && cd caddy/caddymain \ + && export LINE="$(grep -n "// This is where other plugins get plugged in (imported)" < run.go | sed 's/^\([0-9]\+\):.*$/\1/')" \ + && head -n ${LINE} run.go > newrun.go \ + && cat /plugins >> newrun.go \ + && line=`expr ${LINE} + 1` \ + && tail -n +${LINE} run.go >> newrun.go \ + && rm -f run.go \ + && mv newrun.go run.go \ + && go get ${CLONE_URL}/... \ + && mv $GOPATH/bin/caddy /usr/bin \ + && setcap cap_net_bind_service=+ep /usr/bin/caddy \ + && apk del --purge build-base go \ + && mkdir /caddy \ + && rm -rf $GOPATH /var/cache/apk/* /plugins -ADD root / +ADD root / -EXPOSE 2015 80 443 -VOLUME ["$CADDYPATH"] +EXPOSE 2015 80 443 +VOLUME ["/caddy", "/var/www"] diff --git a/root/etc/Caddyfile.insecure.template b/root/etc/Caddyfile.insecure.template new file mode 100644 index 0000000..a24f595 --- /dev/null +++ b/root/etc/Caddyfile.insecure.template @@ -0,0 +1,3 @@ +:80 { + root /var/www +} diff --git a/root/etc/Caddyfile.secure.template b/root/etc/Caddyfile.secure.template new file mode 100644 index 0000000..e8da6f1 --- /dev/null +++ b/root/etc/Caddyfile.secure.template @@ -0,0 +1,4 @@ +DOMAIN { + root /var/www + tls EMAIL +} diff --git a/root/etc/s6.d/caddy/run b/root/etc/s6.d/caddy/run index 8128727..272eaf8 100755 --- a/root/etc/s6.d/caddy/run +++ b/root/etc/s6.d/caddy/run @@ -1,3 +1,23 @@ -#!/bin/sh -chown -R ${UID}:${GID} /caddy -exec su-exec ${UID}:${GID} /usr/bin/caddy -quic --conf /caddy/Caddyfile +#!/bin/bash +if [[ -z ${CADDYPATH} ]]; then + export CADDYPATH=/caddy +fi +P="--conf /etc/Caddyfile" +if [[ -n ${USE_QUIC} ]]; then + P="-quic $P" +fi +if [[ -n ${LE_STAGING} ]]; then + P="-ca acme-staging.api.letsencrypt.org/directory $P" +fi +chown -R ${UID}:${GID} /var/www +chown -R ${UID}:${GID} ${CADDYPATH} +if [[ ! -f /etc/Caddyfile ]]; then + if [[ -z "$DOMAIN" || -z "$EMAIL" ]]; then + cp /etc/Caddyfile.insecure.template /etc/Caddyfile + else + cp /etc/Caddyfile.secure.template /etc/Caddyfile + sed -i -e "s/DOMAIN/${DOMAIN}/" -e "s/EMAIL/${EMAIL}/" /etc/Caddyfile + fi +fi +cd ${CADDYPATH} +su-exec ${UID}:${GID} /usr/bin/caddy $P