Skip to content

Commit 4e623d5

Browse files
authored
Merge pull request #209 from linuxserver/swag-auto-proxy-address
2 parents 7453e31 + d1f2f98 commit 4e623d5

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This mod gives SWAG the ability to auto-detect running containers via labels and
1010

1111
## Labels:
1212
- `swag=enable` - required for auto-detection
13+
- `swag_address=containername` - *optional* - overrides upstream app address. Can be set to an IP or a DNS hostname. Defaults to `container name`.
1314
- `swag_port=80` - *optional* - overrides *internal* exposed port
1415
- `swag_proto=http` - *optional* - overrides internal proto (defaults to http)
1516
- `swag_url=containername.domain.com` - *optional* - overrides *server_name* (defaults to `containername.*`)

root/app/auto-proxy.sh

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ else
1313
AUTO_GEN="${CONTAINER} ${AUTO_GEN}"
1414
else
1515
INSPECTION=$(docker inspect ${CONTAINER})
16-
for VAR in swag_port swag_proto swag_url swag_auth swag_auth_bypass; do
16+
for VAR in swag_address swag_port swag_proto swag_url swag_auth swag_auth_bypass; do
1717
VAR_VALUE=$(echo ${INSPECTION} | jq -r ".[0].Config.Labels[\"${VAR}\"]")
1818
if [ "${VAR_VALUE}" == "null" ]; then
1919
VAR_VALUE=""
@@ -40,7 +40,7 @@ fi
4040
for CONTAINER in ${AUTO_GEN}; do
4141
INSPECTION=$(docker inspect ${CONTAINER})
4242
rm -rf "/auto-proxy/${CONTAINER}.conf"
43-
for VAR in swag_port swag_proto swag_url swag_auth swag_auth_bypass; do
43+
for VAR in swag_address swag_port swag_proto swag_url swag_auth swag_auth_bypass; do
4444
VAR_VALUE=$(echo ${INSPECTION} | jq -r ".[0].Config.Labels[\"${VAR}\"]")
4545
if [ "${VAR_VALUE}" == "null" ]; then
4646
VAR_VALUE=""
@@ -54,17 +54,21 @@ for CONTAINER in ${AUTO_GEN}; do
5454
if [ -n "${swag_auth_bypass}" ]; then
5555
echo "**** Swag auth bypass is auto managed via preset confs and cannot be overridden via env vars ****"
5656
fi
57+
if [ -n "${swag_address}" ]; then
58+
sed -i "s|set \$upstream_app .*|set \$upstream_app ${swag_address};|g" "/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
59+
echo "**** Overriding address as ${swag_address} for ${CONTAINER} ****"
60+
fi
5761
if [ -n "${swag_port}" ]; then
5862
sed -i "s|set \$upstream_port .*|set \$upstream_port ${swag_port};|g" "/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
59-
echo "**** Overriding port for ${CONTAINER} ****"
63+
echo "**** Overriding port as ${swag_port} for ${CONTAINER} ****"
6064
fi
6165
if [ -n "${swag_proto}" ]; then
6266
sed -i "s|set \$upstream_proto .*|set \$upstream_proto ${swag_proto};|g" "/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
63-
echo "**** Overriding proto for ${CONTAINER} ****"
67+
echo "**** Overriding proto as ${swag_proto} for ${CONTAINER} ****"
6468
fi
6569
if [ -n "${swag_url}" ]; then
6670
sed -i "s|server_name .*|server_name ${swag_url};|" "/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
67-
echo "**** Overriding url for ${CONTAINER} ****"
71+
echo "**** Overriding url as ${swag_url} for ${CONTAINER} ****"
6872
fi
6973
if [ "${swag_auth}" == "authelia" ]; then
7074
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
100104
done
101105
echo "}" >> "/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
102106
fi
103-
sed -i "s|<container_name>|${CONTAINER}|g" "/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
107+
if [ -z "${swag_address}" ]; then
108+
swag_address="${CONTAINER}"
109+
fi
110+
sed -i "s|<container_name>|${swag_address}|g" "/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
111+
echo "**** Setting upstream address ${swag_address} for ${CONTAINER} ****"
104112
if [ -z "${swag_port}" ]; then
105113
swag_port=$(docker inspect ${CONTAINER} | jq -r '.[0].NetworkSettings.Ports | keys[0]' | sed 's|/.*||')
106114
if [ "${swag_port}" == "null" ]; then

0 commit comments

Comments
 (0)