Files
Media-download-telegram-bot/docker-compose.yml
T
MichilisandClaude Fable 5.2 7d4893bc3f Phase 4: scale out
Remote workers, Postgres and S3, all chosen by configuration.

- Pull-based worker protocol over HTTP: claim (long poll), heartbeat,
  complete, fail, upload, source, probe. Workers need no inbound ports
- cmd/worker: standalone stateless worker with health endpoint and
  scheduled yt-dlp self-update
- Per-worker bearer tokens, stored hashed, revocable; identity always
  taken from the token; actions only on jobs the worker holds a lease for
- Tags: site_tags routes a site's jobs and lookups to workers that carry
  the required tags
- Drain, /workers, /ytdlp update, and "core worker add|revoke|list"
- Link lookups can run on remote workers (PROBE_MODE), so the core needs
  no yt-dlp and no residential address
- Postgres backend with pgx, same schema and queries; per-user advisory
  lock and job row lock where SQLite's serial writes were relied on
- The whole test suite runs on SQLite and on Postgres
- S3 storage backend with presigned worker uploads, sharing a conformance
  suite with the local backend
- Dockerfile with core, worker and faketelegram targets, docker-compose
  with optional Postgres and local Bot API server, systemd units
- deploy/acceptance/kill-worker.sh: kills a worker mid-job and checks
  that the other one delivers the file
- Fixes found on the way: /cancel could let the next playlist item start;
  a refund note could be missing when the sweep refunded first

Docker was not available on the build machine: the compose files were
validated with "docker compose config" only. The acceptance scenario was
run with real processes.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-18 09:27:11 +00:00

117 lines
3.4 KiB
YAML

# The Noderunners Download Bot: core, two workers, and two optional services.
#
# cp .env.example .env # set BOT_TOKEN, WORKER_A_TOKEN, WORKER_B_TOKEN
# docker compose up -d --build
#
# Optional services are behind profiles:
#
# docker compose --profile postgres up -d # Postgres instead of SQLite
# docker compose --profile local-api up -d # local Bot API server, 2 GB uploads
#
# See docs/OPERATIONS.md for what to put in .env for each of them.
name: dlbot
x-worker: &worker
build:
context: .
dockerfile: deploy/Dockerfile
target: worker
image: dlbot-worker:local
restart: unless-stopped
depends_on:
core:
condition: service_healthy
# A worker has no inbound ports. It only needs to reach the core and the
# sites it downloads from.
environment: &worker-env
CORE_URL: http://core:8080
WORKER_CONCURRENCY: ${WORKER_CONCURRENCY:-2}
WORKER_TEMP_DIR: /data/tmp
YTDLP_EXTRA_ARGS: ${YTDLP_EXTRA_ARGS:-}
LOG_LEVEL: ${LOG_LEVEL:-info}
stop_grace_period: 30s
services:
core:
build:
context: .
dockerfile: deploy/Dockerfile
target: core
image: dlbot-core:local
restart: unless-stopped
# Everything from .env.example can go in .env. The core refuses to
# start without BOT_TOKEN, so a missing file is noticed at once.
env_file:
- path: .env
required: false
environment:
HTTP_LISTEN: ":8080"
# Downloads run on the workers below, not inside the core.
WORKER_EMBEDDED: "false"
WORKER_TOKENS: "worker-a:${WORKER_A_TOKEN:?set WORKER_A_TOKEN in .env},worker-b:${WORKER_B_TOKEN:?set WORKER_B_TOKEN in .env}"
volumes:
- core-data:/data
ports:
# Bound to localhost. Put a TLS reverse proxy in front for PUBLIC_URL.
- "127.0.0.1:${CORE_PORT:-8080}:8080"
stop_grace_period: 30s
worker-a:
<<: *worker
environment:
<<: *worker-env
WORKER_TOKEN: ${WORKER_A_TOKEN:?set WORKER_A_TOKEN in .env}
WORKER_TAGS: ${WORKER_A_TAGS:-}
volumes:
- worker-a-data:/data
worker-b:
<<: *worker
environment:
<<: *worker-env
WORKER_TOKEN: ${WORKER_B_TOKEN:?set WORKER_B_TOKEN in .env}
WORKER_TAGS: ${WORKER_B_TAGS:-}
volumes:
- worker-b-data:/data
# Optional: Postgres. In .env set
# DB_DRIVER=postgres
# DB_DSN=postgres://dlbot:<POSTGRES_PASSWORD>@postgres:5432/dlbot?sslmode=disable
postgres:
profiles: ["postgres"]
image: postgres:16-alpine
restart: unless-stopped
environment:
POSTGRES_USER: dlbot
POSTGRES_DB: dlbot
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-change-me}
volumes:
- postgres-data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U dlbot -d dlbot"]
interval: 10s
timeout: 5s
retries: 5
# Optional: local Bot API server, for files up to 2 GB. In .env set
# TELEGRAM_API_URL=http://telegram-bot-api:8081
# TELEGRAM_MAX_UPLOAD_MB=2000
# and TELEGRAM_API_ID / TELEGRAM_API_HASH from https://my.telegram.org.
telegram-bot-api:
profiles: ["local-api"]
image: aiogram/telegram-bot-api:latest
restart: unless-stopped
environment:
TELEGRAM_API_ID: ${TELEGRAM_API_ID:-}
TELEGRAM_API_HASH: ${TELEGRAM_API_HASH:-}
volumes:
- telegram-bot-api-data:/var/lib/telegram-bot-api
volumes:
core-data:
worker-a-data:
worker-b-data:
postgres-data:
telegram-bot-api-data: