# syntax=docker/dockerfile:1

FROM python:3.10-slim AS base

ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    PIP_NO_CACHE_DIR=1 \
    PIP_DISABLE_PIP_VERSION_CHECK=1 \
    UVICORN_WORKERS=2 \
    PORT=8002

WORKDIR /app

# 安装系统依赖（如需 Pillow 等编译依赖，可按需添加）
RUN apt-get update \
    && apt-get install -y --no-install-recommends build-essential \
    && rm -rf /var/lib/apt/lists/*

# 仅拷贝依赖文件，加速构建缓存
COPY requirements.txt /app/backend/requirements.txt
RUN pip install -r /app/backend/requirements.txt

# 拷贝后端代码
COPY . /app/backend

# 创建非 root 用户（更安全）
RUN useradd -m appuser && chown -R appuser:appuser /app
USER appuser

EXPOSE 8000

# 生产环境不需要 reload
CMD ["sh", "-c", "uvicorn backend.api.ai_swap_api:app --host 0.0.0.0 --port ${PORT} --workers ${UVICORN_WORKERS}"]


