Skip to content

Commit 7cdfdfe

Browse files
author
Kavyansh Chourasia
committed
Shiksha API: Moved to poetry
1 parent 9d8f3d5 commit 7cdfdfe

File tree

6 files changed

+4441
-98
lines changed

6 files changed

+4441
-98
lines changed

shiksha-api/app-service/Dockerfile

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,26 @@ FROM python:3.11-slim
33
# Set working directory
44
WORKDIR /app
55

6-
# Install system dependencies
6+
# Install system dependencies and Poetry
77
RUN apt-get update && apt-get install -y \
88
gcc \
99
g++ \
10-
&& rm -rf /var/lib/apt/lists/*
10+
curl \
11+
&& rm -rf /var/lib/apt/lists/* \
12+
&& curl -sSL https://install.python-poetry.org | python3 -
1113

12-
# Copy requirements first for better caching
13-
COPY requirements.txt .
14+
# Add Poetry to PATH
15+
ENV PATH="${PATH}:/root/.local/bin"
16+
17+
# Configure Poetry to not create a virtual environment inside the Docker container
18+
RUN poetry config virtualenvs.create false
19+
20+
# Copy pyproject.toml and poetry.lock (if exists)
21+
COPY pyproject.toml ./
22+
COPY poetry.lock* ./
1423

1524
# Install Python dependencies
16-
RUN pip install --no-cache-dir -r requirements.txt
25+
RUN poetry install --no-interaction --no-ansi --no-dev
1726

1827
# Copy application code
1928
COPY . .

shiksha-api/app-service/logging_config.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Logging configuration for the FastAPI application.
33
Uses structured logging with JSON output for better observability.
44
"""
5+
56
import sys
67
import logging
78
from typing import Dict, Any
@@ -11,14 +12,14 @@
1112

1213
def configure_logging() -> None:
1314
"""Configure structured logging for the application."""
14-
15+
1516
# Configure standard library logging
1617
logging.basicConfig(
1718
format="%(message)s",
1819
stream=sys.stdout,
19-
level=getattr(logging, settings.log_level.upper())
20+
level=getattr(logging, settings.log_level.upper()),
2021
)
21-
22+
2223
# Configure structlog
2324
structlog.configure(
2425
processors=[
@@ -31,8 +32,11 @@ def configure_logging() -> None:
3132
structlog.processors.format_exc_info,
3233
structlog.processors.UnicodeDecoder(),
3334
# Add JSON formatting for production
34-
structlog.processors.JSONRenderer() if not settings.debug
35-
else structlog.dev.ConsoleRenderer(colors=True)
35+
(
36+
structlog.processors.JSONRenderer()
37+
if not settings.debug
38+
else structlog.dev.ConsoleRenderer(colors=True)
39+
),
3640
],
3741
context_class=dict,
3842
logger_factory=structlog.stdlib.LoggerFactory(),
@@ -49,42 +53,43 @@ def get_logger(name: str) -> structlog.BoundLogger:
4953
# Middleware for request logging
5054
def log_request_middleware():
5155
"""Middleware to log HTTP requests."""
56+
5257
async def middleware(request, call_next):
5358
logger = get_logger("http")
54-
59+
5560
# Log request
5661
logger.info(
5762
"Request started",
5863
method=request.method,
5964
url=str(request.url),
6065
headers=dict(request.headers),
61-
client_ip=request.client.host if request.client else None
66+
client_ip=request.client.host if request.client else None,
6267
)
63-
68+
6469
# Process request
6570
try:
6671
response = await call_next(request)
67-
72+
6873
# Log response
6974
logger.info(
7075
"Request completed",
7176
method=request.method,
7277
url=str(request.url),
7378
status_code=response.status_code,
74-
response_time_ms=0 # You can add timing here
79+
response_time_ms=0, # You can add timing here
7580
)
76-
81+
7782
return response
78-
83+
7984
except Exception as e:
8085
# Log error
8186
logger.error(
8287
"Request failed",
8388
method=request.method,
8489
url=str(request.url),
8590
error=str(e),
86-
exc_info=True
91+
exc_info=True,
8792
)
8893
raise
89-
94+
9095
return middleware

0 commit comments

Comments
 (0)