Skip to content

Commit 217dc99

Browse files
Merge pull request #47 from CS3219-AY2425S1/staging
Milestone D4
2 parents 73ecfef + 74baa54 commit 217dc99

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+5757
-2864
lines changed

.github/workflows/test.yml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: Run Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- staging
8+
- frontend-websocket-test
9+
pull_request:
10+
branches:
11+
- main
12+
- staging
13+
14+
jobs:
15+
test:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
22+
- name: Set up Docker Compose
23+
run: |
24+
sudo apt-get update
25+
sudo apt-get install -y docker-compose
26+
27+
- name: Create Environment Files
28+
env:
29+
QUESTION_SERVICE_URL: ${{ vars.QUESTION_SERVICE_URL }}
30+
USER_SERVICE_URL: ${{ vars.USER_SERVICE_URL }}
31+
MATCHING_SERVICE_URL: ${{ vars.MATCHING_SERVICE_URL }}
32+
JWT_SECRET: ${{ secrets.JWT_SECRET }}
33+
FIREBASE_CREDENTIAL_PATH: ${{ vars.QUESTION_SERVICE_FIREBASE_CREDENTIAL_PATH }}
34+
DB_CLOUD_URI: ${{ secrets.USER_SERVICE_DB_CLOUD_URI }}
35+
USER_SERVICE_PORT: ${{ vars.USER_SERVICE_PORT }}
36+
MATCHING_SERVICE_PORT: ${{ vars.MATCHING_SERVICE_PORT }}
37+
MATCHING_SERVICE_TIMEOUT: ${{ vars.MATCHING_SERVICE_TIMEOUT }}
38+
REDIS_URL: ${{ vars.REDIS_URL }}
39+
run: |
40+
cd ./apps/frontend
41+
echo "NEXT_PUBLIC_QUESTION_SERVICE_URL=$QUESTION_SERVICE_URL" >> .env
42+
echo "NEXT_PUBLIC_USER_SERVICE_URL=$USER_SERVICE_URL" >> .env
43+
echo "NEXT_PUBLIC_MATCHING_SERVICE_URL=$MATCHING_SERVICE_URL" >> .env
44+
45+
cd ../question-service
46+
echo "FIREBASE_CREDENTIAL_PATH=$FIREBASE_CREDENTIAL_PATH" >> .env
47+
echo "JWT_SECRET=$JWT_SECRET" >> .env
48+
49+
cd ../user-service
50+
echo "DB_CLOUD_URI=$DB_CLOUD_URI" >> .env
51+
echo "PORT=$USER_SERVICE_PORT" >> .env
52+
echo "JWT_SECRET=$JWT_SECRET" >> .env
53+
54+
cd ../matching-service
55+
echo "PORT=$MATCHING_SERVICE_PORT" >> .env
56+
echo "MATCH_TIMEOUT=$MATCHING_SERVICE_TIMEOUT" >> .env
57+
echo "JWT_SECRET=$JWT_SECRET" >> .env
58+
echo "REDIS_URL=$REDIS_URL" >> .env
59+
60+
- name: Create Database Credential Files
61+
env:
62+
FIREBASE_JSON: ${{ secrets.QUESTION_SERVICE_FIREBASE_CREDENTIAL }}
63+
FIREBASE_CREDENTIAL_PATH: ${{ vars.QUESTION_SERVICE_FIREBASE_CREDENTIAL_PATH }}
64+
run: |
65+
cd ./apps/question-service
66+
echo "$FIREBASE_JSON" > "./$FIREBASE_CREDENTIAL_PATH"
67+
68+
- name: Build and Run Services
69+
run: |
70+
cd ./apps
71+
docker-compose up --build -d
72+
73+
- name: Wait for services to be ready
74+
run: sleep 30
75+
76+
- name: Install websocat
77+
run: |
78+
sudo wget -qO /usr/local/bin/websocat https://github.com/vi/websocat/releases/latest/download/websocat.x86_64-unknown-linux-musl
79+
sudo chmod a+x /usr/local/bin/websocat
80+
websocat --version
81+
82+
- name: Run Tests
83+
env:
84+
FRONTEND_URL: ${{ vars.FRONTEND_URL }}
85+
USER_SERVICE_URL: ${{ vars.USER_SERVICE_URL }}
86+
QUESTION_SERVICE_URL: ${{ vars.QUESTION_SERVICE_URL }}
87+
MATCHING_SERVICE_URL: ${{ vars.MATCHING_SERVICE_URL }}
88+
run: |
89+
echo "Testing Question Service..."
90+
curl -sSL -o /dev/null $QUESTION_SERVICE_URL && echo "Question Service is up"
91+
echo "Testing User Service..."
92+
curl -fsSL -o /dev/null $USER_SERVICE_URL && echo "User Service is up"
93+
echo "Testing Frontend..."
94+
curl -fsSL -o /dev/null $FRONTEND_URL && echo "Frontend is up"
95+
echo "Testing Matching Service..."
96+
if ! (echo "Hello" | websocat $MATCHING_SERVICE_URL); then
97+
echo "WebSocket for Matching Service is not live"
98+
else
99+
echo "WebSocket for Matching Service is live"
100+
fi
101+
# Add in test for matching service in the future
102+
103+
# We can add more tests here

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/.dockerignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ node_modules
44
.gitignore
55
.next
66
out
7-
public
87
README.md

apps/frontend/.env.example

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
# Replace with the corresponding url, credentials and endpoint
1+
# URL endpoints of the services
22
NEXT_PUBLIC_QUESTION_SERVICE_URL="http://localhost:8080/"
3-
NEXT_PUBLIC_USER_SERVICE_URL="http://localhost:3001/"
3+
NEXT_PUBLIC_USER_SERVICE_URL="http://localhost:3001/"
4+
NEXT_PUBLIC_MATCHING_SERVICE_URL="ws://localhost:8081/match"

apps/frontend/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ RUN addgroup --system --gid 1001 nodejs
4141
RUN adduser --system --uid 1001 nextjs
4242

4343
# Include this when we want to include images in the future
44-
# COPY --from=builder /app/public ./public
44+
COPY --from=builder /app/public ./public
4545

4646
# Set the correct permission for prerender cache
4747
RUN mkdir .next

apps/frontend/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +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="ws://localhost:8081"
2829
```
2930

3031
First, run the development server:

apps/frontend/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
"next": "14.2.13",
1717
"react": "^18.2.0",
1818
"react-dom": "^18.2.0",
19-
"sass": "^1.79.2"
19+
"react-timer-hook": "^3.0.7",
20+
"react-use-websocket": "^4.9.0",
21+
"sass": "^1.79.2",
22+
"typeface-montserrat": "^1.1.13"
2023
},
2124
"devDependencies": {
2225
"@types/node": "^20",

0 commit comments

Comments
 (0)