dashboard-nanobot/bot-images/Dashboard.Dockerfile

80 lines
3.6 KiB
Plaintext
Raw Normal View History

2026-04-25 05:55:24 +00:00
FROM python:3.12-slim AS builder
2026-03-01 16:26:03 +00:00
ENV PYTHONUNBUFFERED=1
ENV LANG=C.UTF-8
ENV LC_ALL=C.UTF-8
ENV PYTHONIOENCODING=utf-8
2026-04-25 05:55:24 +00:00
ENV PATH=/opt/venv/bin:$PATH
2026-03-01 16:26:03 +00:00
2026-03-05 04:52:52 +00:00
# 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
2026-03-01 16:26:03 +00:00
2026-04-25 05:55:24 +00:00
# 2. 仅在构建阶段安装编译依赖
2026-03-01 16:26:03 +00:00
RUN apt-get update && apt-get install -y --no-install-recommends \
2026-03-05 04:52:52 +00:00
gcc \
2026-03-01 16:26:03 +00:00
&& rm -rf /var/lib/apt/lists/*
2026-04-25 05:55:24 +00:00
RUN python -m venv /opt/venv
2026-03-01 16:26:03 +00:00
WORKDIR /app
2026-04-25 05:55:24 +00:00
COPY pyproject.toml README.md LICENSE THIRD_PARTY_NOTICES.md ./
2026-04-26 07:27:02 +00:00
# 3. 先安装第三方依赖。该层只依赖 pyproject.toml源码改动不会触发整套依赖重装。
RUN --mount=type=cache,target=/root/.cache/pip \
python -m pip install -i https://mirrors.aliyun.com/pypi/simple/ --upgrade \
--no-compile pip setuptools wheel aiohttp hatchling && \
python -c 'import tomllib; data=tomllib.load(open("pyproject.toml","rb")); deps=list(data["project"].get("dependencies", [])); deps.extend(data["project"].get("optional-dependencies", {}).get("wecom", [])); print("\n".join(deps))' > /tmp/requirements.txt && \
pip install --no-compile -i https://mirrors.aliyun.com/pypi/simple/ -r /tmp/requirements.txt && \
rm -f /tmp/requirements.txt
2026-04-25 05:55:24 +00:00
COPY nanobot/ nanobot/
COPY bridge/ bridge/
2026-04-26 07:27:02 +00:00
# 4. 源码层只安装 nanobot 本体,不重复解析/下载第三方依赖。
RUN --mount=type=cache,target=/root/.cache/pip \
pip install --no-compile --no-deps --no-build-isolation . && \
2026-04-25 05:55:24 +00:00
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/*
2026-03-01 16:26:03 +00:00
2026-04-25 05:55:24 +00:00
# 3. 仅复制已安装好的运行环境,避免把源码目录打进最终镜像
COPY --from=builder /opt/venv /opt/venv
2026-03-01 16:26:03 +00:00
WORKDIR /root
# 官方 gateway 模式,现在它会自动加载您的 DashboardChannel
CMD ["nanobot", "gateway"]