feat: add more granular configuration via env vars

This commit is contained in:
Jan Christian Grünhage 2017-12-15 03:35:21 +01:00
parent 84a0a03ac6
commit d4d2f19b18
Signed by: jcgruenhage
GPG key ID: 6594C449C633D10C
4 changed files with 65 additions and 34 deletions

View file

@ -1,39 +1,43 @@
FROM docker.jcg.re/base-alpine
MAINTAINER Jan Christian Grünhage <jan.christian@gruenhage.xyz>
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"]

View file

@ -0,0 +1,3 @@
:80 {
root /var/www
}

View file

@ -0,0 +1,4 @@
DOMAIN {
root /var/www
tls EMAIL
}

View file

@ -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