# MMD 能力沙箱：Node 20 + Python 3，供 MCP 通过 docker exec 运行
ARG BASE_IMAGE=node:20-bookworm-slim
FROM ${BASE_IMAGE}

# slim 基础镜像尚无 CA，不能先切 HTTPS 国内源；先用默认源装 ca-certificates
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get -o Acquire::http::Timeout=30 -o Acquire::Retries=3 update \
    && apt-get install -y --no-install-recommends ca-certificates \
    && rm -rf /var/lib/apt/lists/*

# bookworm 使用 DEB822 源文件；勿用 sed 乱改（会导致 apt-get 长时间无响应）
ARG USE_APT_MIRROR=1
ARG APT_MIRROR=https://mirrors.aliyun.com/debian
ARG APT_SECURITY_MIRROR=https://mirrors.aliyun.com/debian-security
RUN if [ "$USE_APT_MIRROR" = "1" ] && [ -f /etc/apt/sources.list.d/debian.sources ]; then \
        printf '%s\n' \
          'Types: deb' \
          "URIs: ${APT_MIRROR}" \
          'Suites: bookworm bookworm-updates' \
          'Components: main contrib non-free non-free-firmware' \
          '' \
          'Types: deb' \
          "URIs: ${APT_SECURITY_MIRROR}" \
          'Suites: bookworm-security' \
          'Components: main contrib non-free non-free-firmware' \
          > /etc/apt/sources.list.d/debian.sources; \
    fi

RUN apt-get -o Acquire::http::Timeout=30 -o Acquire::Retries=3 update \
    && apt-get install -y --no-install-recommends \
        python3 python3-pip python3-venv curl \
    && rm -rf /var/lib/apt/lists/*

ARG PIP_INDEX_URL=https://mirrors.aliyun.com/pypi/simple/
RUN pip3 install --no-cache-dir --break-system-packages \
        -i "$PIP_INDEX_URL" \
        mcp-server-fetch \
        requests httpx beautifulsoup4 lxml aiohttp pyyaml

WORKDIR /workspace

ARG NPM_REGISTRY=https://registry.npmmirror.com
RUN npm config set registry "$NPM_REGISTRY" \
    && npm install -g @larksuiteoapi/lark-mcp

CMD ["sleep", "infinity"]
