Skip to content

Commit 2489e8d

Browse files
authored
Merge pull request #118 from IABTechLab/sas-UID2-6299-docker-images
variable proxy_pass for multiple environments
2 parents 4200310 + 104c30f commit 2489e8d

File tree

3 files changed

+60
-12
lines changed

3 files changed

+60
-12
lines changed

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ services:
99
container_name: reverse-proxy
1010
environment:
1111
- DOMAIN=${DOMAIN:-sample-dev.com}
12+
- BACKEND_HOST=
1213

1314
# javascript sdk integrations
1415
javascript-sdk-client-side:

tools/reverse-proxy/default.conf.template

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ server {
4242
server_name js-client-side.${DOMAIN} *.js-client-side.${DOMAIN};
4343

4444
location / {
45-
proxy_pass http://localhost:3031;
45+
proxy_pass http://${JS_CLIENT_SIDE_BACKEND}:3031;
4646
proxy_redirect off;
4747
proxy_connect_timeout 5s;
4848
proxy_send_timeout 60s;
@@ -60,7 +60,7 @@ server {
6060
server_name js-client-server.${DOMAIN} *.js-client-server.${DOMAIN};
6161

6262
location / {
63-
proxy_pass http://localhost:3032;
63+
proxy_pass http://${JS_CLIENT_SERVER_BACKEND}:3032;
6464
proxy_redirect off;
6565
proxy_connect_timeout 5s;
6666
proxy_send_timeout 60s;
@@ -78,7 +78,7 @@ server {
7878
server_name js-react.${DOMAIN} *.js-react.${DOMAIN};
7979

8080
location / {
81-
proxy_pass http://localhost:3034;
81+
proxy_pass http://${JS_REACT_CLIENT_SIDE_BACKEND}:3034;
8282
proxy_redirect off;
8383
proxy_connect_timeout 5s;
8484
proxy_send_timeout 60s;
@@ -96,7 +96,7 @@ server {
9696
server_name server-side.${DOMAIN} *.server-side.${DOMAIN};
9797

9898
location / {
99-
proxy_pass http://localhost:3033;
99+
proxy_pass http://${SERVER_SIDE_BACKEND}:3033;
100100
proxy_redirect off;
101101
proxy_connect_timeout 5s;
102102
proxy_send_timeout 60s;
@@ -114,7 +114,7 @@ server {
114114
server_name secure-signals-client-server.${DOMAIN} *.secure-signals-client-server.${DOMAIN};
115115

116116
location / {
117-
proxy_pass http://localhost:3041;
117+
proxy_pass http://${SECURE_SIGNALS_CLIENT_SERVER_BACKEND}:3041;
118118
proxy_redirect off;
119119
proxy_connect_timeout 5s;
120120
proxy_send_timeout 60s;
@@ -132,7 +132,7 @@ server {
132132
server_name secure-signals-client-side.${DOMAIN} *.secure-signals-client-side.${DOMAIN};
133133

134134
location / {
135-
proxy_pass http://localhost:3042;
135+
proxy_pass http://${SECURE_SIGNALS_CLIENT_SIDE_BACKEND}:3042;
136136
proxy_redirect off;
137137
proxy_connect_timeout 5s;
138138
proxy_send_timeout 60s;
@@ -150,7 +150,7 @@ server {
150150
server_name secure-signals-server-side.${DOMAIN} *.secure-signals-server-side.${DOMAIN};
151151

152152
location / {
153-
proxy_pass http://localhost:3043;
153+
proxy_pass http://${SECURE_SIGNALS_SERVER_SIDE_BACKEND}:3043;
154154
proxy_redirect off;
155155
proxy_connect_timeout 5s;
156156
proxy_send_timeout 60s;
@@ -168,7 +168,7 @@ server {
168168
server_name secure-signals-react.${DOMAIN} *.secure-signals-react.${DOMAIN};
169169

170170
location / {
171-
proxy_pass http://localhost:3044;
171+
proxy_pass http://${SECURE_SIGNALS_REACT_CLIENT_SIDE_BACKEND}:3044;
172172
proxy_redirect off;
173173
proxy_connect_timeout 5s;
174174
proxy_send_timeout 60s;
@@ -186,7 +186,7 @@ server {
186186
server_name prebid-client.${DOMAIN} *.prebid-client.${DOMAIN};
187187

188188
location / {
189-
proxy_pass http://localhost:3051;
189+
proxy_pass http://${PREBID_CLIENT_BACKEND}:3051;
190190
proxy_redirect off;
191191
proxy_connect_timeout 10s;
192192
proxy_send_timeout 60s;
@@ -214,7 +214,7 @@ server {
214214
server_name prebid-client-server.${DOMAIN} *.prebid-client-server.${DOMAIN};
215215

216216
location / {
217-
proxy_pass http://localhost:3052;
217+
proxy_pass http://${PREBID_CLIENT_SERVER_BACKEND}:3052;
218218
proxy_redirect off;
219219
proxy_connect_timeout 5s;
220220
proxy_send_timeout 60s;
@@ -232,7 +232,7 @@ server {
232232
server_name prebid-secure-signals.${DOMAIN} *.prebid-secure-signals.${DOMAIN};
233233

234234
location / {
235-
proxy_pass http://localhost:3061;
235+
proxy_pass http://${PREBID_SECURE_SIGNALS_CLIENT_SIDE_BACKEND}:3061;
236236
proxy_redirect off;
237237
proxy_connect_timeout 5s;
238238
proxy_send_timeout 60s;

tools/reverse-proxy/docker-entrypoint.sh

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,55 @@ set -e
44
# Default domain if not set
55
DOMAIN=${DOMAIN:-sample-dev.com}
66

7+
# Default backend host pattern (defaults to localhost for Kubernetes same-pod)
8+
# For Docker Compose with separate containers, set BACKEND_HOST="" to use service names
9+
# Check if BACKEND_HOST is explicitly set to empty string - if so, use service names
10+
# If BACKEND_HOST is unset, it will default to localhost
11+
if [ "${BACKEND_HOST+set}" = "set" ] && [ -z "$BACKEND_HOST" ]; then
12+
# BACKEND_HOST is explicitly set to empty string - use service names for Docker Compose
13+
JS_CLIENT_SIDE_BACKEND=${JS_CLIENT_SIDE_BACKEND:-javascript-sdk-client-side}
14+
JS_CLIENT_SERVER_BACKEND=${JS_CLIENT_SERVER_BACKEND:-javascript-sdk-client-server}
15+
JS_REACT_CLIENT_SIDE_BACKEND=${JS_REACT_CLIENT_SIDE_BACKEND:-javascript-sdk-react-client-side}
16+
SERVER_SIDE_BACKEND=${SERVER_SIDE_BACKEND:-server-side}
17+
SECURE_SIGNALS_CLIENT_SERVER_BACKEND=${SECURE_SIGNALS_CLIENT_SERVER_BACKEND:-google-secure-signals-client-server}
18+
SECURE_SIGNALS_CLIENT_SIDE_BACKEND=${SECURE_SIGNALS_CLIENT_SIDE_BACKEND:-google-secure-signals-client-side}
19+
SECURE_SIGNALS_SERVER_SIDE_BACKEND=${SECURE_SIGNALS_SERVER_SIDE_BACKEND:-google-secure-signals-server-side}
20+
SECURE_SIGNALS_REACT_CLIENT_SIDE_BACKEND=${SECURE_SIGNALS_REACT_CLIENT_SIDE_BACKEND:-google-secure-signals-react-client-side}
21+
PREBID_CLIENT_BACKEND=${PREBID_CLIENT_BACKEND:-prebid-client}
22+
PREBID_CLIENT_SERVER_BACKEND=${PREBID_CLIENT_SERVER_BACKEND:-prebid-client-server}
23+
PREBID_SECURE_SIGNALS_CLIENT_SIDE_BACKEND=${PREBID_SECURE_SIGNALS_CLIENT_SIDE_BACKEND:-prebid-secure-signals-client-side}
24+
else
25+
# BACKEND_HOST is unset (defaults to localhost) or set to a value - use it for all services
26+
BACKEND_HOST_VALUE=${BACKEND_HOST:-localhost}
27+
JS_CLIENT_SIDE_BACKEND=${JS_CLIENT_SIDE_BACKEND:-$BACKEND_HOST_VALUE}
28+
JS_CLIENT_SERVER_BACKEND=${JS_CLIENT_SERVER_BACKEND:-$BACKEND_HOST_VALUE}
29+
JS_REACT_CLIENT_SIDE_BACKEND=${JS_REACT_CLIENT_SIDE_BACKEND:-$BACKEND_HOST_VALUE}
30+
SERVER_SIDE_BACKEND=${SERVER_SIDE_BACKEND:-$BACKEND_HOST_VALUE}
31+
SECURE_SIGNALS_CLIENT_SERVER_BACKEND=${SECURE_SIGNALS_CLIENT_SERVER_BACKEND:-$BACKEND_HOST_VALUE}
32+
SECURE_SIGNALS_CLIENT_SIDE_BACKEND=${SECURE_SIGNALS_CLIENT_SIDE_BACKEND:-$BACKEND_HOST_VALUE}
33+
SECURE_SIGNALS_SERVER_SIDE_BACKEND=${SECURE_SIGNALS_SERVER_SIDE_BACKEND:-$BACKEND_HOST_VALUE}
34+
SECURE_SIGNALS_REACT_CLIENT_SIDE_BACKEND=${SECURE_SIGNALS_REACT_CLIENT_SIDE_BACKEND:-$BACKEND_HOST_VALUE}
35+
PREBID_CLIENT_BACKEND=${PREBID_CLIENT_BACKEND:-$BACKEND_HOST_VALUE}
36+
PREBID_CLIENT_SERVER_BACKEND=${PREBID_CLIENT_SERVER_BACKEND:-$BACKEND_HOST_VALUE}
37+
PREBID_SECURE_SIGNALS_CLIENT_SIDE_BACKEND=${PREBID_SECURE_SIGNALS_CLIENT_SIDE_BACKEND:-$BACKEND_HOST_VALUE}
38+
fi
39+
40+
# Export all variables for envsubst
41+
export DOMAIN
42+
export JS_CLIENT_SIDE_BACKEND
43+
export JS_CLIENT_SERVER_BACKEND
44+
export JS_REACT_CLIENT_SIDE_BACKEND
45+
export SERVER_SIDE_BACKEND
46+
export SECURE_SIGNALS_CLIENT_SERVER_BACKEND
47+
export SECURE_SIGNALS_CLIENT_SIDE_BACKEND
48+
export SECURE_SIGNALS_SERVER_SIDE_BACKEND
49+
export SECURE_SIGNALS_REACT_CLIENT_SIDE_BACKEND
50+
export PREBID_CLIENT_BACKEND
51+
export PREBID_CLIENT_SERVER_BACKEND
52+
export PREBID_SECURE_SIGNALS_CLIENT_SIDE_BACKEND
53+
754
# Substitute environment variables in the template
8-
envsubst '${DOMAIN}' < /etc/nginx/templates/default.conf.template > /etc/nginx/conf.d/default.conf
55+
envsubst '${DOMAIN} ${JS_CLIENT_SIDE_BACKEND} ${JS_CLIENT_SERVER_BACKEND} ${JS_REACT_CLIENT_SIDE_BACKEND} ${SERVER_SIDE_BACKEND} ${SECURE_SIGNALS_CLIENT_SERVER_BACKEND} ${SECURE_SIGNALS_CLIENT_SIDE_BACKEND} ${SECURE_SIGNALS_SERVER_SIDE_BACKEND} ${SECURE_SIGNALS_REACT_CLIENT_SIDE_BACKEND} ${PREBID_CLIENT_BACKEND} ${PREBID_CLIENT_SERVER_BACKEND} ${PREBID_SECURE_SIGNALS_CLIENT_SIDE_BACKEND}' < /etc/nginx/templates/default.conf.template > /etc/nginx/conf.d/default.conf
956

1057
# Test nginx configuration
1158
nginx -t

0 commit comments

Comments
 (0)