Commit 453ef792 authored by Vũ Hoàng Anh's avatar Vũ Hoàng Anh

perf: multi-stage Dockerfile, remove workers, fix docker-compose prod

parent 1d44f574
__pycache__
*.pyc
*.pyo
.env
.env.*
.venv
venv
.git
......@@ -8,3 +10,11 @@ venv
.dockerignore
logs
data
*.md
*.txt
!requirements.txt
tests/
.agent/
.agents/
dashboard_debug.png
dashboard_fixed.png
# ── Stage 1: Builder ──
FROM python:3.11-slim AS builder
FROM python:3.11-slim
WORKDIR /build
COPY requirements.txt .
RUN pip install --no-cache-dir --prefix=/install -r requirements.txt
WORKDIR /app
# ── Stage 2: Runtime (minimal) ──
FROM python:3.11-slim
WORKDIR /app
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1
ENV ENV=development
ENV ENV=production
COPY requirements.txt .
RUN pip install -r requirements.txt
# Copy only installed packages from builder
COPY --from=builder /install /usr/local
COPY . .
EXPOSE 5000
ENV WORKERS=16
ENV TIMEOUT=60
EXPOSE 5005
CMD gunicorn server:app --workers $WORKERS --worker-class uvicorn.workers.UvicornWorker --bind 0.0.0.0:5000 --timeout $TIMEOUT
CMD ["uvicorn", "server:app", "--host", "0.0.0.0", "--port", "5005", "--timeout-keep-alive", "65"]
......@@ -8,20 +8,20 @@ services:
env_file: .env
ports:
- "5005:5005"
volumes:
- .:/app
environment:
- PORT=5005
- ENV=production
restart: unless-stopped
deploy:
resources:
limits:
memory: 8g
memory: 4g
networks:
- backend_network
logging:
driver: "json-file"
options:
max-size: "50m"
max-file: "3"
tag: "{{.Name}}"
networks:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment