Skip to content

Commit 88460d8

Browse files
committed
Merge branch 'main' into anun/docker-question
2 parents 817f69e + cb25c64 commit 88460d8

16 files changed

+187
-36
lines changed

.env.local

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,20 @@ 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-express
1618
QUESTION_EXPRESS_ENV=compose
1719
QUESTION_EXPRESS_PORT=9002
1820

21+
COLLAB_CONTAINER_NAME=collab-express
1922
COLLAB_EXPRESS_ENV=compose
2023
COLLAB_EXPRESS_PORT=9003
2124

2225
MATCHING_EXPRESS_ENV=compose
23-
MATCHING_EXPRESS_PORT=9003
26+
MATCHING_EXPRESS_PORT=9004
27+
28+
FRONTEND_ENV=compose
29+
FRONTEND_PORT=3000

docker-compose.yaml

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,78 +3,80 @@
33
services:
44
# Databases
55
user-db:
6-
hostname: "user-db"
6+
hostname: 'user-db'
77
image: postgres:16.4
8-
container_name: "user-db"
8+
container_name: 'user-db'
99
build:
1010
context: ./backend/user/src/lib/db
1111
env_file:
1212
- ./backend/user/.env.local
1313
volumes:
14-
- "user-db-docker:${USER_PGDATA}"
14+
- 'user-db-docker:${USER_PGDATA}'
1515
restart: unless-stopped
1616
networks:
1717
- user-db-network
1818
healthcheck:
19-
test: ["CMD-SHELL", "pg_isready -U peerprep-user-express -d user"]
19+
test: ['CMD-SHELL', 'pg_isready -U peerprep-user-express -d user']
2020
interval: 10s
2121
retries: 5
2222
start_period: 30s
2323
timeout: 10s
2424

2525
collab-db:
26-
hostname: "collab-db"
27-
image: "postgres:16.4"
28-
container_name: "collab-db"
26+
hostname: 'collab-db'
27+
image: 'postgres:16.4'
28+
container_name: 'collab-db'
2929
build:
3030
context: ./backend/collaboration/src/lib/db
3131
env_file:
3232
- ./backend/collaboration/.env.local
3333
volumes:
34-
- "collab-db-docker:/${COLLAB_PGDATA}"
34+
- 'collab-db-docker:/${COLLAB_PGDATA}'
3535
restart: unless-stopped
3636
networks:
3737
- collab-db-network
3838
healthcheck:
39-
test: ["CMD-SHELL", "pg_isready -U peerprep-collab-express -d collab"]
39+
test: ['CMD-SHELL', 'pg_isready -U peerprep-collab-express -d collab']
4040
interval: 10s
4141
retries: 5
4242
start_period: 30s
4343
timeout: 10s
4444

4545
question-db:
46-
hostname: "question-db"
46+
hostname: 'question-db'
4747
image: postgres:16.4
48-
container_name: "question-db"
48+
container_name: 'question-db'
4949
build:
5050
context: ./backend/question/src/lib/db
5151
env_file:
5252
- ./backend/question/.env.local
5353
volumes:
54-
- "question-db-docker:${QUESTION_PGDATA}"
54+
- 'question-db-docker:${QUESTION_PGDATA}'
5555
restart: unless-stopped
5656
networks:
5757
- question-db-network
58+
ports:
59+
- 5433:5432
5860
healthcheck:
59-
test: ["CMD-SHELL", "pg_isready -U peerprep-qn-express -d question"]
61+
test: ['CMD-SHELL', 'pg_isready -U peerprep-qn-express -d question']
6062
interval: 10s
6163
retries: 5
6264
start_period: 30s
6365
timeout: 10s
6466

6567
# Services
6668
user-service:
67-
image: "user-express"
68-
container_name: "user-express"
69+
image: 'user-express'
70+
container_name: '${USER_SERVICE_NAME}'
6971
build:
7072
context: ./backend/user
7173
dockerfile: express.Dockerfile
7274
target: production
73-
args:
75+
args:
7476
# For building with the correct env vars
7577
- port=${USER_EXPRESS_PORT}
7678
ports:
77-
- "9001:${USER_EXPRESS_PORT}"
79+
- '9001:${USER_EXPRESS_PORT}'
7880
env_file:
7981
- ./backend/user/.env.compose
8082
environment:
@@ -90,9 +92,9 @@ services:
9092
- user-api-network
9193
healthcheck:
9294
test: wget --no-verbose --tries=1 --spider http://localhost:9001/health || exit 1
93-
interval: 30s
94-
timeout: 10s
95-
retries: 5
95+
interval: 30s
96+
timeout: 10s
97+
retries: 5
9698
start_period: 5s
9799

98100
question-service:
@@ -127,6 +129,34 @@ services:
127129
retries: 5
128130
start_period: 5s
129131

