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__ __pycache__
*.pyc *.pyc
*.pyo
.env .env
.env.*
.venv .venv
venv venv
.git .git
...@@ -8,3 +10,11 @@ venv ...@@ -8,3 +10,11 @@ venv
.dockerignore .dockerignore
logs logs
data 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 PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1 ENV PYTHONDONTWRITEBYTECODE=1
ENV ENV=development ENV ENV=production
COPY requirements.txt . # Copy only installed packages from builder
RUN pip install -r requirements.txt COPY --from=builder /install /usr/local
COPY . . COPY . .
EXPOSE 5000 EXPOSE 5005
ENV WORKERS=16
ENV TIMEOUT=60
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: ...@@ -8,20 +8,20 @@ services:
env_file: .env env_file: .env
ports: ports:
- "5005:5005" - "5005:5005"
volumes:
- .:/app
environment: environment:
- PORT=5005 - ENV=production
restart: unless-stopped restart: unless-stopped
deploy: deploy:
resources: resources:
limits: limits:
memory: 8g memory: 4g
networks: networks:
- backend_network - backend_network
logging: logging:
driver: "json-file" driver: "json-file"
options: options:
max-size: "50m"
max-file: "3"
tag: "{{.Name}}" tag: "{{.Name}}"
networks: 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