FROM python:3.12-slim AS builder ENV PYTHONUNBUFFERED=1 ENV LANG=C.UTF-8 ENV LC_ALL=C.UTF-8 ENV PYTHONIOENCODING=utf-8 ENV PATH=/opt/venv/bin:$PATH # 1. 替换 Debian 源为国内镜像 RUN sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list.d/debian.sources && \ sed -i 's/security.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list.d/debian.sources # 2. 仅在构建阶段安装编译依赖 RUN apt-get update && apt-get install -y --no-install-recommends \ gcc \ && rm -rf /var/lib/apt/lists/* RUN python -m venv /opt/venv WORKDIR /app COPY pyproject.toml README.md LICENSE THIRD_PARTY_NOTICES.md ./ COPY nanobot/ nanobot/ COPY bridge/ bridge/ # 3. 在 builder 中完成 Python 依赖安装,避免源码和编译工具进入最终镜像 RUN python -m pip install --no-cache-dir -i https://mirrors.aliyun.com/pypi/simple/ --upgrade \ --no-compile pip setuptools wheel aiohttp && \ pip install --no-cache-dir --no-compile -i https://mirrors.aliyun.com/pypi/simple/ ".[wecom]" && \ find /opt/venv -type d -name __pycache__ -prune -exec rm -rf {} + && \ find /opt/venv -name '*.pyc' -delete FROM python:3.12-slim ENV PYTHONUNBUFFERED=1 ENV LANG=C.UTF-8 ENV LC_ALL=C.UTF-8 ENV PYTHONIOENCODING=utf-8 ENV PATH=/opt/venv/bin:$PATH # 1. 替换 Debian 源为国内镜像 RUN sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list.d/debian.sources && \ sed -i 's/security.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list.d/debian.sources # 2. 安装运行时依赖与技能所需 CLI RUN apt-get update && apt-get install -y --no-install-recommends \ bubblewrap \ ca-certificates \ curl \ git \ gnupg \ openssh-client \ tmux \ && mkdir -p /etc/apt/keyrings /etc/apt/sources.list.d \ && curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \ && echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_22.x nodistro main" > /etc/apt/sources.list.d/nodesource.list \ && curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg > /etc/apt/keyrings/githubcli-archive-keyring.gpg \ && chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg \ && echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" > /etc/apt/sources.list.d/github-cli.list \ && apt-get update && apt-get install -y --no-install-recommends \ gh \ nodejs \ && apt-get purge -y --auto-remove gnupg \ && git config --global --add url."https://github.com/".insteadOf ssh://git@github.com/ \ && git config --global --add url."https://github.com/".insteadOf git@github.com: \ && rm -rf /var/lib/apt/lists/* # 3. 仅复制已安装好的运行环境,避免把源码目录打进最终镜像 COPY --from=builder /opt/venv /opt/venv WORKDIR /root # 官方 gateway 模式,现在它会自动加载您的 DashboardChannel CMD ["nanobot", "gateway"]