Refactor Docker and configuration files for improved structure and functionality
- Updated `.dockerignore` to include additional development and temporary files, enhancing build efficiency. - Modified `.gitignore` to remove unnecessary entries and streamline ignored files. - Enhanced `docker-compose.yml` with health checks, resource limits, and improved environment variable handling for better service management. - Refactored `Dockerfile.bot` to utilize a multi-stage build for optimized image size and security. - Improved `Makefile` with new commands for deployment, migration, and backup, along with enhanced help documentation. - Updated `requirements.txt` to include new dependencies for environment variable management. - Refactored metrics handling in the bot to ensure proper initialization and collection.
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
telegram-bot:
|
||||
build:
|
||||
@@ -5,27 +7,63 @@ services:
|
||||
dockerfile: Dockerfile.bot
|
||||
container_name: telegram-bot
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "8000:8000" # Экспозиция порта для метрик
|
||||
expose:
|
||||
- "8000"
|
||||
environment:
|
||||
- PYTHONPATH=/app
|
||||
- DOCKER_CONTAINER=true
|
||||
- LOG_LEVEL=${LOG_LEVEL:-INFO}
|
||||
- LOG_RETENTION_DAYS=${LOG_RETENTION_DAYS:-30}
|
||||
- METRICS_HOST=${METRICS_HOST:-0.0.0.0}
|
||||
- METRICS_PORT=${METRICS_PORT:-8000}
|
||||
# Telegram settings
|
||||
- TELEGRAM_BOT_TOKEN=${BOT_TOKEN}
|
||||
- TELEGRAM_LISTEN_BOT_TOKEN=${LISTEN_BOT_TOKEN}
|
||||
- TELEGRAM_TEST_BOT_TOKEN=${TEST_BOT_TOKEN}
|
||||
- TELEGRAM_PREVIEW_LINK=${PREVIEW_LINK:-false}
|
||||
- TELEGRAM_MAIN_PUBLIC=${MAIN_PUBLIC}
|
||||
- TELEGRAM_GROUP_FOR_POSTS=${GROUP_FOR_POSTS}
|
||||
- TELEGRAM_GROUP_FOR_MESSAGE=${GROUP_FOR_MESSAGE}
|
||||
- TELEGRAM_GROUP_FOR_LOGS=${GROUP_FOR_LOGS}
|
||||
- TELEGRAM_IMPORTANT_LOGS=${IMPORTANT_LOGS}
|
||||
- TELEGRAM_ARCHIVE=${ARCHIVE}
|
||||
- TELEGRAM_TEST_GROUP=${TEST_GROUP}
|
||||
# Bot settings
|
||||
- SETTINGS_LOGS=${LOGS:-false}
|
||||
- SETTINGS_TEST=${TEST:-false}
|
||||
# Database
|
||||
- DATABASE_PATH=${DATABASE_PATH:-/app/database/tg-bot-database.db}
|
||||
volumes:
|
||||
- ./database:/app/database
|
||||
- ./logs:/app/logs
|
||||
- ./settings.ini:/app/settings.ini
|
||||
- ./database:/app/database:rw
|
||||
- ./logs:/app/logs:rw
|
||||
- ./.env:/app/.env:ro
|
||||
networks:
|
||||
- monitoring
|
||||
- bot-internal
|
||||
depends_on:
|
||||
- prometheus
|
||||
- grafana
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
start_period: 40s
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: 512M
|
||||
cpus: '0.5'
|
||||
reservations:
|
||||
memory: 256M
|
||||
cpus: '0.25'
|
||||
|
||||
prometheus:
|
||||
image: prom/prometheus:latest
|
||||
container_name: prometheus
|
||||
ports:
|
||||
- "9090:9090"
|
||||
expose:
|
||||
- "9090"
|
||||
volumes:
|
||||
- ./prometheus.yml:/etc/prometheus/prometheus.yml
|
||||
- ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
|
||||
- prometheus_data:/prometheus
|
||||
command:
|
||||
- '--config.file=/etc/prometheus/prometheus.yml'
|
||||
@@ -36,31 +74,57 @@ services:
|
||||
- '--web.enable-lifecycle'
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- monitoring
|
||||
- bot-internal
|
||||
healthcheck:
|
||||
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:9090/-/healthy"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: 256M
|
||||
cpus: '0.25'
|
||||
|
||||
grafana:
|
||||
image: grafana/grafana:latest
|
||||
container_name: grafana
|
||||
ports:
|
||||
- "3000:3000"
|
||||
- "3000:3000" # Grafana доступна извне
|
||||
environment:
|
||||
- GF_SECURITY_ADMIN_USER=admin
|
||||
- GF_SECURITY_ADMIN_PASSWORD=admin
|
||||
- GF_SECURITY_ADMIN_USER=${GRAFANA_ADMIN_USER:-admin}
|
||||
- GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_ADMIN_PASSWORD:-admin}
|
||||
- GF_USERS_ALLOW_SIGN_UP=false
|
||||
- GF_SERVER_ROOT_URL=http://localhost:3000
|
||||
volumes:
|
||||
- grafana_data:/var/lib/grafana
|
||||
- ./grafana/dashboards:/etc/grafana/provisioning/dashboards
|
||||
- ./grafana/datasources:/etc/grafana/provisioning/datasources
|
||||
- ./grafana/dashboards:/etc/grafana/provisioning/dashboards:ro
|
||||
- ./grafana/datasources:/etc/grafana/provisioning/datasources:ro
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- monitoring
|
||||
- bot-internal
|
||||
depends_on:
|
||||
- prometheus
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "curl -f http://localhost:3000/api/health || exit 1"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: 256M
|
||||
cpus: '0.25'
|
||||
|
||||
volumes:
|
||||
prometheus_data:
|
||||
driver: local
|
||||
grafana_data:
|
||||
driver: local
|
||||
|
||||
networks:
|
||||
monitoring:
|
||||
bot-internal:
|
||||
driver: bridge
|
||||
ipam:
|
||||
config:
|
||||
- subnet: 172.20.0.0/16
|
||||
|
||||
Reference in New Issue
Block a user