Files
bot-telegram/docker-compose.yml
2025-09-22 11:54:42 +05:00

88 lines
2.3 KiB
YAML

services:
# База данных PostgreSQL (отдельный сервис)
postgres:
image: postgres:15
container_name: telegram_bot_db
environment:
POSTGRES_DB: ${DB_NAME:-botdb}
POSTGRES_USER: ${DB_USER:-botuser}
POSTGRES_PASSWORD: ${DB_PASSWORD:-your_password_here}
ports:
- "${DB_PORT:-5432}:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
networks:
- bot_network
healthcheck:
test: ["CMD-SHELL", "pg_isready -h localhost -p 5432 -q -U ${DB_USER:-botuser}"]
interval: 10s
timeout: 5s
retries: 5
# Telegram Bot приложение
bot:
build: .
container_name: telegram_bot
environment:
# Загружаем переменные из .env файла
TELEGRAM_BOT_TOKEN: ${TELEGRAM_BOT_TOKEN}
DB_HOST: postgres
DB_PORT: ${DB_PORT:-5432}
DB_NAME: ${DB_NAME:-botdb}
DB_USER: ${DB_USER:-botuser}
DB_PASSWORD: ${DB_PASSWORD}
APP_ENV: ${APP_ENV:-production}
LOG_LEVEL: ${LOG_LEVEL:-INFO}
DEBUG: ${DEBUG:-False}
command: python main.py --mode bot
depends_on:
postgres:
condition: service_healthy
networks:
- bot_network
restart: unless-stopped
volumes:
- ./images:/app/images:ro
# API сервер (опционально)
api:
build: .
container_name: telegram_bot_api
environment:
# Настройки подключения к PostgreSQL
DB_HOST: postgres
DB_PORT: ${DB_PORT:-5432}
DB_NAME: ${DB_NAME:-botdb}
DB_USER: ${DB_USER:-botuser}
DB_PASSWORD: ${DB_PASSWORD}
# Настройки API сервера
API_HOST: 0.0.0.0
API_PORT: ${API_PORT:-8000}
API_RELOAD: "false"
LOG_LEVEL: ${LOG_LEVEL:-INFO}
APP_ENV: ${APP_ENV:-production}
command: python main.py --mode api
ports:
- "${API_PORT:-8000}:${API_PORT:-8000}"
depends_on:
postgres:
condition: service_healthy
networks:
- bot_network
restart: unless-stopped
profiles:
- api
# Сети для изоляции сервисов
networks:
bot_network:
driver: bridge
# Постоянное хранение данных БД
volumes:
postgres_data: