Skip to content

Commit 0c79c46

Browse files
committed
add optional swag_server_custom_directive label
1 parent f044bef commit 0c79c46

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ This mod gives SWAG the ability to auto-detect running containers via labels and
1616
- `swag_url=containername.domain.com` - *optional* - overrides *server_name* (defaults to `containername.*`)
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.
19+
- `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.
1920

2021

2122
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: 12 additions & 2 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; do
16+
for VAR in swag_address swag_port swag_proto swag_url swag_auth swag_auth_bypass swag_server_custom_directive; 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_address 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 swag_server_custom_directive; do
4444
VAR_VALUE=$(echo ${INSPECTION} | jq -r ".[0].Config.Labels[\"${VAR}\"]")
4545
if [ "${VAR_VALUE}" == "null" ]; then
4646
VAR_VALUE=""
@@ -71,6 +71,11 @@ for CONTAINER in ${AUTO_GEN}; do
7171
sed -i "s|server_name .*|server_name ${SED_swag_url};|" "/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
7272
echo "**** Overriding url as ${swag_url} for ${CONTAINER} ****"
7373
fi
74+
if [ -n "${swag_server_custom_directive}" ]; then
75+
SED_swag_server_custom_directive=$(sed -e 's/[&\\|]/\\&/g; s|$|\\|; $s|\\$||' <<<"${swag_server_custom_directive}")
76+
sed -i -e '/include.*ssl.conf;/a\' -e " ${SED_swag_server_custom_directive}" "/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
77+
echo "**** Adding custom directive from the swag_server_custom_directive label for ${CONTAINER} ****"
78+
fi
7479
if [ "${swag_auth}" == "authelia" ]; then
7580
sed -i "s|#include /config/nginx/authelia|include /config/nginx/authelia|g" "/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
7681
echo "**** Enabling Authelia for ${CONTAINER} ****"
@@ -137,6 +142,11 @@ DUDE
137142
SED_swag_url=$(sed -e 's/[&\\|]/\\&/g; s|$|\\|; $s|\\$||' <<<"${swag_url}")
138143
sed -i "s|server_name .*|server_name ${SED_swag_url};|" "/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
139144
echo "**** Setting url ${swag_url} for ${CONTAINER} ****"
145+
if [ -n "${swag_server_custom_directive}" ]; then
146+
SED_swag_server_custom_directive=$(sed -e 's/[&\\|]/\\&/g; s|$|\\|; $s|\\$||' <<<"${swag_server_custom_directive}")
147+
sed -i -e '/include.*ssl.conf;/a\' -e " ${SED_swag_server_custom_directive}" "/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
148+
echo "**** Adding custom directive from the swag_server_custom_directive label for ${CONTAINER} ****"
149+
fi
140150
if [ "${swag_auth}" == "authelia" ]; then
141151
sed -i "s|#include /config/nginx/authelia|include /config/nginx/authelia|g" "/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
142152
echo "**** Enabling Authelia for ${CONTAINER} ****"

0 commit comments

Comments
 (0)