Skip to content

Commit

Permalink
add config templating
Browse files Browse the repository at this point in the history
  • Loading branch information
saltydk committed Jan 31, 2024
1 parent 75d40ca commit f22ca91
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,7 @@ ENV ALLOW_RESTARTS=0 \
TASKS=0 \
VERSION=1 \
VOLUMES=0
COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg
COPY docker-entrypoint.sh /
COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg.template

ENTRYPOINT ["/docker-entrypoint.sh"]
32 changes: 32 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/sh
set -e

# Normalize the input for ENABLE_IPV6 to lowercase
ENABLE_IPV6_LOWER=$(echo "$ENABLE_IPV6" | tr '[:upper:]' '[:lower:]')

# Check for different representations of 'true' and set BIND_CONFIG
case "$ENABLE_IPV6_LOWER" in
1|true|yes)
BIND_CONFIG="[::]:2375 v4v6"
;;
*)
BIND_CONFIG=":2375"
;;
esac

# Process the HAProxy configuration template using sed
sed "s/\${BIND_CONFIG}/$BIND_CONFIG/g" /usr/local/etc/haproxy/haproxy.cfg.template > /usr/local/etc/haproxy/haproxy.cfg

# Command-line argument handling
if [ "${1#-}" != "$1" ]; then
set -- haproxy "$@"
fi

if [ "$#" -eq 0 ] || [ "$1" = 'haproxy' ]; then
if [ "$1" = 'haproxy' ]; then
shift
fi
set -- haproxy -W -db "$@"
fi

exec "$@"
2 changes: 1 addition & 1 deletion haproxy.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ backend docker-events
timeout server 0

frontend dockerfrontend
bind :::2375 v4v6
bind ${BIND_CONFIG}
http-request deny unless METH_GET || { env(POST) -m bool }
http-request allow if { path,url_dec -m reg -i ^(/v[\d\.]+)?/containers/[a-zA-Z0-9_.-]+/((stop)|(restart)|(kill)) } { env(ALLOW_RESTARTS) -m bool }
http-request allow if { path,url_dec -m reg -i ^(/v[\d\.]+)?/containers/[a-zA-Z0-9_.-]+/start } { env(ALLOW_START) -m bool }
Expand Down

0 comments on commit f22ca91

Please sign in to comment.