# 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
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates curl git ripgrep poppler-utils docker.io openssh-client libasound2 \
    && rm -rf /var/lib/apt/lists/*
COPY --from=build /anybot /usr/local/bin/anybot
ENV ANYBOT_DATA_DIR=/data
VOLUME /data
CMD ["anybot", "--serve"]
