180 lines
4.8 KiB
Bash
Executable File
180 lines
4.8 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# ================================================================
|
|
# E-Voting System - Docker Compose Quick Start Script
|
|
# ================================================================
|
|
|
|
set -e
|
|
|
|
# Colors for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Functions
|
|
print_header() {
|
|
echo -e "${BLUE}================================${NC}"
|
|
echo -e "${BLUE}$1${NC}"
|
|
echo -e "${BLUE}================================${NC}"
|
|
}
|
|
|
|
print_success() {
|
|
echo -e "${GREEN}✓ $1${NC}"
|
|
}
|
|
|
|
print_error() {
|
|
echo -e "${RED}✗ $1${NC}"
|
|
}
|
|
|
|
print_warning() {
|
|
echo -e "${YELLOW}! $1${NC}"
|
|
}
|
|
|
|
print_info() {
|
|
echo -e "${BLUE}→ $1${NC}"
|
|
}
|
|
|
|
# Check prerequisites
|
|
check_prerequisites() {
|
|
print_header "Checking Prerequisites"
|
|
|
|
if ! command -v docker &> /dev/null; then
|
|
print_error "Docker is not installed"
|
|
exit 1
|
|
fi
|
|
print_success "Docker found: $(docker --version)"
|
|
|
|
if ! command -v docker-compose &> /dev/null; then
|
|
print_error "Docker Compose is not installed"
|
|
exit 1
|
|
fi
|
|
print_success "Docker Compose found: $(docker-compose --version)"
|
|
}
|
|
|
|
# Create environment file if it doesn't exist
|
|
setup_env_file() {
|
|
print_header "Setting Up Environment"
|
|
|
|
if [ ! -f .env ]; then
|
|
if [ -f .env.example ]; then
|
|
cp .env.example .env
|
|
print_success "Created .env from template"
|
|
else
|
|
print_error ".env.example not found"
|
|
exit 1
|
|
fi
|
|
else
|
|
print_warning ".env already exists (skipping)"
|
|
fi
|
|
}
|
|
|
|
# Build services
|
|
build_services() {
|
|
print_header "Building Services"
|
|
print_info "Building Docker images..."
|
|
docker-compose build --no-cache
|
|
print_success "Services built successfully"
|
|
}
|
|
|
|
# Start services
|
|
start_services() {
|
|
print_header "Starting Services"
|
|
print_info "Starting containers..."
|
|
docker-compose up -d
|
|
print_success "Services started"
|
|
|
|
print_info "Waiting for services to be ready..."
|
|
sleep 10
|
|
}
|
|
|
|
# Check service health
|
|
check_health() {
|
|
print_header "Checking Service Health"
|
|
|
|
# Check Docker Compose status
|
|
docker-compose ps
|
|
|
|
print_info "Verifying services..."
|
|
|
|
# Check database
|
|
if docker-compose exec -T mariadb mariadb-admin ping -h localhost --silent 2>/dev/null; then
|
|
print_success "Database is healthy"
|
|
else
|
|
print_warning "Database may still be starting (this is normal)"
|
|
fi
|
|
|
|
# Check backend
|
|
if docker-compose exec -T backend curl -f http://localhost:8000/health 2>/dev/null; then
|
|
print_success "Backend API is responding"
|
|
else
|
|
print_warning "Backend may still be starting (this is normal)"
|
|
fi
|
|
|
|
# Check frontend
|
|
if docker-compose exec -T frontend wget -q http://localhost:3000 -O /dev/null 2>/dev/null; then
|
|
print_success "Frontend is responding"
|
|
else
|
|
print_warning "Frontend may still be starting (this is normal)"
|
|
fi
|
|
}
|
|
|
|
# Display access information
|
|
print_access_info() {
|
|
print_header "Access Information"
|
|
|
|
echo ""
|
|
echo -e "${GREEN}Your e-voting system is ready!${NC}"
|
|
echo ""
|
|
echo "Access the application:"
|
|
echo -e " ${BLUE}Frontend${NC}: http://localhost:3000"
|
|
echo -e " ${BLUE}Backend API${NC}: http://localhost:8000"
|
|
echo -e " ${BLUE}API Docs${NC}: http://localhost:8000/docs"
|
|
echo -e " ${BLUE}Database UI${NC}: http://localhost:8081"
|
|
echo ""
|
|
echo "Database credentials:"
|
|
echo -e " ${BLUE}Host${NC}: mariadb (from docker)"
|
|
echo -e " ${BLUE}User${NC}: evoting_user"
|
|
echo -e " ${BLUE}Password${NC}: evoting_pass123 (change in .env)"
|
|
echo -e " ${BLUE}Database${NC}: evoting_db"
|
|
echo ""
|
|
echo "Useful commands:"
|
|
echo -e " ${YELLOW}docker-compose logs -f${NC} - View all logs"
|
|
echo -e " ${YELLOW}docker-compose logs -f backend${NC} - View backend logs"
|
|
echo -e " ${YELLOW}docker-compose logs -f frontend${NC} - View frontend logs"
|
|
echo -e " ${YELLOW}docker-compose ps${NC} - View service status"
|
|
echo -e " ${YELLOW}docker-compose stop${NC} - Stop services"
|
|
echo -e " ${YELLOW}docker-compose down${NC} - Stop and remove services"
|
|
echo ""
|
|
}
|
|
|
|
# Main flow
|
|
main() {
|
|
print_header "E-Voting System - Docker Setup"
|
|
echo ""
|
|
echo "This script will:"
|
|
echo " 1. Check Docker prerequisites"
|
|
echo " 2. Set up environment configuration"
|
|
echo " 3. Build Docker images"
|
|
echo " 4. Start all services"
|
|
echo " 5. Verify service health"
|
|
echo ""
|
|
read -p "Continue? (y/n) " -n 1 -r
|
|
echo
|
|
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
|
print_warning "Setup cancelled"
|
|
exit 0
|
|
fi
|
|
|
|
check_prerequisites
|
|
setup_env_file
|
|
build_services
|
|
start_services
|
|
check_health
|
|
print_access_info
|
|
}
|
|
|
|
# Run main
|
|
main
|