FROM python:3.11-slim-bookworm

ENV TZ=Asia/Shanghai \
    PYTHONUNBUFFERED=1 \
    PIP_NO_CACHE_DIR=1 \
    PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple \
    DQD_CONFIG_PATH=/app/config/settings.yaml \
    DQD_TASKS_FILE=/app/config/crawler_tasks.yaml \
    DQD_LOCK_DIR=/app/data/locks

WORKDIR /app

RUN sed -i 's|http://deb.debian.org|https://mirrors.aliyun.com|g' /etc/apt/sources.list.d/debian.sources \
    && apt-get update \
    && apt-get install -y --no-install-recommends \
        bash \
        ca-certificates \
        cron \
        curl \
        tzdata \
    && rm -rf /var/lib/apt/lists/*

COPY requirements.txt /app/requirements.txt
RUN python -m pip install --upgrade pip setuptools wheel \
    && python -m pip install -r /app/requirements.txt

# API 型采集任务不依赖 Chromium。浏览器型采集需要时再在镜像内单独安装，
# 避免本地首次构建因浏览器下载通道不可达而阻塞整个调度器。

COPY . /app

RUN sed -i 's/\r$//' /app/docker/entrypoint.sh \
    && mkdir -p /app/logs /app/data/locks /etc/sport-era-crawler \
    && chmod +x /app/docker/entrypoint.sh

ENTRYPOINT ["/app/docker/entrypoint.sh"]
