Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to dynamically reload caddy server on config changes #92

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ FROM alpine
MAINTAINER Marios Andreopoulos <marios@landoop.com>

WORKDIR /
VOLUME ["/tmp"]

# Add needed tools
RUN apk add --no-cache ca-certificates wget \
RUN apk add --no-cache ca-certificates wget inotify-tools \
&& echo "progress = dot:giga" | tee /etc/wgetrc

# Add and Setup Caddy webserver
Expand All @@ -24,8 +26,9 @@ RUN wget "$KAFKA_CONNECT_UI_URL" -O /kafka-connect-ui.tar.gz \

# Add configuration and runtime files
ADD Caddyfile /caddy/Caddyfile.template
ADD run.sh /
RUN chmod +x /run.sh
ADD run.sh wait.sh /

RUN chmod +x /run.sh /wait.sh

EXPOSE 8000

Expand Down
5 changes: 5 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ The only option for the UI, is the URL(s) of your Connect cluster(s).
Usually the main reason for using this is when you run the
container with `--net=host`, where you can't use docker's publish
flag (`-p HOST_PORT:8000`).

- `RELOAD[true|false]`

Whether to reload the caddy configuration in case it has been externally changed.

- `CADDY_OPTIONS=[OPTIONS]`

The webserver that powers the image is Caddy. Via this variable
Expand Down
12 changes: 11 additions & 1 deletion docker/run.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/sh

PROXY="${PROXY:-true}"
RELOAD="${RELOAD:-false}"

PROXY_SKIP_VERIFY="${PROXY_SKIP_VERIFY:-false}"
INSECURE_PROXY=""
CADDY_OPTIONS="${CADDY_OPTIONS:-}"
Expand Down Expand Up @@ -99,5 +101,13 @@ http://0.0.0.0:$PORT
EOF
} 1>&2

if echo "$RELOAD" | egrep -sq "true|TRUE|y|Y|yes|YES|1"; then
echo "Enabling watch on caddy config file."
./wait.sh&
exec /caddy/caddy -conf /tmp/Caddyfile -quiet
else
exec /caddy/caddy -conf /tmp/Caddyfile -quiet
fi



exec /caddy/caddy -conf /tmp/Caddyfile -quiet
5 changes: 5 additions & 0 deletions docker/wait.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
inotifywait -m -e modify,close_write /tmp/Caddyfile | while read file; do pkill -USR1 caddy; done