BUH_bot/docker-compose.prod.yml

287 lines
6.3 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.

version: '3.8'
# Production Docker Compose для BUH Bot
# Использует готовые образы, nginx, мониторинг
services:
# Telegram бот
buh_bot:
image: igornadein/buh_bot:latest
container_name: buh_bot_prod
restart: always
environment:
- TELEGRAM_BOT_TOKEN=${TELEGRAM_BOT_TOKEN}
- MOYSKLAD_API_URL=${MOYSKLAD_API_URL:-https://api.moysklad.ru/api/remap/1.2}
- TZ=${TZ:-Europe/Moscow}
- LOG_LEVEL=${LOG_LEVEL:-INFO}
- DATA_DIR=/app/data
- LOGS_DIR=/app/logs
volumes:
# Персистентные данные на хосте
- ~/BUH_bot/data:/app/data
- ~/BUH_bot/logs:/app/logs
- ~/BUH_bot/temp_documents:/app/temp_documents
networks:
- buh_network
# Ограничения ресурсов для production
deploy:
resources:
limits:
cpus: '1.0'
memory: 1G
reservations:
cpus: '0.5'
memory: 512M
restart_policy:
condition: on-failure
delay: 5s
max_attempts: 3
window: 120s
# Healthcheck для мониторинга
healthcheck:
test: ["CMD", "python", "-c", "import sys; sys.exit(0)"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
# Логирование с ротацией
logging:
driver: "json-file"
options:
max-size: "50m"
max-file: "5"
labels: "service=buh_bot,environment=production"
labels:
- "com.buh_bot.service=telegram-bot"
- "com.buh_bot.environment=production"
# Nginx reverse proxy (для webhook режима или API)
nginx:
image: nginx:alpine
container_name: buh_bot_nginx
restart: always
ports:
- "${NGINX_HTTP_PORT:-80}:80"
- "${NGINX_HTTPS_PORT:-443}:443"
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
- ./nginx/ssl:/etc/nginx/ssl:ro
- /var/log/nginx:/var/log/nginx
networks:
- buh_network
depends_on:
- buh_bot
deploy:
resources:
limits:
cpus: '0.5'
memory: 256M
healthcheck:
test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost/health"]
interval: 30s
timeout: 5s
retries: 3
logging:
driver: "json-file"
options:
max-size: "20m"
max-file: "3"
# Prometheus для метрик
prometheus:
image: prom/prometheus:latest
container_name: buh_bot_prometheus
restart: always
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
- '--storage.tsdb.retention.time=30d'
volumes:
- ./monitoring/prometheus.yml:/etc/prometheus/prometheus.yml:ro
- prometheus_data:/prometheus
networks:
- buh_network
ports:
- "${PROMETHEUS_PORT:-9090}:9090"
deploy:
resources:
limits:
cpus: '0.5'
memory: 512M
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
# Grafana для визуализации метрик
grafana:
image: grafana/grafana:latest
container_name: buh_bot_grafana
restart: always
environment:
- GF_SECURITY_ADMIN_USER=${GRAFANA_USER:-admin}
- GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_PASSWORD:-admin}
- GF_INSTALL_PLUGINS=
volumes:
- grafana_data:/var/lib/grafana
- ./monitoring/grafana/dashboards:/etc/grafana/provisioning/dashboards:ro
- ./monitoring/grafana/datasources:/etc/grafana/provisioning/datasources:ro
networks:
- buh_network
ports:
- "${GRAFANA_PORT:-3000}:3000"
depends_on:
- prometheus
deploy:
resources:
limits:
cpus: '0.5'
memory: 512M
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
# Node Exporter для метрик хоста
node_exporter:
image: prom/node-exporter:latest
container_name: buh_bot_node_exporter
restart: always
command:
- '--path.procfs=/host/proc'
- '--path.sysfs=/host/sys'
- '--collector.filesystem.mount-points-exclude=^/(sys|proc|dev|host|etc)($$|/)'
volumes:
- /proc:/host/proc:ro
- /sys:/host/sys:ro
- /:/rootfs:ro
networks:
- buh_network
ports:
- "9100:9100"
deploy:
resources:
limits:
cpus: '0.2'
memory: 128M
logging:
driver: "json-file"
options:
max-size: "5m"
max-file: "2"
# cAdvisor для метрик контейнеров
cadvisor:
image: gcr.io/cadvisor/cadvisor:latest
container_name: buh_bot_cadvisor
restart: always
privileged: true
volumes:
- /:/rootfs:ro
- /var/run:/var/run:ro
- /sys:/sys:ro
- /var/lib/docker/:/var/lib/docker:ro
- /dev/disk/:/dev/disk:ro
networks:
- buh_network
ports:
- "8080:8080"
deploy:
resources:
limits:
cpus: '0.3'
memory: 256M
logging:
driver: "json-file"
options:
max-size: "5m"
max-file: "2"
# Watchtower для автоматического обновления образов
watchtower:
image: containrrr/watchtower:latest
container_name: buh_bot_watchtower
restart: always
environment:
- WATCHTOWER_CLEANUP=true
- WATCHTOWER_POLL_INTERVAL=3600
- WATCHTOWER_INCLUDE_STOPPED=false
- WATCHTOWER_REVIVE_STOPPED=false
- WATCHTOWER_NOTIFICATIONS=shoutrrr
- WATCHTOWER_NOTIFICATION_URL=${WATCHTOWER_NOTIFICATION_URL:-}
volumes:
- /var/run/docker.sock:/var/run/docker.sock
networks:
- buh_network
deploy:
resources:
limits:
cpus: '0.2'
memory: 128M
logging:
driver: "json-file"
options:
max-size: "5m"
max-file: "2"
# Сети
networks:
buh_network:
driver: bridge
ipam:
config:
- subnet: 172.20.0.0/16
# Volumes для персистентных данных
volumes:
prometheus_data:
driver: local
grafana_data:
driver: local