#!/bin/bash # DJ Management System Deployment Script # This script helps deploy the application using Docker set -e # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color echo -e "${GREEN}๐ŸŽต DJ Management System Deployment Script${NC}" echo "=================================================" # Check if Docker is installed if ! command -v docker &> /dev/null; then echo -e "${RED}โŒ Docker is not installed. Please install Docker first.${NC}" exit 1 fi # Check if Docker Compose is installed if ! command -v docker-compose &> /dev/null; then echo -e "${RED}โŒ Docker Compose is not installed. Please install Docker Compose first.${NC}" exit 1 fi # Function to create .env file if it doesn't exist create_env_file() { if [ ! -f .env ]; then echo -e "${YELLOW}๐Ÿ“ Creating .env file from template...${NC}" cp .env.example .env echo -e "${YELLOW}โš ๏ธ Please edit .env file with your configuration before proceeding.${NC}" read -p "Press Enter to continue after editing .env file..." fi } # Function to generate a random session secret generate_session_secret() { if [ -f .env ]; then if grep -q "your-super-secret-session-key" .env; then echo -e "${YELLOW}๐Ÿ” Generating secure session secret...${NC}" SESSION_SECRET=$(openssl rand -base64 32) sed -i "s/your-super-secret-session-key-here-minimum-32-characters-long/$SESSION_SECRET/" .env fi fi } # Function to build and start the application deploy_application() { echo -e "${GREEN}๐Ÿš€ Building and starting the DJ Management System...${NC}" # Build the Docker image docker-compose build --no-cache # Start the services docker-compose up -d # Wait for services to be ready echo -e "${YELLOW}โณ Waiting for services to start...${NC}" sleep 10 # Check if services are running if docker-compose ps | grep -q "Up"; then echo -e "${GREEN}โœ… DJ Management System is running!${NC}" echo "" echo "๐ŸŒ Application URL: http://localhost:5000" echo "๐Ÿ“Š Database: PostgreSQL on port 5432" echo "" echo "๐Ÿ“‹ To view logs: docker-compose logs -f" echo "๐Ÿ›‘ To stop: docker-compose down" echo "๐Ÿ”„ To restart: docker-compose restart" else echo -e "${RED}โŒ Failed to start services. Check logs with: docker-compose logs${NC}" exit 1 fi } # Function to deploy production version deploy_production() { echo -e "${GREEN}๐Ÿญ Deploying production version...${NC}" # Use production docker-compose file docker-compose -f docker-compose.prod.yml build --no-cache docker-compose -f docker-compose.prod.yml up -d echo -e "${GREEN}โœ… Production deployment complete!${NC}" } # Function to show usage show_usage() { echo "Usage: $0 [OPTION]" echo "Options:" echo " dev Deploy development version (default)" echo " prod Deploy production version" echo " stop Stop all services" echo " restart Restart all services" echo " logs Show application logs" echo " clean Clean up Docker containers and images" echo " help Show this help message" } # Function to stop services stop_services() { echo -e "${YELLOW}๐Ÿ›‘ Stopping DJ Management System...${NC}" docker-compose down echo -e "${GREEN}โœ… Services stopped.${NC}" } # Function to restart services restart_services() { echo -e "${YELLOW}๐Ÿ”„ Restarting DJ Management System...${NC}" docker-compose restart echo -e "${GREEN}โœ… Services restarted.${NC}" } # Function to show logs show_logs() { echo -e "${GREEN}๐Ÿ“‹ Showing application logs...${NC}" docker-compose logs -f app } # Function to clean up Docker resources clean_up() { echo -e "${YELLOW}๐Ÿงน Cleaning up Docker resources...${NC}" docker-compose down --volumes --remove-orphans docker system prune -f echo -e "${GREEN}โœ… Cleanup complete.${NC}" } # Main script logic case "${1:-dev}" in dev) create_env_file generate_session_secret deploy_application ;; prod) create_env_file generate_session_secret deploy_production ;; stop) stop_services ;; restart) restart_services ;; logs) show_logs ;; clean) clean_up ;; help) show_usage ;; *) echo -e "${RED}โŒ Invalid option: $1${NC}" show_usage exit 1 ;; esac