Files
DJ-Management-Tool/deploy.sh
T
spliceboti ec2ab0e9f4 Enable containerization for simplified deployment and scaling of the app
Adds Dockerfile, docker-compose files, and deployment scripts for containerizing the React/Express app.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 3a22ac80-cd1d-4441-9e36-f24fc2f4c3de
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/3478f7c3-db8c-4fca-9165-3adbdf1b5829/e8da43e7-d99c-4328-9fdc-485bdeecffc1.jpg
2025-07-10 00:35:23 +00:00

164 lines
4.5 KiB
Bash
Executable File

#!/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