AnyBot/deploy/server/Dockerfile

35 lines
2.0 KiB
Docker
Raw Normal View History

# AnyBot without a window (`anybot --serve`) on a Linux server: the bots, routines, triggers and
# channels run around the clock; the person uses the phone. The bot's own computer is a sibling
# container started through the host's Docker (the socket is mounted in docker-compose.yml).
# Build from the repository root: docker build -f deploy/server/Dockerfile -t anybot-serve .
# JOBS limits parallel compiles on small servers (setup.sh sets it from the memory).
FROM rust:1-bookworm AS build
RUN apt-get update && apt-get install -y --no-install-recommends pkg-config libasound2-dev \
&& rm -rf /var/lib/apt/lists/*
ARG JOBS=
WORKDIR /src
COPY . .
# The registry, git and target caches survive rebuilds, so an update only recompiles what changed
# (and a dependency taken from GitHub isn't fetched again: a slow GitHub failed a server's update).
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/usr/local/cargo/git \
--mount=type=cache,target=/src/target \
cargo build --release --bin anybot ${JOBS:+-j $JOBS} \
&& cp target/release/anybot /anybot
FROM debian:bookworm-slim
# nodejs/npm (npx) and python3 + uv (uvx): the 連接器 (MCP servers) the bots use run here, at the
# brain, and the market's are started with `npx -y …` or `uvx …`. Without them every such
# connector failed to start and the bots had none of their tools.
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates curl git ripgrep poppler-utils docker.io openssh-client libasound2 \
nodejs npm python3 \
&& rm -rf /var/lib/apt/lists/*
COPY --from=ghcr.io/astral-sh/uv:0.13.6 /uv /uvx /usr/local/bin/
COPY --from=build /anybot /usr/local/bin/anybot
ENV ANYBOT_DATA_DIR=/data
# What npx and uvx download stays on the data volume: a rebuilt brain starts its connectors
# without fetching them all again.
ENV NPM_CONFIG_CACHE=/data/cache/npm UV_CACHE_DIR=/data/cache/uv UV_PYTHON_INSTALL_DIR=/data/cache/uv-python
VOLUME /data
CMD ["anybot", "--serve"]