132+
# Frontend
133+
134+
frontend:
135+
container_name: 'frontend'
136+
build:
137+
context: ./frontend
138+
dockerfile: ./frontend.Dockerfile
139+
target: production
140+
args:
141+
- FRONTEND_PORT=${FRONTEND_PORT}
142+
ports:
143+
- '3000:${FRONTEND_PORT}'
144+
env_file:
145+
- ./frontend/.env.compose
146+
environment:
147+
- VITE_USER_SERVICE=http://${USER_SERVICE_NAME}:${USER_EXPRESS_PORT}
148+
##to remove localhost once integrating question
149+
- VITE_QUESTION_SERVICE=http://host.docker.internal:${QUESTION_EXPRESS_PORT}
150+
- FRONTEND_PORT=${FRONTEND_PORT}
151+
depends_on:
152+
user-service:
153+
condition: service_healthy
154+
restart: true
155+
networks:
156+
- user-api-network
157+
- question-api-network
158+
- collab-api-network
159+
130160
volumes:
131161
# Persistent Volumes for Databases
132162
user-db-docker:
@@ -136,7 +166,6 @@ volumes:
136166
question-db-docker:
137167
external: true
138168

139-
140169
networks:
141170
# Isolated API Server Networks
142171
user-db-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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FRONTEND_ENV=compose

frontend/.env.docker

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FRONTEND_ENV=local
2+
3+
VITE_USER_SERVICE=http://host.docker.internal:9001
4+
VITE_QUESTION_SERVICE=http://host.docker.internal:9002
5+
FRONTEND_PORT=3000

frontend/.env.local

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
VITE_USER_SERVICE="http://localhost:9001"
2-
VITE_QUESTION_SERVICE="http://localhost:9002"
1+
FRONTEND_ENV=local
2+
3+
VITE_USER_SERVICE=http://localhost:9001
4+
VITE_QUESTION_SERVICE=http://localhost:9002

frontend/README.md

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,33 @@
1-
# React + TypeScript + Vite
1+
# Frontend
22

3-
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
3+
## Running with Docker (Standalone)
44

5-
Currently, two official plugins are available:
5+
1. Run this command to build:
6+
```sh
7+
docker build \
8+
--build-arg VITE_USER_SERVICE=http://host.docker.internal:9001 \
9+
--build-arg VITE_QUESTION_SERVICE=http://host.docker.internal:9002 \
10+
--build-arg FRONTEND_PORT=3000 \
11+
-t frontend-app -f frontend.Dockerfile .
12+
```
13+
2. Run this command, from the root folder:
614

7-
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
8-
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
15+
```sh
16+
make db-up
17+
```
18+
19+
3. Run the necessary migrate and seed commands, if you haven't yet.
20+
21+
4. Run this command to expose the container:
22+
```sh
23+
docker run -p 3000:3000 --env-file ./.env.docker frontend-app
24+
```
25+
26+
## Running with Docker-Compose (Main config)
27+
28+
Edit the variables in the `.env.compose` file and run `make up` from the root folder.
29+
30+
Any startup instructions will be run from `entrypoint.sh` instead.
931

1032
## Expanding the ESLint configuration
1133

@@ -22,7 +44,7 @@ export default tseslint.config({
2244
tsconfigRootDir: import.meta.dirname,
2345
},
2446
},
25-
})
47+
});
2648
```
2749

2850
- Replace `tseslint.configs.recommended` to `tseslint.configs.recommendedTypeChecked` or `tseslint.configs.strictTypeChecked`
@@ -31,7 +53,7 @@ export default tseslint.config({
3153

3254
```js
3355
// eslint.config.js
34-
import react from 'eslint-plugin-react'
56+
import react from 'eslint-plugin-react';
3557

3658
export default tseslint.config({
3759
// Set the react version
@@ -46,5 +68,5 @@ export default tseslint.config({
4668
...react.configs.recommended.rules,
4769
...react.configs['jsx-runtime'].rules,
4870
},
49-
})
71+
});
5072
```

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 '${FRONTEND_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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM node:20-alpine AS build
2+
3+
WORKDIR /app
4+
COPY ./package*.json ./
5+
RUN npm install
6+
COPY ./ ./
7+
8+
RUN npm run build
9+
10+
FROM nginx:stable-alpine AS production
11+
12+
COPY --from=build /app/build /usr/share/nginx/html
13+
14+
COPY ./nginx.conf.template /etc/nginx/nginx.conf.template
15+
COPY entrypoint.sh /usr/local/bin/
16+
RUN chmod +x /usr/local/bin/entrypoint.sh
17+
18+
ARG FRONTEND_PORT
19+
EXPOSE ${FRONTEND_PORT}
20+
21+
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]

frontend/frontend.dev.Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM node:20-alpine
2+
3+
WORKDIR /app/
4+
COPY ./frontend/package*.json ./
5+
RUN npm install
6+
COPY ./frontend/ ./
7+
8+
ARG port
9+
EXPOSE ${port}
10+
11+
CMD ["npm", "run", "dev", "--", "--host"]

0 commit comments

Comments
 (0)