Skip to content

Commit 6288a01

Browse files
committed
PEER-254: Inject env vars into nginx config
1 parent fb80e54 commit 6288a01

File tree

6 files changed

+29
-13
lines changed

6 files changed

+29
-13
lines changed

.env.local

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@ COLLAB_EXPRESS_DB_PORT=5434
1010
MATCHING_PGDATA="/data/collab-db"
1111
MATCHING_EXPRESS_DB_PORT=5434
1212

13+
USER_SERVICE_NAME=user-express
1314
USER_EXPRESS_ENV=compose
1415
USER_EXPRESS_PORT=9001
1516

17+
QUESTION_SERVICE_NAME=question-service
1618
QUESTION_EXPRESS_ENV=compose
1719
QUESTION_EXPRESS_PORT=9002
1820

21+
COLLAB_SERVICE_NAME=collab-service
1922
COLLAB_EXPRESS_ENV=compose
2023
COLLAB_EXPRESS_PORT=9003
2124

docker-compose.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,22 @@ services:
7878
# Frontend
7979

8080
frontend:
81-
image: 'frontend'
8281
container_name: 'frontend'
8382
build:
8483
context: ./frontend
8584
dockerfile: ./frontend.Dockerfile
8685
args:
87-
- VITE_USER_SERVICE
88-
- VITE_QUESTION_SERVICE
86+
- VITE_USER_SERVICE=http://${USER_SERVICE_NAME}:${USER_EXPRESS_PORT}
87+
- VITE_QUESTION_SERVICE=http://${QUESTION_SERVICE_NAME}:${QUESTION_EXPRESS_PORT}
8988
- port=${FRONTEND_PORT}
9089
ports:
9190
- '3000:${FRONTEND_PORT}'
9291
env_file:
9392
- ./frontend/.env.compose
93+
environment:
94+
- VITE_USER_SERVICE=http://${USER_SERVICE_NAME}:${USER_EXPRESS_PORT}
95+
- VITE_QUESTION_SERVICE=http://localhost:${QUESTION_EXPRESS_PORT}
96+
- port=${FRONTEND_PORT}
9497
# depends_on:
9598
# - user-service
9699
networks:

frontend/.env.compose

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FRONTEND_ENV=compose
22

3-
VITE_USER_SERVICE=http://user-service:9001
4-
VITE_QUESTION_SERVICE=http://question-service:9002
3+
# VITE_USER_SERVICE=http://user-service:9001
4+
# VITE_QUESTION_SERVICE=http://question-service:9002
55

6-
FRONTEND_PORT=3000
6+
# FRONTEND_PORT=3000

frontend/entrypoint.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
3+
envsubst '${port} ${VITE_USER_SERVICE} ${VITE_QUESTION_SERVICE}' < /etc/nginx/nginx.conf.template > /etc/nginx/conf.d/default.conf
4+
5+
nginx -g 'daemon off;'

frontend/frontend.Dockerfile

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,14 @@ ENV VITE_QUESTION_SERVICE=${VITE_QUESTION_SERVICE}
1414
RUN npm run build
1515

1616
FROM nginx:stable-alpine
17+
1718
COPY --from=build /app/build /usr/share/nginx/html
18-
COPY ./nginx.conf /etc/nginx/conf.d/default.conf
1919

20-
EXPOSE 3000
21-
CMD ["nginx", "-g", "daemon off;"]
20+
COPY ./nginx.conf.template /etc/nginx/nginx.conf.template
21+
COPY entrypoint.sh /usr/local/bin/
22+
RUN chmod +x /usr/local/bin/entrypoint.sh
23+
24+
ARG port
25+
EXPOSE ${port}
26+
27+
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
11
server {
2-
listen 3000;
2+
listen ${port};
33
location / {
44
root /usr/share/nginx/html;
55
index index.html;
66
try_files $uri $uri/ /index.html;
77
}
88

99
location /user-service/ {
10-
proxy_pass http://host.docker.internal:9001/;
10+
proxy_pass ${VITE_USER_SERVICE};
1111
proxy_set_header Host $host;
1212
proxy_set_header X-Real-IP $remote_addr;
1313
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
1414
proxy_set_header X-Forwarded-Proto $scheme;
1515
}
1616

1717
location /question-service/ {
18-
proxy_pass http://host.docker.internal:9002/;
18+
proxy_pass ${VITE_QUESTION_SERVICE};
1919
proxy_set_header Host $host;
2020
proxy_set_header X-Real-IP $remote_addr;
2121
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
2222
proxy_set_header X-Forwarded-Proto $scheme;
2323
}
2424

25-
# Optionally log details of proxied requests
2625
access_log /var/log/nginx/access.log;
2726
error_log /var/log/nginx/error.log;
2827
}

0 commit comments

Comments
 (0)