Skip to content

Commit

Permalink
Merge pull request #47 from CS3219-AY2425S1/staging
Browse files Browse the repository at this point in the history
Milestone D4
  • Loading branch information
UnwilledTangent authored Oct 20, 2024
2 parents 73ecfef + 74baa54 commit 217dc99
Show file tree
Hide file tree
Showing 63 changed files with 5,757 additions and 2,864 deletions.
103 changes: 103 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: Run Tests

on:
push:
branches:
- main
- staging
- frontend-websocket-test
pull_request:
branches:
- main
- staging

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Docker Compose
run: |
sudo apt-get update
sudo apt-get install -y docker-compose
- name: Create Environment Files
env:
QUESTION_SERVICE_URL: ${{ vars.QUESTION_SERVICE_URL }}
USER_SERVICE_URL: ${{ vars.USER_SERVICE_URL }}
MATCHING_SERVICE_URL: ${{ vars.MATCHING_SERVICE_URL }}
JWT_SECRET: ${{ secrets.JWT_SECRET }}
FIREBASE_CREDENTIAL_PATH: ${{ vars.QUESTION_SERVICE_FIREBASE_CREDENTIAL_PATH }}
DB_CLOUD_URI: ${{ secrets.USER_SERVICE_DB_CLOUD_URI }}
USER_SERVICE_PORT: ${{ vars.USER_SERVICE_PORT }}
MATCHING_SERVICE_PORT: ${{ vars.MATCHING_SERVICE_PORT }}
MATCHING_SERVICE_TIMEOUT: ${{ vars.MATCHING_SERVICE_TIMEOUT }}
REDIS_URL: ${{ vars.REDIS_URL }}
run: |
cd ./apps/frontend
echo "NEXT_PUBLIC_QUESTION_SERVICE_URL=$QUESTION_SERVICE_URL" >> .env
echo "NEXT_PUBLIC_USER_SERVICE_URL=$USER_SERVICE_URL" >> .env
echo "NEXT_PUBLIC_MATCHING_SERVICE_URL=$MATCHING_SERVICE_URL" >> .env
cd ../question-service
echo "FIREBASE_CREDENTIAL_PATH=$FIREBASE_CREDENTIAL_PATH" >> .env
echo "JWT_SECRET=$JWT_SECRET" >> .env
cd ../user-service
echo "DB_CLOUD_URI=$DB_CLOUD_URI" >> .env
echo "PORT=$USER_SERVICE_PORT" >> .env
echo "JWT_SECRET=$JWT_SECRET" >> .env
cd ../matching-service
echo "PORT=$MATCHING_SERVICE_PORT" >> .env
echo "MATCH_TIMEOUT=$MATCHING_SERVICE_TIMEOUT" >> .env
echo "JWT_SECRET=$JWT_SECRET" >> .env
echo "REDIS_URL=$REDIS_URL" >> .env
- name: Create Database Credential Files
env:
FIREBASE_JSON: ${{ secrets.QUESTION_SERVICE_FIREBASE_CREDENTIAL }}
FIREBASE_CREDENTIAL_PATH: ${{ vars.QUESTION_SERVICE_FIREBASE_CREDENTIAL_PATH }}
run: |
cd ./apps/question-service
echo "$FIREBASE_JSON" > "./$FIREBASE_CREDENTIAL_PATH"
- name: Build and Run Services
run: |
cd ./apps
docker-compose up --build -d
- name: Wait for services to be ready
run: sleep 30

