Skip to content

Commit fb80e54

Browse files
committed
PEER-254: Update dockerfile and docker-compose
1 parent 1f1d9f1 commit fb80e54

File tree

13 files changed

+62
-26
lines changed

13 files changed

+62
-26
lines changed

docker-compose.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,8 @@ services:
9191
- '3000:${FRONTEND_PORT}'
9292
env_file:
9393
- ./frontend/.env.compose
94-
environment:
95-
- FRONTEND_PORT=PORT
96-
depends_on:
97-
- user-service
94+
# depends_on:
95+
# - user-service
9896
networks:
9997
- user-api-network
10098
- question-api-network

frontend/.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
dist
3+
frontend.*Dockerfile
4+
.dockerignore

frontend/.env.compose

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
FRONTEND_ENV="compose"
1+
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

66
FRONTEND_PORT=3000

frontend/.env.docker

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
FRONTEND_ENV=local
22

3-
VITE_USER_SERVICE="http://localhost:9001"
4-
VITE_QUESTION_SERVICE="http://localhost:9002"
3+
VITE_USER_SERVICE=http://host.docker.internal:9001
4+
VITE_QUESTION_SERVICE=http://host.docker.internal:9002

frontend/.env.local

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
FRONTEND_ENV=local
22

3-
VITE_USER_SERVICE="http://localhost:9001"
4-
VITE_QUESTION_SERVICE="http://localhost:9002"
3+
VITE_USER_SERVICE=http://localhost:9001
4+
VITE_QUESTION_SERVICE=http://localhost:9002

frontend/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
1. Run this command to build:
66
```sh
77
docker build \
8-
-t frontend-local \
9-
--build-arg port=3000 \
10-
-f frontend.Dockerfile .
8+
--build-arg VITE_USER_SERVICE=http://host.docker.internal:9001 \
9+
--build-arg VITE_QUESTION_SERVICE=http://host.docker.internal:9002 \
10+
-t frontend-app -f frontend.Dockerfile .
1111
```
1212
2. Run this command, from the root folder:
1313

frontend/frontend.Dockerfile

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,17 @@ COPY ./package*.json ./
55
RUN npm install
66
COPY ./ ./
77

8+
#ADD Service ENV
89
ARG VITE_USER_SERVICE
910
ARG VITE_QUESTION_SERVICE
1011
ENV VITE_USER_SERVICE=${VITE_USER_SERVICE}
1112
ENV VITE_QUESTION_SERVICE=${VITE_QUESTION_SERVICE}
1213

1314
RUN npm run build
1415

15-
FROM node:20-alpine AS production
16-
RUN npm install -g serve
17-
WORKDIR /app
18-
COPY --from=build /app/dist ./dist
19-
20-
ARG port
21-
EXPOSE ${port}
16+
FROM nginx:stable-alpine
17+
COPY --from=build /app/build /usr/share/nginx/html
18+
COPY ./nginx.conf /etc/nginx/conf.d/default.conf
2219

23-
CMD ["serve", , "-s", "dist"]
20+
EXPOSE 3000
21+
CMD ["nginx", "-g", "daemon off;"]

frontend/nginx.conf

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
server {
2+
listen 3000;
3+
location / {
4+
root /usr/share/nginx/html;
5+
index index.html;
6+
try_files $uri $uri/ /index.html;
7+
}
8+
9+
location /user-service/ {
10+
proxy_pass http://host.docker.internal:9001/;
11+
proxy_set_header Host $host;
12+
proxy_set_header X-Real-IP $remote_addr;
13+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
14+
proxy_set_header X-Forwarded-Proto $scheme;
15+
}
16+
17+
location /question-service/ {
18+
proxy_pass http://host.docker.internal:9002/;
19+
proxy_set_header Host $host;
20+
proxy_set_header X-Real-IP $remote_addr;
21+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
22+
proxy_set_header X-Forwarded-Proto $scheme;
23+
}
24+
25+
# Optionally log details of proxied requests
26+
access_log /var/log/nginx/access.log;
27+
error_log /var/log/nginx/error.log;
28+
}

frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"dev": "env-cmd -f .env.local vite",
77
"build": "tsc -b && vite build",
88
"lint": "eslint .",
9-
"preview": "vite preview --port 5173"
9+
"preview": "vite preview --port 5173 --host 0.0.0.0"
1010
},
1111
"dependencies": {
1212
"@hookform/resolvers": "^3.9.0",

frontend/src/assets/questions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,6 @@ export const questions: Question[] = questionDetails.map((question) => ({
183183
id: question.id,
184184
title: question.title,
185185
difficulty: question.difficulty as 'Easy' | 'Medium' | 'Hard',
186-
topics: question.topics,
186+
topic: question.topics,
187187
attempted: false,
188188
}));

0 commit comments

Comments
 (0)