Skip to content

Commit 842abd7

Browse files
committed
Fix parsed upstream port when using upstream host
* Keep existing behavior if no upstream host * When using upstream host look for 80, 8080, or first exposed container port and use HostPort for upstream
1 parent fad04d1 commit 842abd7

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

root/app/auto-proxy.sh

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,28 @@ DUDE
124124
sed -i "s|<container_name>|${swag_address}|g" "/etc/nginx/http.d/auto-proxy-${CONTAINER_ID}.subdomain.conf"
125125
echo "**** Setting upstream address ${swag_address} for ${CONTAINER_ID} ****"
126126
if [ -z "${swag_port}" ]; then
127-
swag_port=$(docker inspect ${CONTAINER} | jq -r '.[0].NetworkSettings.Ports | keys[0]' | sed 's|/.*||')
128-
if [ "${swag_port}" == "null" ]; then
127+
if [[ -v UPSTREAM_HOST ]];then
128+
# assuming different network.
129+
# Try to find 80
130+
if [ "$(docker inspect ${CONTAINER} | jq -r '.[0].NetworkSettings.Ports | has("80/tcp")')" == "true" ]; then
131+
swag_port="$(docker inspect ${CONTAINER} | jq -r '.[0].NetworkSettings.Ports."80/tcp"[0].HostPort')"
132+
# Try to find 8080
133+
elif [ "$(docker inspect ${CONTAINER} | jq -r '.[0].NetworkSettings.Ports | has("8080/tcp")')" == "true" ]; then
134+
swag_port="$(docker inspect ${CONTAINER} | jq -r '.[0].NetworkSettings.Ports."8080/tcp"[0].HostPort')"
135+
# If there are any exposed ports use the first one found
136+
elif [ "$(docker inspect ${CONTAINER} | jq -r '.[0].NetworkSettings.Ports | to_entries | length')" != "0" ]; then
137+
swag_port="$(docker inspect ${CONTAINER} | jq -r '.[0].NetworkSettings.Ports | to_entries | .[0].value[0].HostPort')"
138+
else
129139
echo "**** No exposed ports found for ${CONTAINER_ID}. Setting reverse proxy port to 80. ****"
130140
swag_port="80"
141+
swag_address="${UPSTREAM_HOST}"
142+
fi
143+
else
144+
swag_port=$(docker inspect ${CONTAINER} | jq -r '.[0].NetworkSettings.Ports | keys[0]' | sed 's|/.*||')
145+
if [ "${swag_port}" == "null" ]; then
146+
echo "**** No exposed ports found for ${CONTAINER_ID}. Setting reverse proxy port to 80. ****"
147+
swag_port="80"
148+
fi
131149
fi
132150
fi
133151
sed -i "s|set \$upstream_port .*|set \$upstream_port ${swag_port};|g" "/etc/nginx/http.d/auto-proxy-${CONTAINER_ID}.subdomain.conf"

0 commit comments

Comments
 (0)