- name: Install websocat
run: |
sudo wget -qO /usr/local/bin/websocat https://github.com/vi/websocat/releases/latest/download/websocat.x86_64-unknown-linux-musl
sudo chmod a+x /usr/local/bin/websocat
websocat --version
- name: Run Tests
env:
FRONTEND_URL: ${{ vars.FRONTEND_URL }}
USER_SERVICE_URL: ${{ vars.USER_SERVICE_URL }}
QUESTION_SERVICE_URL: ${{ vars.QUESTION_SERVICE_URL }}
MATCHING_SERVICE_URL: ${{ vars.MATCHING_SERVICE_URL }}
run: |
echo "Testing Question Service..."
curl -sSL -o /dev/null $QUESTION_SERVICE_URL && echo "Question Service is up"
echo "Testing User Service..."
curl -fsSL -o /dev/null $USER_SERVICE_URL && echo "User Service is up"
echo "Testing Frontend..."
curl -fsSL -o /dev/null $FRONTEND_URL && echo "Frontend is up"
echo "Testing Matching Service..."
if ! (echo "Hello" | websocat $MATCHING_SERVICE_URL); then
echo "WebSocket for Matching Service is not live"
else
echo "WebSocket for Matching Service is live"
fi
# Add in test for matching service in the future
# We can add more tests here
22 changes: 16 additions & 6 deletions apps/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,21 @@ In the `./apps` directory:
```plaintext
.
├── docker-compose.yml # Docker Compose configuration
├── README.md # Project documentation (for docker compose)
├── .env # Global environment variables (optional)
├── frontend
│ ├── Dockerfile # Dockerfile for frontend
│ └── ... (other frontend files)
├── matching-service
│ ├── Dockerfile # Dockerfile for matching-service
│ └── ... (other matching-service files)
├── question-service
│ ├── Dockerfile # Dockerfile for question-service
│ └── ... (other question-service files)
├── user-service
│ ├── Dockerfile # Dockerfile for user-service
│ └── ... (other user-service files)
└── README.md # Project documentation (for docker compose)
```

## Docker Compose Setup
Expand All @@ -53,6 +57,8 @@ Once running, you can access:
- The **frontend** at http://localhost:3000
- The **user service** at http://localhost:3001
- The **question service** at http://localhost:8080
- The **matching service** at http://localhost:8081
- The **redis service** at http://localhost:6379

3. Stopping Services

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

## Troubleshooting

**Common Issues**
### Common Issues

- **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.
- **Environment Variables Not Loaded**: Ensure the `.env` files are in the correct directories as found in the `docker-compose.yml` file.

### Known Issues

- 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.
- Environment Variables Not Loaded: Ensure the `.env` files are in the correct directories as found in the `docker-compose.yml` file.
- **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.

**Logs**
### Logs

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

```bash
docker-compose logs
```

**Useful Commands**
### Useful Commands

Rebuild a specific service:

Expand Down
23 changes: 23 additions & 0 deletions apps/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,28 @@ services:
volumes:
- ./question-service:/question-service

matching-service:
build:
context: ./matching-service
dockerfile: Dockerfile
ports:
- 8081:8081
env_file:
- ./matching-service/.env
networks:
- apps_network
volumes:
- ./matching-service:/matching-service
depends_on:
- redis

redis:
image: redis:latest
networks:
- apps_network
ports:
- 6379:6379
container_name: redis-container

networks:
apps_network:
1 change: 0 additions & 1 deletion apps/frontend/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ node_modules
.gitignore
.next
out
public
README.md
5 changes: 3 additions & 2 deletions apps/frontend/.env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Replace with the corresponding url, credentials and endpoint
# URL endpoints of the services
NEXT_PUBLIC_QUESTION_SERVICE_URL="http://localhost:8080/"
NEXT_PUBLIC_USER_SERVICE_URL="http://localhost:3001/"
NEXT_PUBLIC_USER_SERVICE_URL="http://localhost:3001/"
NEXT_PUBLIC_MATCHING_SERVICE_URL="ws://localhost:8081/match"
2 changes: 1 addition & 1 deletion apps/frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

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

# Set the correct permission for prerender cache
RUN mkdir .next
Expand Down
1 change: 1 addition & 0 deletions apps/frontend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Then, follow the `.env.example` file and create a `.env` file in the current dir
```bash
NEXT_PUBLIC_QUESTION_SERVICE_URL="http://localhost:8080"
NEXT_PUBLIC_USER_SERVICE_URL="http://localhost:3001/"
NEXT_PUBLIC_MATCHING_SERVICE_URL="ws://localhost:8081"
```

First, run the development server:
Expand Down
5 changes: 4 additions & 1 deletion apps/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
"next": "14.2.13",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"sass": "^1.79.2"
"react-timer-hook": "^3.0.7",
"react-use-websocket": "^4.9.0",
"sass": "^1.79.2",
"typeface-montserrat": "^1.1.13"
},
"devDependencies": {
"@types/node": "^20",
Expand Down
Loading

0 comments on commit 217dc99

Please sign in to comment.