Skip to content

Commit cdb7119

Browse files
authored
Merge pull request #163 from CS3219-AY2425S1/feature/matching-service-nodylan
Set up branch
2 parents cf43b98 + 11a6a56 commit cdb7119

File tree

10 files changed

+82
-1
lines changed

10 files changed

+82
-1
lines changed

docker-compose.dev.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,9 @@ services:
1818
target: dev
1919
volumes:
2020
- ./user-service/app:/app/app
21+
22+
matching-service:
23+
environment:
24+
- BUILD_ENV=dev
25+
volumes:
26+
- ./matching-service/app:/app/app

docker-compose.prod.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ services:
1111
user-service:
1212
build:
1313
target: prod
14+
15+
matching-service:
16+
environment:
17+
- BUILD_ENV=prod

docker-compose.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,16 @@ services:
2929
- EMAIL_ADDRESS=$EMAIL_ADDRESS
3030
- EMAIL_PASSWORD=$EMAIL_PASSWORD
3131

32+
matching-service:
33+
build:
34+
context: ./matching-service
35+
ports:
36+
- $MATCHING_SVC_PORT:$MATCHING_SVC_PORT
37+
environment:
38+
- PORT=$MATCHING_SVC_PORT
39+
3240
redis:
3341
image: redis:7.4-alpine
3442
restart: always
3543
ports:
36-
- 6379:6379
44+
- 6379:6379

matching-service/.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
**/README.md
2+
**/.gitignore
3+
**/.venv

matching-service/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.venv
2+
app/__pycache__
3+
app/routers/__pycache__

matching-service/Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM python:3.12-slim AS base
2+
WORKDIR /app
3+
COPY requirements.txt .
4+
RUN python -m venv .venv
5+
RUN .venv/bin/pip install --no-cache-dir -r requirements.txt
6+
COPY . .
7+
CMD [".venv/bin/python", "app/main.py"]

matching-service/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Dependencies: Python 12
2+
3+
## Setup
4+
1. In the `matching-service` directory, run `python -m venv .venv` to create a virtual environment.
5+
2. Run `source .venv/bin/activate` for mac or `.\.venv\Scripts\activate` for windows to activate the virtual environment.
6+
3. Run `pip install -r requirements.txt` to install all necessary dependencies.
7+
4. Ensure you have a `.env` file in `matching-service` with the question service mongoDB uri.
8+
5. To start the service, run `fastapi dev app/main.py`
9+
10+
Note: For VSCode to properly detect the venv, open the project with `matching-service` as the root directory. If not, VSCode will not detect the venv properly and will scream at you for everything.

matching-service/app/main.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from fastapi import FastAPI
2+
from fastapi.middleware.cors import CORSMiddleware
3+
import os
4+
5+
from routers import match
6+
7+
app = FastAPI(title="Matching Service API")
8+
9+
origins = [
10+
"http://localhost:3000",
11+
]
12+
13+
app.add_middleware(
14+
CORSMiddleware,
15+
allow_origins=origins,
16+
allow_credentials=True,
17+
allow_methods=["*"],
18+
allow_headers=["*"],
19+
)
20+
21+
# Include routers
22+
app.include_router(match.router, prefix="/match", tags=["match"])
23+
24+
if __name__ == "__main__":
25+
import uvicorn
26+
27+
uvicorn.run(
28+
"main:app",
29+
host="0.0.0.0",
30+
port=int(os.environ.get("PORT", 6969)),
31+
reload=(os.environ.get("BUILD_ENV", "dev") == "dev")
32+
)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from fastapi import APIRouter
2+
3+
router = APIRouter()
4+
5+
# Make a dummy endpoint to test the connection
6+
@router.get("/")
7+
async def test_connection():
8+
return {"message": "Connection successful"}

matching-service/requirements.txt

1.18 KB
Binary file not shown.

0 commit comments

Comments
 (0)