Merge pull request #209 from linuxserver/swag-auto-proxy-address

This commit is contained in:
Roxedus
2021-06-03 21:56:48 +02:00
committed by GitHub
2 changed files with 15 additions and 6 deletions
+1
View File
@@ -10,6 +10,7 @@ This mod gives SWAG the ability to auto-detect running containers via labels and
## Labels:
- `swag=enable` - required for auto-detection
- `swag_address=containername` - *optional* - overrides upstream app address. Can be set to an IP or a DNS hostname. Defaults to `container name`.
- `swag_port=80` - *optional* - overrides *internal* exposed port
- `swag_proto=http` - *optional* - overrides internal proto (defaults to http)
- `swag_url=containername.domain.com` - *optional* - overrides *server_name* (defaults to `containername.*`)
+14 -6
View File
@@ -13,7 +13,7 @@ else
AUTO_GEN="${CONTAINER} ${AUTO_GEN}"
else
INSPECTION=$(docker inspect ${CONTAINER})
for VAR in swag_port swag_proto swag_url swag_auth swag_auth_bypass; do
for VAR in swag_address swag_port swag_proto swag_url swag_auth swag_auth_bypass; do
VAR_VALUE=$(echo ${INSPECTION} | jq -r ".[0].Config.Labels[\"${VAR}\"]")
if [ "${VAR_VALUE}" == "null" ]; then
VAR_VALUE=""
@@ -40,7 +40,7 @@ fi
for CONTAINER in ${AUTO_GEN}; do
INSPECTION=$(docker inspect ${CONTAINER})
rm -rf "/auto-proxy/${CONTAINER}.conf"
for VAR in swag_port swag_proto swag_url swag_auth swag_auth_bypass; do
for VAR in swag_address swag_port swag_proto swag_url swag_auth swag_auth_bypass; do
VAR_VALUE=$(echo ${INSPECTION} | jq -r ".[0].Config.Labels[\"${VAR}\"]")
if [ "${VAR_VALUE}" == "null" ]; then
VAR_VALUE=""
@@ -54,17 +54,21 @@ for CONTAINER in ${AUTO_GEN}; do
if [ -n "${swag_auth_bypass}" ]; then
echo "**** Swag auth bypass is auto managed via preset confs and cannot be overridden via env vars ****"
fi
if [ -n "${swag_address}" ]; then
sed -i "s|set \$upstream_app .*|set \$upstream_app ${swag_address};|g" "/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
echo "**** Overriding address as ${swag_address} for ${CONTAINER} ****"
fi
if [ -n "${swag_port}" ]; then
sed -i "s|set \$upstream_port .*|set \$upstream_port ${swag_port};|g" "/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
echo "**** Overriding port for ${CONTAINER} ****"
echo "**** Overriding port as ${swag_port} for ${CONTAINER} ****"
fi
if [ -n "${swag_proto}" ]; then
sed -i "s|set \$upstream_proto .*|set \$upstream_proto ${swag_proto};|g" "/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
echo "**** Overriding proto for ${CONTAINER} ****"
echo "**** Overriding proto as ${swag_proto} for ${CONTAINER} ****"
fi
if [ -n "${swag_url}" ]; then
sed -i "s|server_name .*|server_name ${swag_url};|" "/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
echo "**** Overriding url for ${CONTAINER} ****"
echo "**** Overriding url as ${swag_url} for ${CONTAINER} ****"
fi
if [ "${swag_auth}" == "authelia" ]; then
sed -i "s|#include /config/nginx/authelia|include /config/nginx/authelia|g" "/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
@@ -100,7 +104,11 @@ DUDE
done
echo "}" >> "/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
fi
sed -i "s|<container_name>|${CONTAINER}|g" "/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
if [ -z "${swag_address}" ]; then
swag_address="${CONTAINER}"
fi
sed -i "s|<container_name>|${swag_address}|g" "/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
echo "**** Setting upstream address ${swag_address} for ${CONTAINER} ****"
if [ -z "${swag_port}" ]; then
swag_port=$(docker inspect ${CONTAINER} | jq -r '.[0].NetworkSettings.Ports | keys[0]' | sed 's|/.*||')
if [ "${swag_port}" == "null" ]; then