fix: production hardening — 5 critical issues resolved

1. Dockerfile: remove UTF-16 encoding conversion (requirements.txt now plain UTF-8)
   Add --forwarded-allow-ips=* to uvicorn so rate limiter + audit logs
   see real client IPs through nginx, not nginx container IP

2. .dockerignore: exclude pandoc MSI (~200MB), blog_images/, frontend-legacy/,
   *.md docs, *.docx, *.msi, *.patch, openrouter_error.log — significant image
   size reduction

3. requirements.txt: convert from UTF-16 to plain UTF-8 (removes need for
   Dockerfile encoding hack), pypdf==4.3.1 already added in previous commit

4. DEPLOYMENT.md: add missing frontend build step (npm install && npm run build),
   add database migration commands (migrate.py + v003 + v004 SQL files),
   add super admin creation step, add HTTPS setup, add backup command,
   add troubleshooting table

5. All secrets now come from .env only (no fallback defaults in docker-compose)
This commit is contained in:
Atharv1705
2026-08-10 10:42:37 +05:30
parent aff470bb48
commit 419aa6de3d
4 changed files with 223 additions and 32 deletions
+13 -13
View File
@@ -6,9 +6,8 @@ ENV PYTHONDONTWRITEBYTECODE=1 \
WORKDIR /app
# Install Tesseract OCR + English + Hindi language data (Stage 2 of extraction pipeline)
# tesseract-ocr: ~50MB — CPU-only, no GPU needed
# tesseract-ocr-hin: Hindi language pack for bilingual Indian documents (Aadhaar, PAN, etc.)
# System deps: Tesseract OCR (Stage 2 of extraction pipeline — CPU-only, no GPU)
# eng: English, hin: Hindi — for bilingual Indian documents (Aadhaar, PAN, etc.)
RUN apt-get update && apt-get install -y --no-install-recommends \
tesseract-ocr \
tesseract-ocr-eng \
@@ -16,21 +15,22 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
libgl1 \
&& rm -rf /var/lib/apt/lists/*
# Install Python dependencies (plain UTF-8 requirements.txt)
COPY services/api/requirements.txt /tmp/requirements.txt
RUN python - <<'PY'
from pathlib import Path
src = Path('/tmp/requirements.txt')
text = src.read_text(encoding='utf-16')
Path('/tmp/requirements-utf8.txt').write_text(text, encoding='utf-8')
PY
RUN pip install --upgrade pip && pip install -r /tmp/requirements-utf8.txt
RUN pip install --upgrade pip && pip install -r /tmp/requirements.txt
# Copy app source
COPY . /app
WORKDIR /app/services/api
EXPOSE 8000
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "4", "--proxy-headers"]
# --forwarded-allow-ips=* trusts X-Forwarded-For from nginx container
# Required so rate limiter and audit logs see real client IPs (not nginx's internal IP)
CMD ["uvicorn", "app.main:app", \
"--host", "0.0.0.0", \
"--port", "8000", \
"--workers", "4", \
"--proxy-headers", \
"--forwarded-allow-ips=*"]