Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MONGO_URI="mongodb+srv://<USERNAME>:<PASSWORD>@<YOUR_CLUSTER_URL>/?retryWrites=true&w=majority"
37 changes: 37 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Backend CI/CD Workflow

on:
push:
branches:
- main
pull_request:

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: "3.10"

- name: Install Dependencies
run: pip install -r requirements.txt

- name: Run Tests (with MockDB)
env:
TESTING: "True"
run: pytest tests/

build:
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Build Docker Image
run: docker build -t suraksha-backend:latest .
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM python:3.10-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
# Optional: if you need port 5000 internally
EXPOSE 5000
CMD ["python", "app.py"]
11 changes: 8 additions & 3 deletions db/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@

try:
MONGO_URI = os.getenv("MONGO_URI", "mongodb://localhost:27017/")
client = MongoClient(MONGO_URI)
if os.getenv("TESTING") == "True":
import mongomock
client = mongomock.MongoClient()
print("Connected to MongoMock for testing.")
else:
client = MongoClient(MONGO_URI)

# Test connection
client.admin.command('ping')
print("Connected successfully to MongoDB")
client.admin.command('ping')
print("Connected successfully to MongoDB")

db = client["earnsure"]

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ requests==2.31.0
numpy==1.26.2
pytest==7.4.3
python-dotenv==1.0.0
mongomock==4.1.2
Loading