Files
b2bcall/docker-compose.yml
B2BCall Bootstrap eee6d7aece feat: add asterisk pjsip integration
- infrastructure/docker/asterisk.Dockerfile: Asterisk 22.10.1 LTS compilado
  do fonte oficial (Debian trixie nao distribui mais o pacote asterisk),
  com PJSIP, AMI, ARI, res_odbc/res_config_odbc, cdr_adaptive_odbc,
  cel_odbc, app_queue
- infrastructure/asterisk/config: templates renderizados no entrypoint
  (secrets via envsubst, nunca versionados) + sorcery.conf/extconfig.conf
  para PJSIP realtime, dialplan de teste (extensao 600)
- infrastructure/postgres/init/002-asterisk-realtime.sql: tabelas
  ps_endpoints/ps_auths/ps_aors/ps_contacts/ps_endpoint_id_ips/
  ps_registrations/cdr/cel no schema 'asterisk'
- infrastructure/nftables: protege AMI/ARI/SIP contra acesso pela LAN
  (interface ens18), trazido da Fase 9 do TODO para ja, sem afetar SSH
  nem a rede interna do Docker
- docker-compose.yml: servico asterisk em network_mode: host (RTP);
  Postgres publicado em 127.0.0.1:5432 (nao 0.0.0.0) para o Asterisk
  alcanca-lo, ja que host network nao enxerga a rede Docker interna

Testado: AMI login, ARI com auth (401 sem auth), pjsip realtime
consultando Postgres sem erro, dialplan originate -> CDR e CEL gravados
corretamente, healthcheck do compose passando.
2026-08-27 10:47:28 -03:00

124 lines
3.5 KiB
YAML

name: b2bcall
networks:
b2bcall-net:
driver: bridge
volumes:
postgres-data:
redis-data:
asterisk-lib:
asterisk-log:
asterisk-spool:
services:
postgres:
image: postgres:17-alpine
container_name: b2bcall-postgres
restart: unless-stopped
environment:
POSTGRES_DB: ${POSTGRES_DB:-b2bcall}
POSTGRES_USER: ${POSTGRES_USER:-b2bcall}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?POSTGRES_PASSWORD is required}
volumes:
- postgres-data:/var/lib/postgresql/data
- ./infrastructure/postgres/init:/docker-entrypoint-initdb.d:ro
networks:
- b2bcall-net
ports:
# Publicado SOMENTE em loopback do host: o container do Asterisk usa
# network_mode: host (necessário para RTP) e por isso não enxerga a
# rede Docker interna por nome — precisa alcançar o Postgres via
# 127.0.0.1. Isso nunca fica acessível pela LAN/Internet (não é 0.0.0.0).
- "127.0.0.1:${POSTGRES_PORT:-5432}:5432"
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-b2bcall} -d ${POSTGRES_DB:-b2bcall}"]
interval: 10s
timeout: 5s
retries: 5
start_period: 10s
logging:
driver: json-file
options:
max-size: "10m"
max-file: "3"
deploy:
resources:
limits:
memory: 512M
redis:
image: redis:7-alpine
container_name: b2bcall-redis
restart: unless-stopped
environment:
REDIS_PASSWORD: ${REDIS_PASSWORD:?REDIS_PASSWORD is required}
command: >
redis-server
--requirepass ${REDIS_PASSWORD:?REDIS_PASSWORD is required}
--maxmemory 100mb
--maxmemory-policy noeviction
--appendonly yes
volumes:
- redis-data:/data
networks:
- b2bcall-net
# Sem "ports": Redis não deve ficar acessível fora da rede Docker interna.
healthcheck:
test: ["CMD-SHELL", "redis-cli -a $$REDIS_PASSWORD --no-auth-warning ping | grep -q PONG"]
interval: 10s
timeout: 5s
retries: 5
start_period: 5s
logging:
driver: json-file
options:
max-size: "10m"
max-file: "3"
deploy:
resources:
limits:
memory: 160M
asterisk:
build:
context: .
dockerfile: infrastructure/docker/asterisk.Dockerfile
image: b2bcall-asterisk:22.10.1
container_name: b2bcall-asterisk
restart: unless-stopped
network_mode: host
# RTP exige uma faixa larga de portas UDP — inviável de mapear uma a uma
# em bridge network, por isso host mode (ver docs/ARCHITECTURE.md 3.1).
# AMI (5038), ARI (8088) e SIP (5060) ficam protegidos pelo nftables
# (infrastructure/nftables/b2bcall.nft), que bloqueia acesso pela LAN.
depends_on:
postgres:
condition: service_healthy
env_file:
- .env
environment:
# O Asterisk (host network) alcança o Postgres via loopback do host,
# não pelo nome do container (ver publicação de porta do serviço postgres).
ASTERISK_DB_HOST: ${ASTERISK_DB_HOST:-127.0.0.1}
volumes:
- ./infrastructure/asterisk/config:/etc/asterisk-templates:ro
- asterisk-lib:/var/lib/asterisk
- asterisk-log:/var/log/asterisk
- asterisk-spool:/var/spool/asterisk
healthcheck:
test: ["CMD-SHELL", "asterisk -rx 'core show uptime' | grep -q 'System uptime'"]
interval: 15s
timeout: 5s
retries: 5
start_period: 20s
logging:
driver: json-file
options:
max-size: "10m"
max-file: "3"
deploy:
resources:
limits:
memory: 400M