Skip to content

Commit 9d3bda7

Browse files
committed
Merge branch 'staging' into fix-timer
2 parents bf9ce45 + 74baa54 commit 9d3bda7

File tree

7 files changed

+94
-12
lines changed

7 files changed

+94
-12
lines changed

apps/README.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,21 @@ In the `./apps` directory:
1616
```plaintext
1717
.
1818
├── docker-compose.yml # Docker Compose configuration
19+
├── README.md # Project documentation (for docker compose)
1920
├── .env # Global environment variables (optional)
2021
├── frontend
2122
│ ├── Dockerfile # Dockerfile for frontend
2223
│ └── ... (other frontend files)
24+
├── matching-service
25+
│ ├── Dockerfile # Dockerfile for matching-service
26+
│ └── ... (other matching-service files)
2327
├── question-service
2428
│ ├── Dockerfile # Dockerfile for question-service
2529
│ └── ... (other question-service files)
2630
├── user-service
2731
│ ├── Dockerfile # Dockerfile for user-service
2832
│ └── ... (other user-service files)
29-
└── README.md # Project documentation (for docker compose)
33+
3034
```
3135

3236
## Docker Compose Setup
@@ -53,6 +57,8 @@ Once running, you can access:
5357
- The **frontend** at http://localhost:3000
5458
- The **user service** at http://localhost:3001
5559
- The **question service** at http://localhost:8080
60+
- The **matching service** at http://localhost:8081
61+
- The **redis service** at http://localhost:6379
5662

5763
3. Stopping Services
5864

@@ -66,20 +72,24 @@ This command will stop and remove the containers, networks, and volumes created
6672

6773
## Troubleshooting
6874

69-
**Common Issues**
75+
### Common Issues
76+
77+
- **Port Conflicts**: If you encounter port conflicts, ensure the host ports specified in docker-compose.yml (e.g., 3000:3000) are not in use by other applications.
78+
- **Environment Variables Not Loaded**: Ensure the `.env` files are in the correct directories as found in the `docker-compose.yml` file.
79+
80+
### Known Issues
7081

71-
- Port Conflicts: If you encounter port conflicts, ensure the host ports specified in docker-compose.yml (e.g., 3000:3000) are not in use by other applications.
72-
- Environment Variables Not Loaded: Ensure the `.env` files are in the correct directories as found in the `docker-compose.yml` file.
82+
- **Mongo DB Connection Failing**: The user service fails to connect to the Mongo DB server on NUS Wi-Fi. To resolve this we have to use another network.
7383

74-
**Logs**
84+
### Logs
7585

7686
You can view the logs for each service using the following command:
7787

7888
```bash
7989
docker-compose logs
8090
```
8191

82-
**Useful Commands**
92+
### Useful Commands
8393

8494
Rebuild a specific service:
8595

apps/docker-compose.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,28 @@ services:
3838
volumes:
3939
- ./question-service:/question-service
4040

41+
matching-service:
42+
build:
43+
context: ./matching-service
44+
dockerfile: Dockerfile
45+
ports:
46+
- 8081:8081
47+
env_file:
48+
- ./matching-service/.env
49+
networks:
50+
- apps_network
51+
volumes:
52+
- ./matching-service:/matching-service
53+
depends_on:
54+
- redis
55+
56+
redis:
57+
image: redis:latest
58+
networks:
59+
- apps_network
60+
ports:
61+
- 6379:6379
62+
container_name: redis-container
63+
4164
networks:
4265
apps_network:

apps/frontend/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Then, follow the `.env.example` file and create a `.env` file in the current dir
2525
```bash
2626
NEXT_PUBLIC_QUESTION_SERVICE_URL="http://localhost:8080"
2727
NEXT_PUBLIC_USER_SERVICE_URL="http://localhost:3001/"
28-
NEXT_PUBLIC_MATCHING_SERVICE_URL="wss://localhost:8081"
28+
NEXT_PUBLIC_MATCHING_SERVICE_URL="ws://localhost:8081"
2929
```
3030

3131
First, run the development server:

apps/matching-service/.env.example

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
PORT=8081
2-
MATCH_TIMEOUT=10
2+
MATCH_TIMEOUT=30
33
JWT_SECRET=you-can-replace-this-with-your-own-secret
4-
REDIS_URL=localhost:6379
4+
5+
# if you are NOT USING docker, use the below url
6+
REDIS_URL=localhost:6379
7+
8+
# if you are USING docker, use the below url
9+
# REDIS_URL=redis-container:6379

apps/matching-service/Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM golang:1.23
2+
3+
WORKDIR /usr/src/app
4+
5+
# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading them in subsequent builds if they change
6+
COPY go.mod go.sum ./
7+
8+
RUN go mod tidy && go mod download && go mod verify
9+
10+
COPY .env /usr/src/app/.env
11+
12+
COPY . .
13+
14+
RUN go build -v -o /usr/local/bin/app ./main.go
15+
16+
EXPOSE 8081
17+
18+
CMD ["app"]

apps/matching-service/README.md

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ go mod tidy
2727
- `PORT`: Specifies the port for the WebSocket server. Default is `8081`.
2828
- `JWT_SECRET`: The secret key used to verify JWT tokens.
2929
- `MATCH_TIMEOUT`: The time in seconds to wait for a match before timing out.
30-
- `REDIS_URL`: The URL for the Redis server. Default is `localhost:6379`.
30+
- `REDIS_URL`: The URL for the Redis server. Default is `localhost:6379`. If you are using docker, use `redis-container:6379`
3131

3232
4. Start a local Redis server:
3333

@@ -121,6 +121,28 @@ Make sure to open the HTML file in a web browser while the WebSocket server is r
121121

122122
You can open one instance of the HTML file in multiple tabs to simulate multiple clients connecting to the server. (In the future: ensure that only one connection is allowed per user)
123123

124-
## Docker Support
124+
## Running the Application via Docker
125125

126-
TODO: Add section for Docker setup and usage instructions.
126+
Before running the following commands, ensure that the URL for the Redis server in `.env` file has been changed to `REDIS_URL=redis-container:6379`
127+
128+
To run the application via Docker, run the following command:
129+
130+
1. Set up the Go Docker container for the matching service
131+
```bash
132+
docker build -f Dockerfile -t match-go-app .
133+
```
134+
135+
2. Create the Docker network for Redis and Go
136+
```bash
137+
docker network create redis-go-network
138+
```
139+
140+
3. Start a new Redis container in detached mode using the Redis image from Docker Hub
141+
```bash
142+
docker run -d --name redis-container --network redis-go-network redis
143+
```
144+
145+
4. Run the Go Docker container for the matching-service
146+
```bash
147+
docker run -d -p 8081:8081 --name go-app-container --network redis-go-network match-go-app
148+
```

apps/user-service/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,3 +303,7 @@ docker ps
303303
# To stop the container, use the container ID from the previous command
304304
docker stop <container_id>
305305
```
306+
307+
### Known Issues with MongoDB
308+
309+
The user service fails to connect to the Mongo DB server on NUS Wi-Fi. To resolve this we have to use another network.

0 commit comments

Comments
 (0)