agenthub/deploy/Dockerfile.nanobot

51 lines
2.3 KiB
Docker
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# nanobot 运行时镜像(只跑 `nanobot serve` 这个 OpenAI 兼容端点)
# docker build -f deploy/Dockerfile.nanobot -t nanobot:agenthub soucecode/nanobot
#
# 与上游 soucecode/nanobot/Dockerfile 的差别只有一个:这里 NANOBOT_SKIP_WEBUI_BUILD=1
# 跳过 Vite/WebUI 构建(serve 不需要 nanobot/web/dist),少一个 node 阶段,构建快很多。
# 要 WebUI 就用上游那份 Dockerfile。
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim
ENV PYTHONUNBUFFERED=1 \
VIRTUAL_ENV=/app/.venv \
PATH=/app/.venv/bin:$PATH
RUN apt-get update \
&& apt-get install -y --no-install-recommends ca-certificates libmagic1 \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
RUN uv venv --seed "$VIRTUAL_ENV"
# 先装依赖(缓存层):hatch 的 build hook 需要 hatch_build.py 在场。
# `serve` 属于 nanobot 的 api extra(少了它起进程时会打印 "aiohttp is required" 后退出)。
ARG NANOBOT_EXTRAS=api
COPY pyproject.toml README.md LICENSE THIRD_PARTY_NOTICES.md hatch_build.py ./
RUN mkdir -p nanobot && touch nanobot/__init__.py \
&& NANOBOT_SKIP_WEBUI_BUILD=1 uv pip install --python "$VIRTUAL_ENV/bin/python" --no-cache ".[${NANOBOT_EXTRAS}]" \
&& rm -rf nanobot
COPY nanobot/ nanobot/
COPY scripts/ scripts/
RUN NANOBOT_SKIP_WEBUI_BUILD=1 uv pip install --python "$VIRTUAL_ENV/bin/python" --no-cache ".[${NANOBOT_EXTRAS}]"
RUN useradd -m -u 1000 -s /bin/bash nanobot \
&& mkdir -p /home/nanobot/.nanobot \
&& chown -R nanobot:nanobot /home/nanobot /app
# AgentHub 内置 channel:nanobot 只扫自己安装树里的包
# (pkgutil.iter_modules(nanobot.channels.__path__)),所以这里预置一个软链,
# 真目录由 compose 挂到 /opt/agenthub/channel。没挂载时目标不存在,
# nanobot 的通道发现会安静跳过,镜像单独跑 serve 不受影响。
RUN SITE=/app/.venv/lib/python3.12/site-packages/nanobot/channels \
&& mkdir -p /opt/agenthub/channel "${SITE}" \
&& ln -sfn /opt/agenthub/channel/agenthub "${SITE}/agenthub" \
&& ln -sfn /opt/agenthub/channel/agenthub /app/nanobot/channels/agenthub \
&& chown -R nanobot:nanobot /opt/agenthub
ENV HOME=/home/nanobot
USER nanobot
# serve 的默认端口,容器内保持 8901;对外映射由 compose 决定
EXPOSE 8901
CMD ["serve", "--host", "0.0.0.0", "--port", "8901", "--workspace", "/home/nanobot/.nanobot/workspace"]