# AgentRun as a server and two runners on one store, all from one image (packages/serve/docker/Dockerfile): the server # serves the API and sets the store up; each runner claims runs from the store and runs them. deploy/README.md says how # to run it, and how to run more runners. In this directory, once: # printf 'AGENTRUN_SEAL_KEY=%s\n' "$(openssl rand -base64 32)" > .env && chmod 600 .env # docker compose up -d --build # Today the store is SQLite in the shared /data volume. With AGENTRUN_STORE_URL set to a postgres:// URL the store is # Postgres instead (the "pg" profile below runs one); a server and runners that do not read that setting yet keep SQLite. # The server's port is published on this machine's loopback only: put a reverse proxy with TLS in front of it before you # publish it anywhere else. # What the server and every runner are given. AGENTRUN_STORE_URL, AGENTRUN_STORE_SCHEMA and AGENTRUN_STORE_POOL_SIZE # with no value are passed only when set here (in .env or the shell), and left unset otherwise. AGENTRUN_STORE_URL holds the database's password, so it # is a secret like the seal key: keep it in .env (0600), never written in this file. The launcher moves each secret out of # the process environment and hands it to the server or runner over a pipe, so no run's process ever sees it. The model keys are the runners' (a runner makes a run's # model requests) and the server's (it checks a model can run before a run starts); each is empty when not set. x-agentrun-env: &agentrun-env AGENTRUN_SEAL_KEY: ${AGENTRUN_SEAL_KEY:?make deploy/.env with AGENTRUN_SEAL_KEY (openssl rand -base64 32); the server and every runner need the same one} AGENTRUN_STORE_URL: AGENTRUN_STORE_SCHEMA: AGENTRUN_STORE_POOL_SIZE: AGENT_MODEL: ${AGENT_MODEL:-} AGENT_MODEL_FAST: ${AGENT_MODEL_FAST:-} AGENT_MODEL_STRONG: ${AGENT_MODEL_STRONG:-} AGENT_MODEL_BASE_URL: ${AGENT_MODEL_BASE_URL:-} AGENT_MODEL_API_KEY: ${AGENT_MODEL_API_KEY:-} ANTHROPIC_API_KEY: ${ANTHROPIC_API_KEY:-} OPENAI_API_KEY: ${OPENAI_API_KEY:-} OPENROUTER_API_KEY: ${OPENROUTER_API_KEY:-} # A runner: the same image with `runner --data /data --name ` as its command. It never sets the store up, so it # starts once the server is healthy, and a runner that still finds a store it does not know (exit 3) is started again. # On SIGTERM it claims nothing more and lets each busy run finish its turn for up to its drain (--drain-timeout, else # AGENTRUN_DRAIN_TIMEOUT, else 6 s), then hands the rest back and gives up a stuck loop 25 s after that: 31 s in all, # inside the 35 s it is given. # Each runner claims runs by the memory it has, each run weighed by its harness (a claude-agent run 288 MB, a pi run # 128 MB), and reads that memory from its container's limit. Without a limit every runner reads the whole host's and # budgets all of it, so two runners on one host could take twice what it holds. Each gets 2 GB here (runs then hold # 1920 MB: six claude-agent runs or fifteen pi runs at once, the rest wait queued); set AGENTRUN_RUNNER_MEMORY in .env # (512m, 4g, ...) so that the runners' limits together, with room left for the server, fit the host. A run whose # harness never fits a runner's limit (an opencode run, 704 MB, under 512m) fails at that runner's claim, in words, and # never starts there. x-runner: &runner image: ${AGENTRUN_IMAGE:-ghcr.io/parcha-ai/agentrun-server:beta} volumes: - agentrun-data:/data depends_on: server: condition: service_healthy restart: on-failure stop_grace_period: 35s mem_limit: ${AGENTRUN_RUNNER_MEMORY:-2g} # A runner's health: its heartbeat (runner-.alive in /data) is younger than 20 s. `runner --check` reads no store # and needs no secret, so it runs with an empty environment: the seal key the container was given stays out of it. x-runner-check: &runner-check interval: 10s timeout: 5s retries: 3 start_period: 15s services: # The server alone (--no-runner): the runners below run every run. It listens on its own container's address (its # hostname, `server`), where Docker publishes the port and the runners never call. server: image: ${AGENTRUN_IMAGE:-ghcr.io/parcha-ai/agentrun-server:beta} build: context: .. dockerfile: packages/serve/docker/Dockerfile hostname: server command: ["--data", "/data", "--listen", "server", "--port", "7340", "--drain-timeout", "6s", "--no-runner"] ports: - "127.0.0.1:${AGENTRUN_PORT:-7340}:7340" # key-gate: loopback-rule this machines loopback, where the port is published volumes: - agentrun-data:/data environment: <<: *agentrun-env AGENTRUN_TOKEN: ${AGENTRUN_TOKEN:-} # The runners whose live viewers (a run's browser, desktop or phone, watched and taken over) this server reaches # on this stack's own network: each by the host it names (its AGENTRUN_RUNNER_LIVE_HOST). A host not listed here # is never dialled. AGENTRUN_RUNNER_HOSTS: runner-1,runner-2 AGENTRUN_PUBLIC_URL: "${AGENTRUN_PUBLIC_URL:-http://127.0.0.1:7340/}" # key-gate: loopback-rule the published loopback port, the printed link healthcheck: test: ["CMD", "env", "-i", "/usr/local/bin/node", "-e", "fetch('http://server:7340/v2/health').then(({ ok, status }) => { if (!ok) throw new Error(String(status)) })"] interval: 10s timeout: 5s retries: 3 start_period: 15s restart: unless-stopped stop_grace_period: 15s # Each runner names the host the server reaches its live viewers at (its own, on this stack's network), and its # viewers listen there, taking only the server's signed requests (live-reach.ts). The hop is this stack's own network. runner-1: <<: *runner hostname: runner-1 command: ["runner", "--data", "/data", "--name", "runner-1"] environment: <<: *agentrun-env AGENTRUN_RUNNER_LIVE_HOST: runner-1 healthcheck: <<: *runner-check test: ["CMD", "env", "-i", "/usr/local/bin/node", "/opt/agentrun/packages/serve/dist/cli.js", "runner", "--check", "--data", "/data", "--name", "runner-1"] runner-2: <<: *runner hostname: runner-2 command: ["runner", "--data", "/data", "--name", "runner-2"] environment: <<: *agentrun-env AGENTRUN_RUNNER_LIVE_HOST: runner-2 healthcheck: <<: *runner-check test: ["CMD", "env", "-i", "/usr/local/bin/node", "/opt/agentrun/packages/serve/dist/cli.js", "runner", "--check", "--data", "/data", "--name", "runner-2"] # Postgres for the store, only with `--profile pg`, for when the store takes AGENTRUN_STORE_URL: # AGENTRUN_PG_PASSWORD= and # AGENTRUN_STORE_URL=postgres://agentrun:@postgres:5432/agentrun in .env. # Nothing waits on it: a server that cannot reach its store yet exits and is started again. postgres: profiles: ["pg"] image: postgres:17.11-trixie@sha256:ff87138949ad9a46f32ff23bd6852b52ce024a13dffe9b4087be98292cdd3b4f environment: POSTGRES_USER: agentrun POSTGRES_DB: agentrun POSTGRES_PASSWORD: ${AGENTRUN_PG_PASSWORD:-} volumes: - agentrun-pg:/var/lib/postgresql/data healthcheck: test: ["CMD", "pg_isready", "-U", "agentrun", "-d", "agentrun"] interval: 10s timeout: 5s retries: 5 restart: unless-stopped volumes: agentrun-data: agentrun-pg: