From 5a9b337283393d960e16ce2b673a5cea4de2f6e5 Mon Sep 17 00:00:00 2001 From: Rehan Mahmood Date: Sun, 22 Oct 2023 13:22:26 -0400 Subject: [PATCH] Allow hostnames to be overriden by the environment variable. --- seafile-caddy/Caddyfile | 12 ++++++------ seafile-caddy/Dockerfile | 6 +++++- seafile-caddy/scripts/start.sh | 1 - seafile-caddy/scripts/swarm-dns.sh | 8 ++++---- seahub/Dockerfile | 3 ++- seahub/scripts/start.sh | 10 +++++----- 6 files changed, 22 insertions(+), 18 deletions(-) diff --git a/seafile-caddy/Caddyfile b/seafile-caddy/Caddyfile index 177b739..ed27785 100644 --- a/seafile-caddy/Caddyfile +++ b/seafile-caddy/Caddyfile @@ -3,28 +3,28 @@ } http:// https:// { - reverse_proxy seahub:8000 { + reverse_proxy {$SEAHUB_SERVER_HOST}:8000 { lb_policy header X-Forwarded-For trusted_proxies private_ranges } - reverse_proxy /seafdav* seafile-server:8080 { + reverse_proxy /seafdav* {$SEAFILE_SERVER_HOST}:8080 { header_up Destination https:// http:// trusted_proxies private_ranges } handle_path /seafhttp* { uri strip_prefix seafhttp - reverse_proxy seafile-server:8082 { + reverse_proxy {$SEAFILE_SERVER_HOST}:8082 { trusted_proxies private_ranges } } handle_path /notification* { uri strip_prefix notification - reverse_proxy seafile-server:8083 { + reverse_proxy {$SEAFILE_SERVER_HOST}:8083 { trusted_proxies private_ranges } } - reverse_proxy /media/* seahub-media:80 { + reverse_proxy /media/* {$SEAHUB_MEDIA_SERVER_HOST}:80 { lb_policy header X-Forwarded-For trusted_proxies private_ranges } -} \ No newline at end of file +} diff --git a/seafile-caddy/Dockerfile b/seafile-caddy/Dockerfile index 50af27d..c61f41b 100644 --- a/seafile-caddy/Dockerfile +++ b/seafile-caddy/Dockerfile @@ -8,4 +8,8 @@ COPY Caddyfile /etc/caddy/Caddyfile COPY scripts /scripts RUN chmod u+x /scripts/* -CMD ["/scripts/start.sh"] \ No newline at end of file +ENV SEAFILE_SERVER_HOST=seafile-server +ENV SEAHUB_SERVER_HOST=seahub +ENV SEAHUB_MEDIA_SERVER_HOST=seahub-media + +CMD ["/scripts/start.sh"] diff --git a/seafile-caddy/scripts/start.sh b/seafile-caddy/scripts/start.sh index 390e2f2..409a8dc 100644 --- a/seafile-caddy/scripts/start.sh +++ b/seafile-caddy/scripts/start.sh @@ -3,4 +3,3 @@ /scripts/swarm-dns.sh & caddy run --config /etc/caddy/Caddyfile --adapter caddyfile - diff --git a/seafile-caddy/scripts/swarm-dns.sh b/seafile-caddy/scripts/swarm-dns.sh index c24b221..28d9b79 100644 --- a/seafile-caddy/scripts/swarm-dns.sh +++ b/seafile-caddy/scripts/swarm-dns.sh @@ -6,13 +6,13 @@ if [ "$SWARM_DNS" = true ]; then while true; do - SEAHUB_IPS=$(dig +short seahub | sed -e 's/$/:8000/' | tr ' ' '\n' | sort | tr '\n' ' ') - SEAHUB_MEDIA_IPS=$(dig +short seahub-media | sed -e 's/$/:80/' | tr ' ' '\n' | sort | tr '\n' ' ') + SEAHUB_IPS=$(dig +short $SEAHUB_SERVER_HOST | sed -e 's/$/:8000/' | tr ' ' '\n' | sort | tr '\n' ' ') + SEAHUB_MEDIA_IPS=$(dig +short $SEAHUB_MEDIA_SERVER_HOST | sed -e 's/$/:80/' | tr ' ' '\n' | sort | tr '\n' ' ') cp /etc/caddy/Caddyfile.default /etc/caddy/Caddyfile.tmp - sed -i "s/seahub:8000/$(echo $SEAHUB_IPS)/g" /etc/caddy/Caddyfile.tmp - sed -i "s/seahub-media:80/$(echo $SEAHUB_MEDIA_IPS)/g" /etc/caddy/Caddyfile.tmp + sed -i "s/$SEAHUB_SERVER_HOST:8000/$(echo $SEAHUB_IPS)/g" /etc/caddy/Caddyfile.tmp + sed -i "s/$SEAHUB_MEDIA_SERVER_HOST:80/$(echo $SEAHUB_MEDIA_IPS)/g" /etc/caddy/Caddyfile.tmp if ! diff -q "/etc/caddy/Caddyfile" "/etc/caddy/Caddyfile.tmp"; then rm -f /etc/caddy/Caddyfile diff --git a/seahub/Dockerfile b/seahub/Dockerfile index 507ba8b..8d1d6da 100644 --- a/seahub/Dockerfile +++ b/seahub/Dockerfile @@ -89,9 +89,10 @@ ENV INNER_FILE_SERVER_ROOT=http://seafile-server:8082 ENV SEAHUB_LOG_DIR=/opt/seafile/logs ENV SEAFILE_ADMIN_EMAIL=me@example.com ENV SEAFILE_ADMIN_PASSWORD=asecret +ENV SEAFILE_SERVER_HOST=seafile-server ENV PYTHON=python3 ENV SEAHUB_DIR=/opt/seafile/seafile-server-latest/seahub EXPOSE 8000 -CMD ["/scripts/start.sh"] \ No newline at end of file +CMD ["/scripts/start.sh"] diff --git a/seahub/scripts/start.sh b/seahub/scripts/start.sh index 763954b..1f0142e 100644 --- a/seahub/scripts/start.sh +++ b/seahub/scripts/start.sh @@ -13,20 +13,20 @@ function start_seahub { function start_socat { mkdir -p /opt/seafile/seafile-server-latest/runtime while true; do - while ! nc -z seafile-server 8001 2>/dev/null; do + while ! nc -z ${SEAFILE_SERVER_HOST} 8001 2>/dev/null; do sleep 1 done echo "Starting socat..." - socat -d -d UNIX-LISTEN:/opt/seafile/seafile-server-latest/runtime/seafile.sock,fork,unlink-early TCP:seafile-server:8001,forever,keepalive,keepidle=10,keepintvl=10,keepcnt=2 + socat -d -d UNIX-LISTEN:/opt/seafile/seafile-server-latest/runtime/seafile.sock,fork,unlink-early TCP:${SEAFILE_SERVER_HOST}:8001,forever,keepalive,keepidle=10,keepintvl=10,keepcnt=2 done } function watch_server { while true; do sleep 2 - if ! nc -z seafile-server 8082 2>/dev/null; then + if ! nc -z ${SEAFILE_SERVER_HOST} 8082 2>/dev/null; then /opt/seafile/seafile-server-latest/seahub.sh stop - while ! nc -z seafile-server 8082 2>/dev/null; do + while ! nc -z ${SEAFILE_SERVER_HOST} 8082 2>/dev/null; do sleep 1 done start_seahub & @@ -49,4 +49,4 @@ init_seahub start_seahub & watch_server & logger -keep_running \ No newline at end of file +keep_running