#!/bin/bash set -e # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color # Configuration PROJECT_NAME="telegram-helper-bot" DOCKER_COMPOSE_FILE="docker-compose.yml" ENV_FILE=".env" echo -e "${GREEN}๐Ÿš€ Starting deployment of $PROJECT_NAME${NC}" # Check if .env file exists if [ ! -f "$ENV_FILE" ]; then echo -e "${RED}โŒ Error: $ENV_FILE file not found!${NC}" echo -e "${YELLOW}Please copy env.example to .env and configure your settings${NC}" exit 1 fi # Load environment variables source "$ENV_FILE" # Validate required environment variables required_vars=("BOT_TOKEN" "MAIN_PUBLIC" "GROUP_FOR_POSTS" "GROUP_FOR_MESSAGE" "GROUP_FOR_LOGS") for var in "${required_vars[@]}"; do if [ -z "${!var}" ]; then echo -e "${RED}โŒ Error: Required environment variable $var is not set${NC}" exit 1 fi done echo -e "${GREEN}โœ… Environment variables validated${NC}" # Create necessary directories echo -e "${YELLOW}๐Ÿ“ Creating necessary directories...${NC}" mkdir -p database logs # Set proper permissions echo -e "${YELLOW}๐Ÿ” Setting proper permissions...${NC}" chmod 600 "$ENV_FILE" chmod 755 database logs # Stop existing containers echo -e "${YELLOW}๐Ÿ›‘ Stopping existing containers...${NC}" docker-compose -f "$DOCKER_COMPOSE_FILE" down --remove-orphans || true # Remove old images echo -e "${YELLOW}๐Ÿงน Cleaning up old images...${NC}" docker system prune -f # Build and start services echo -e "${YELLOW}๐Ÿ”จ Building and starting services...${NC}" docker-compose -f "$DOCKER_COMPOSE_FILE" up -d --build # Wait for services to be healthy echo -e "${YELLOW}โณ Waiting for services to be healthy...${NC}" sleep 30 # Check service health echo -e "${YELLOW}๐Ÿฅ Checking service health...${NC}" if docker-compose -f "$DOCKER_COMPOSE_FILE" ps | grep -q "unhealthy"; then echo -e "${RED}โŒ Some services are unhealthy!${NC}" docker-compose -f "$DOCKER_COMPOSE_FILE" logs exit 1 fi # Show service status echo -e "${GREEN}๐Ÿ“Š Service status:${NC}" docker-compose -f "$DOCKER_COMPOSE_FILE" ps echo -e "${GREEN}โœ… Deployment completed successfully!${NC}" echo -e "${GREEN}๐Ÿ“Š Monitoring URLs:${NC}" echo -e " Prometheus: http://localhost:9090" echo -e " Grafana: http://localhost:3000" echo -e " Bot Metrics: http://localhost:8000/metrics" echo -e " Bot Health: http://localhost:8000/health" echo -e "" echo -e "${YELLOW}๐Ÿ“ Useful commands:${NC}" echo -e " View logs: docker-compose logs -f" echo -e " Restart: docker-compose restart" echo -e " Stop: docker-compose down"