FROM condaforge/miniforge3:latest

WORKDIR /app

ARG APT_MIRROR=https://mirrors.tuna.tsinghua.edu.cn/ubuntu
ARG CONDA_CHANNEL=https://mirrors.bfsu.edu.cn/anaconda/pkgs/main
ARG PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple

ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV MPLBACKEND=Agg
ENV APP_ENV=production
ENV DEBUG=false

RUN sed -i "s|http://archive.ubuntu.com/ubuntu|${APT_MIRROR}|g; s|http://security.ubuntu.com/ubuntu|${APT_MIRROR}|g" /etc/apt/sources.list.d/ubuntu.sources \
    && apt-get update \
    && apt-get install -y --no-install-recommends fontconfig fonts-noto-cjk \
    && fc-cache -fv \
    && rm -rf /var/lib/apt/lists/*

COPY requirements.txt .

RUN mamba create -n demo --override-channels -c "${CONDA_CHANNEL}" python=3.12 -y \
    && python -m pip install --no-cache-dir -i "${PIP_INDEX_URL}" uv \
    && uv pip install --python /opt/conda/envs/demo/bin/python --no-cache -i "${PIP_INDEX_URL}" -r requirements.txt \
    && conda clean -afy

COPY app ./app
COPY templates ./templates
COPY static ./static
COPY main.py .
COPY example.xlsx .
COPY 20260630标准文本——供水管道健康状态与剩余寿命评估技术导则.pdf .
COPY model_core ./model_core

RUN mkdir -p data static/images uploads

EXPOSE 5005

CMD ["conda", "run", "--no-capture-output", "-n", "demo", "gunicorn", "--preload", "--bind", "0.0.0.0:5005", "--workers", "2", "--threads", "4", "--timeout", "120", "main:app"]
