AnyBot/deploy/server/docker-compose.yml

209 lines
11 KiB
YAML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Everything on one small server: the account server (relay), HTTPS (Caddy), and AnyBot itself.
# Set up: make server (= ./setup.sh: asks for the address, account and keys, writes .env and
# Caddyfile, starts everything and checks it). Settings live only in .env; after changing it, or
# to update: make update-server. Logs: make server-logs.
# Don't start this with a bare `docker compose up`: on a host with both rootless and root Docker
# that can reach the daemon without this server's data and bring up a second, empty server; the
# make targets always use the one in .env (DOCKER_SOCKET) and the HTTPS port in its address.
# AI keys: set them in .env, or set ANYBOT_RESTORE_FROM_ACCOUNT=1 to start from the newest backup
# your Mac made (bots, chats, routines and the keys you set there).
#
# 大腦: this AnyBot is the brain of the account. It keeps the bots, chats, memory and routines,
# and works even while your computers sleep. On each of your computers: 設定 › 手機與帳號 ›
# 大腦 › 「改用它當大腦」. Those computers then show these bots, and the bots can use them as hands
# (screen, files, browser), asking you first as usual. A Linux computer without a screen can be
# hands too: run `anybot setup` there and pick this brain.
services:
relay:
build:
context: ../..
dockerfile: relay/Dockerfile
args: { JOBS: "${ANYBOT_BUILD_JOBS:-}" }
restart: unless-stopped
environment:
# Your public address (for the links of sites the bots publish), e.g. https://anybot.example.com
ANYBOT_RELAY_PUBLIC_URL: "${ANYBOT_RELAY_PUBLIC_URL:-}"
ANYBOT_RELAY_INVITE: "${ANYBOT_RELAY_INVITE:-}"
# 大腦管理員 (brains, below) asks for each account's cloud brain with this key.
ANYBOT_RELAY_MANAGER_TOKEN: "${ANYBOT_RELAY_MANAGER_TOKEN:-}"
# Caddy (or `tailscale serve`) is in front: the caller's address is the one it reports.
# Without this every login attempt counts as coming from the proxy, and a few wrong
# passwords from anyone lock that account for everyone.
RELAY_TRUST_PROXY: "1"
# Who asked is believed only from Caddy (it sends this): a cloud brain talking to the
# account server straight can't make up the address of its requests.
ANYBOT_RELAY_PROXY_SECRET: "${ANYBOT_PROXY_SECRET:-}"
volumes:
- relay-data:/data
# The 大腦管理員 reaches it on a network of its own (relay-manager): its key never crosses
# the one the brains share.
networks:
default: {}
manager:
aliases: [relay-manager]
caddy:
image: caddy:2
restart: unless-stopped
environment:
ANYBOT_PROXY_SECRET: "${ANYBOT_PROXY_SECRET:-}"
ports: ["80:80", "443:443"]
volumes:
# Written by setup.sh (your domain); ../../relay/Caddyfile is the template.
- ./Caddyfile:/etc/caddy/Caddyfile:ro
- caddy-data:/data
depends_on: [relay]
# The brain of a server set up for one account (.env has ANYBOT_USER — setup.sh turns this
# profile on for it). A server set up the easy way has none: 大腦管理員 (brains) gives every
# account, this one's included, a cloud brain of its own.
anybot:
profiles: ["owner-brain"]
image: anybot-brain:local
build:
context: ../..
dockerfile: deploy/server/Dockerfile
args: { JOBS: "${ANYBOT_BUILD_JOBS:-}" }
restart: unless-stopped
depends_on: [relay]
# A second wall for the bots' computer (optional, Linux): install gVisor on this host
# (see gvisor.dev/docs "Installation" for the apt repository + `apt-get install runsc`,
# then register it in /etc/docker/daemon.json: {"runtimes": {"runsc": {"path": "runsc"}}}
# and `systemctl restart docker`). In AnyBot: 設定 › 電腦 › 在哪裡執行 › 容器隔離 →
# 「強隔離(gVisor)」, then rebuild the computer (更新). The box gets a virtualized
# kernel and Chromium's own sandbox comes back on. On a host without runsc the box won't
# start — switch 容器隔離 back to 標準.
environment:
ANYBOT_ACCOUNT: "http://relay:8080|${ANYBOT_USER:-}"
ANYBOT_ACCOUNT_PASSWORD: "${ANYBOT_PASSWORD:-}"
ANYBOT_HOST_NAME: "${ANYBOT_HOST_NAME:-雲端 AnyBot}"
# First start on a new server: make the account (the first one needs no invite).
ANYBOT_ACCOUNT_CREATE: "1"
ANYBOT_RELAY_INVITE: "${ANYBOT_RELAY_INVITE:-}"
XAI_API_KEY: "${XAI_API_KEY:-}"
ANTHROPIC_API_KEY: "${ANTHROPIC_API_KEY:-}"
OPENAI_API_KEY: "${OPENAI_API_KEY:-}"
GEMINI_API_KEY: "${GEMINI_API_KEY:-}"
ANYBOT_RESTORE_FROM_ACCOUNT: "${ANYBOT_RESTORE_FROM_ACCOUNT:-}"
# The bots' computer goes by its own name: a desktop AnyBot on this same machine keeps
# "anybot-box" for itself (and used to pause the brain's one as idle).
ANYBOT_BOX_NAME: "anybot-brain-box"
# The Docker socket is not mounted here any more (a mounted socket is full control of this
# host). The bots' computer is driven through the filtered proxy below, which only answers
# the calls cloudbox.rs makes: containers (run/start/stop/rm/inspect/ps), exec, volumes,
# images and the box image build. DOCKER_HOST is the plain `docker` CLI default, which is
# what src/cloudbox.rs uses when its own docker_host setting is empty.
DOCKER_HOST: "tcp://docker-socket-proxy:2375"
# 語音 on this server (the voice service below, when it is on): 設定 › 語音 is filled in
# with it once; what you choose there afterwards stays.
ANYBOT_VOICE_URL: "${ANYBOT_VOICE_URL:-}"
ANYBOT_VOICE_LISTEN_MODEL: "${ANYBOT_VOICE_LISTEN_MODEL:-}"
ANYBOT_VOICE_SPEAK_MODEL: "${ANYBOT_VOICE_SPEAK_MODEL:-}"
ANYBOT_VOICE_VOICE: "${ANYBOT_VOICE_VOICE:-}"
# 記憶的本機語意模型 is fetched from Hugging Face on the first start (530 MB, kept as
# 130 MB under /data/models); a mirror when that can't be reached, e.g. https://hf-mirror.com.
ANYBOT_HF_BASE: "${ANYBOT_HF_BASE:-}"
networks: [default, docker-api]
volumes:
- anybot-data:/data
# 大腦管理員 (src/brains.rs): every account on this account server gets a cloud brain of its
# own, a container `anybot-brain-<account>` made with this same image (own data, own bots'
# computer), signed in with a host token the account server hands it — no password on the
# server. Docker only through the filtered proxy, as for the bots' computer.
brains:
image: anybot-brain:local
build:
context: ../..
dockerfile: deploy/server/Dockerfile
args: { JOBS: "${ANYBOT_BUILD_JOBS:-}" }
restart: unless-stopped
depends_on: [relay, docker-socket-proxy]
command: ["anybot", "--brains"]
# (A stop is a stop: an init passes it on and the manager ends between jobs — given the time
# a brain needs to finish its own turn.)
init: true
stop_grace_period: 2m
environment:
ANYBOT_RELAY_MANAGER_TOKEN: "${ANYBOT_RELAY_MANAGER_TOKEN:-}"
# The account server on the manager's own network; the brains reach it on theirs.
ANYBOT_RELAY_INTERNAL: "http://relay-manager:8080"
ANYBOT_BRAIN_RELAY: "http://relay:8080"
# Accounts whose brains get Docker besides the owner's; every account from before the
# manager too; each brain's memory.
ANYBOT_BRAINS_DOCKER: "${ANYBOT_BRAINS_DOCKER:-}"
ANYBOT_BRAINS_ALL: "${ANYBOT_BRAINS_ALL:-}"
ANYBOT_BRAIN_MEMORY: "${ANYBOT_BRAIN_MEMORY:-}"
# The one-account setup's own brain (anybot, above) is left to itself.
# The one-account setup's own brain, and accounts you list to stop theirs (then
# `docker stop` it: the manager leaves it stopped).
ANYBOT_BRAINS_SKIP: "${ANYBOT_USER:-},${ANYBOT_BRAINS_SKIP:-}"
ANYBOT_BRAINS_MAX: "${ANYBOT_BRAINS_MAX:-}"
ANYBOT_BRAIN_CPUS: "${ANYBOT_BRAIN_CPUS:-}"
DOCKER_HOST: "tcp://docker-socket-proxy:2375"
ANYBOT_VOICE_URL: "${ANYBOT_VOICE_URL:-}"
ANYBOT_VOICE_LISTEN_MODEL: "${ANYBOT_VOICE_LISTEN_MODEL:-}"
ANYBOT_VOICE_SPEAK_MODEL: "${ANYBOT_VOICE_SPEAK_MODEL:-}"
ANYBOT_VOICE_VOICE: "${ANYBOT_VOICE_VOICE:-}"
ANYBOT_HF_BASE: "${ANYBOT_HF_BASE:-}"
networks: [default, docker-api, manager]
volumes:
- brains-data:/data
# 語音 (optional: ./setup.sh asks; COMPOSE_PROFILES=voice in .env turns it on): speech to text
# (Whisper) on this server's CPU for every screen and phone, with no key. speaches (MIT) speaks
# OpenAI's audio API. No port is published: only the brain reaches it, at http://voice:8000/v1.
# The model is downloaded once, into voice-models. (It reads English aloud but not Chinese:
# reading aloud is set in 設定 › 語音, e.g. xAI.)
voice:
# The build checked with AnyBot (latest-cpu of 2025-09-19; the 0.8.2-cpu tag is older).
image: ghcr.io/speaches-ai/speaches@sha256:21e3df06d842fb7802ab470dd77c25f0e8c0d22950e8d8c6ae886e851af53ef8
profiles: ["voice"]
restart: unless-stopped
# The brain asks it for ANYBOT_VOICE_LISTEN_MODEL at each start (this build has no
# PRELOAD_MODELS): downloaded the first time, found at once after that.
environment:
WHISPER__COMPUTE_TYPE: "int8"
# Stay loaded: the first sentence after a quiet hour shouldn't wait for a model to load.
WHISPER__TTL: "-1"
volumes:
- voice-models:/home/ubuntu/.cache/huggingface/hub
docker-socket-proxy:
# https://github.com/Tecnativa/docker-socket-proxy: a small nginx in front of the Docker
# socket with an endpoint allowlist. Keep this list minimal: adding an API here widens what
# a compromised brain can do on this host (no AUTH, no SECRETS, no SWARM, no plugins).
image: tecnativa/docker-socket-proxy:0.3.0
restart: unless-stopped
environment:
CONTAINERS: "1" # run, start, stop, rm, inspect, ps (the box's lifecycle)
EXEC: "1" # docker exec: every screen step, box_exec, snapshots
IMAGES: "1" # inspect/create the box image (build uploads it)
BUILD: "1" # 更新/重建 builds the box image
# A daemon of Docker 23 or newer says BuildKit is its builder (_ping: Builder-Version 2),
# and the brain's docker then builds through a session: without these two the proxy
# refuses it (403) and 更新/重建 can't make the box image. They reach only the builder.
GRPC: "1"
SESSION: "1"
VOLUMES: "1" # anybot-box-home: inspect, create, rm (Reset/Restore)
NETWORKS: "1" # inspect/attach (docker run needs the bridge network)
INFO: "1" # docker info: whether a brain can be held to a share of the CPUs
POST: "1"
GET: "1"
# DOCKER_SOCKET in .env: the Docker this server lives on (setup.sh writes it at the first setup,
# e.g. /run/user/<uid>/docker.sock for rootless Docker, and starts compose on that same one).
# The default /var/run/docker.sock is the root daemon; on a rootless host the proxy answers 503.
networks: [docker-api]
volumes:
- ${DOCKER_SOCKET:-/var/run/docker.sock}:/var/run/docker.sock:ro
networks:
# Only `anybot`, `brains` and the cloud brains given Docker (the owner's) share this internal
# network with `docker-socket-proxy`; `relay`, `caddy`, `voice` and the other brains cannot
# reach port 2375.
docker-api:
internal: true
# The account server and the 大腦管理員 only.
manager:
internal: true
volumes:
relay-data:
caddy-data:
anybot-data:
brains-data:
voice-models: