Skip to content

Commit 36ca35d

Browse files
committed
add support for new label swag_preset_conf
1 parent f15c45c commit 36ca35d

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ This mod gives SWAG the ability to auto-detect running containers via labels and
1717
- `swag_auth=authelia` - *optional* - enables auth methods (options are `authelia`, `authentik`, `ldap` and `http` for basic http auth)
1818
- `swag_auth_bypass=/api,/othersubfolder` - *optional* - bypasses auth for selected subfolders. Comma separated, no spaces.
1919
- `swag_server_custom_directive=custom_directive;` - *optional* - injects the label value as is into the server block of the generated conf. Must be a valid nginx directive, ending with a semi colon.
20+
- `swag_preset_conf=confname` - *optional* - allows defining a preset conf to use if the container name does not match one (if conf name is `radarr.subdomain.conf`, set this value to `radarr`). If container name matches an existing conf, this var will be ignored.
2021

2122

2223
In SWAG docker arguments, set an environment variable `DOCKER_MODS=linuxserver/mods:universal-docker|linuxserver/mods:swag-auto-proxy` and either add a volume mapping for `/var/run/docker.sock:/var/run/docker.sock:ro`, or set an environment var `DOCKER_HOST=remoteaddress`.

root/app/auto-proxy.sh

Lines changed: 13 additions & 5 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_address swag_port swag_proto swag_url swag_auth swag_auth_bypass swag_server_custom_directive; do
16+
for VAR in swag_address swag_port swag_proto swag_url swag_auth swag_auth_bypass swag_server_custom_directive swag_preset_conf; do
1717
VAR_VALUE=$(echo ${INSPECTION} | jq -r ".[0].Config.Labels[\"${VAR}\"]")
1818
if [ "${VAR_VALUE}" == "null" ]; then
1919
VAR_VALUE=""
@@ -40,17 +40,22 @@ 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_address swag_port swag_proto swag_url swag_auth swag_auth_bypass swag_server_custom_directive; do
43+
for VAR in swag_address swag_port swag_proto swag_url swag_auth swag_auth_bypass swag_server_custom_directive swag_preset_conf; do
4444
VAR_VALUE=$(echo ${INSPECTION} | jq -r ".[0].Config.Labels[\"${VAR}\"]")
4545
if [ "${VAR_VALUE}" == "null" ]; then
4646
VAR_VALUE=""
4747
fi
4848
echo "${VAR}=\"${VAR_VALUE}\"" >> "/auto-proxy/${CONTAINER}.conf"
4949
done
5050
. /auto-proxy/${CONTAINER}.conf
51-
if [ -f "/config/nginx/proxy-confs/${CONTAINER}.subdomain.conf.sample" ]; then
52-
cp "/config/nginx/proxy-confs/${CONTAINER}.subdomain.conf.sample" "/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
53-
echo "**** Using preset proxy conf for ${CONTAINER} ****"
51+
if [ -f "/config/nginx/proxy-confs/${CONTAINER}.subdomain.conf.sample" ] || [ -f "/config/nginx/proxy-confs/${swag_preset_conf}.subdomain.conf.sample" ]; then
52+
if [ -f "/config/nginx/proxy-confs/${CONTAINER}.subdomain.conf.sample" ]; then
53+
echo "**** Container name matches a preset proxy conf, using ${CONTAINER}.subdomain.conf for container ${CONTAINER} ****"
54+
cp "/config/nginx/proxy-confs/${CONTAINER}.subdomain.conf.sample" "/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
55+
elif [ -f "/config/nginx/proxy-confs/${swag_preset_conf}.subdomain.conf.sample" ]; then
56+
echo "**** Label swag_preset_conf matches a preset proxy conf, using ${swag_preset_conf}.subdomain.conf for container ${CONTAINER} ****"
57+
cp "/config/nginx/proxy-confs/${swag_preset_conf}.subdomain.conf.sample" "/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
58+
fi
5459
if [ -n "${swag_auth_bypass}" ]; then
5560
echo "**** Swag auth bypass is auto managed via preset confs and cannot be overridden via env vars ****"
5661
fi
@@ -96,6 +101,9 @@ for CONTAINER in ${AUTO_GEN}; do
96101
echo "**** Enabling basic http auth for ${CONTAINER} ****"
97102
fi
98103
else
104+
if [ -n "${swag_preset_conf}" ] && [ ! "/config/nginx/proxy-confs/${swag_preset_conf}.subdomain.conf.sample" ]; then
105+
echo "**** Label swag_preset_conf is set, but no preset proxy conf found with the name ${swag_preset_conf}.subdomain.conf.sample ****"
106+
fi
99107
echo "**** No preset proxy conf found for ${CONTAINER}, generating from scratch ****"
100108
cp "/config/nginx/proxy-confs/_template.subdomain.conf.sample" "/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
101109
if [ -n "${swag_auth_bypass}" ]; then

0 commit comments

Comments
 (0)