feat: add more granular configuration via env vars
This commit is contained in:
parent
84a0a03ac6
commit
d4d2f19b18
4 changed files with 65 additions and 34 deletions
66
Dockerfile
66
Dockerfile
|
@ -1,39 +1,43 @@
|
||||||
FROM docker.jcg.re/base-alpine
|
FROM docker.jcg.re/base-alpine
|
||||||
MAINTAINER Jan Christian Grünhage <jan.christian@gruenhage.xyz>
|
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 \
|
ENV GOPATH=/gopath \
|
||||||
CADDY_REPO_OWNER=mholt \
|
UID=192 \
|
||||||
CADDY_REPO_NAME=caddy \
|
GID=192
|
||||||
CADDY_BRANCH=tags/v0.10.10 \
|
|
||||||
CADDYPATH=/caddy \
|
|
||||||
UID=192 \
|
|
||||||
GID=192
|
|
||||||
|
|
||||||
ADD plugins.txt /plugins
|
ADD plugins.txt /plugins
|
||||||
|
|
||||||
RUN apk upgrade --update \
|
RUN apk upgrade --update \
|
||||||
&& apk add build-base su-exec libcap go git \
|
&& apk add \
|
||||||
&& mkdir -p $GOPATH/src/github.com/$CADDY_REPO_OWNER \
|
build-base \
|
||||||
&& cd $GOPATH/src/github.com/$CADDY_REPO_OWNER \
|
su-exec \
|
||||||
&& git clone https://github.com/$CADDY_REPO_OWNER/$CADDY_REPO_NAME \
|
libcap \
|
||||||
&& cd $CADDY_REPO_NAME \
|
go \
|
||||||
&& git checkout $CADDY_BRANCH \
|
git \
|
||||||
&& cd caddy/caddymain \
|
bash \
|
||||||
&& export line="$(grep -n "// This is where other plugins get plugged in (imported)" < run.go | sed 's/^\([0-9]\+\):.*$/\1/')" \
|
&& mkdir -p ${GOPATH}/src/${CLONE_URL} \
|
||||||
&& head -n ${line} run.go > newrun.go \
|
&& cd $GOPATH/src/${CLONE_URL} \
|
||||||
&& cat /plugins >> newrun.go \
|
&& git clone https://${CLONE_URL} . \
|
||||||
&& line=`expr $line + 1` \
|
&& git checkout ${BRANCH} \
|
||||||
&& tail -n +${line} run.go >> newrun.go \
|
&& cd caddy/caddymain \
|
||||||
&& rm -f run.go \
|
&& export LINE="$(grep -n "// This is where other plugins get plugged in (imported)" < run.go | sed 's/^\([0-9]\+\):.*$/\1/')" \
|
||||||
&& mv newrun.go run.go \
|
&& head -n ${LINE} run.go > newrun.go \
|
||||||
&& go get github.com/$CADDY_REPO_OWNER/$CADDY_REPO_NAME/... \
|
&& cat /plugins >> newrun.go \
|
||||||
&& mv $GOPATH/bin/caddy /usr/bin \
|
&& line=`expr ${LINE} + 1` \
|
||||||
&& setcap cap_net_bind_service=+ep /usr/bin/caddy \
|
&& tail -n +${LINE} run.go >> newrun.go \
|
||||||
&& apk del --purge build-base go \
|
&& rm -f run.go \
|
||||||
&& mkdir $CADDYPATH \
|
&& mv newrun.go run.go \
|
||||||
&& rm -rf $GOPATH /var/cache/apk/* /plugins
|
&& 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
|
EXPOSE 2015 80 443
|
||||||
VOLUME ["$CADDYPATH"]
|
VOLUME ["/caddy", "/var/www"]
|
||||||
|
|
3
root/etc/Caddyfile.insecure.template
Normal file
3
root/etc/Caddyfile.insecure.template
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
:80 {
|
||||||
|
root /var/www
|
||||||
|
}
|
4
root/etc/Caddyfile.secure.template
Normal file
4
root/etc/Caddyfile.secure.template
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
DOMAIN {
|
||||||
|
root /var/www
|
||||||
|
tls EMAIL
|
||||||
|
}
|
|
@ -1,3 +1,23 @@
|
||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
chown -R ${UID}:${GID} /caddy
|
if [[ -z ${CADDYPATH} ]]; then
|
||||||
exec su-exec ${UID}:${GID} /usr/bin/caddy -quic --conf /caddy/Caddyfile
|
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
|
||||||
|
|
Loading…
Reference in a new issue