Commit 566ee233 authored by Vũ Hoàng Anh's avatar Vũ Hoàng Anh

chore: update docker configuration for production optimization

parent ac047234
# Lấy Python 3.11 slim (ít file, nhẹ)
FROM python:3.11-slim FROM python:3.11-slim
# Thư mục làm việc
WORKDIR /app WORKDIR /app
ENV PYTHONUNBUFFERED=1 PYTHONDONTWRITEBYTECODE=1
# Copy requirements rồi cài package ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1
ENV ENV=development
COPY requirements.txt . COPY requirements.txt .
RUN pip install -r requirements.txt RUN pip install -r requirements.txt
# Copy code
COPY . . COPY . .
# Copy entrypoint script (nếu có) # Expose port 5000 (Port chạy server)
COPY entrypoint.sh /app/entrypoint.sh
RUN chmod +x /app/entrypoint.sh
# Mở port 5000
EXPOSE 5000 EXPOSE 5000
# Chạy server # Tự động tính số worker = (Số Core * 2) + 1 để tận dụng tối đa CPU
CMD ["/app/entrypoint.sh"] CMD gunicorn server:app --workers $(( 2 * $(nproc) + 1 )) --worker-class uvicorn.workers.UvicornWorker --bind 0.0.0.0:5000 --timeout 60
\ No newline at end of file
# ============================================================
# DOCKERFILE.STAGE - Development/Staging (Hot Reload)
# ============================================================
# Sử dụng Python 3.11 Slim để tối ưu dung lượng
FROM python:3.11-slim
# Thiết lập thư mục làm việc
WORKDIR /app
# Thiết lập biến môi trường để log in ra ngay lập tức
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1
ENV ENV=development
# Copy requirements.txt trước để tận dụng Docker cache
COPY requirements.txt .
# Cài đặt thư viện Python (với cache mount)
RUN pip install -r requirements.txt
# Copy toàn bộ source code vào image
COPY . .
# Expose port 5000 (Port chạy server)
EXPOSE 5000
# Lệnh chạy server dùng uvicorn với hot reload
# ⚡ Hot reload - tự động restart khi code thay đổi (dùng cho dev/stage)
CMD ["uvicorn", "server:app", "--host", "0.0.0.0", "--port", "5000", "--reload"]
services:
# --- Backend Service ---
backend:
build:
context: .
dockerfile: Dockerfile.prod
container_name: canifa_backend
env_file: .env
ports:
- "5000:5000"
volumes:
- .:/app
environment:
- PORT=5000
restart: unless-stopped
deploy:
resources:
limits:
memory: 8g
networks:
- backend_network
logging:
driver: "json-file"
options:
tag: "{{.Name}}"
networks:
backend_network:
driver: bridge
ipam:
driver: default
config:
- subnet: "172.24.0.0/16"
gateway: "172.24.0.1"
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