chore: Add Docker startup and shutdown scripts

Convenience scripts for Docker Compose management:

start.sh:
  • Checks Docker prerequisites
  • Creates .env from template if missing
  • Builds Docker images
  • Starts all services
  • Verifies service health
  • Displays access information

stop.sh:
  • Graceful service shutdown options
  • Option 1: Stop containers (preserve data)
  • Option 2: Stop and remove containers
  • Option 3: Complete cleanup (remove all data)

Usage:
  ./start.sh     - Start the entire system
  ./stop.sh      - Stop services interactively

Features:
  ✓ Color-coded output for clarity
  ✓ Error checking and helpful messages
  ✓ Prerequisites validation
  ✓ Automatic .env setup
  ✓ Health verification
  ✓ Quick access information

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Alexis Bruneteau 2025-11-07 02:10:18 +01:00
parent 368bb38057
commit 68cc8e7014
2 changed files with 249 additions and 0 deletions

179
e-voting-system/start.sh Executable file
View File

@ -0,0 +1,179 @@
#!/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:8080"
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

70
e-voting-system/stop.sh Executable file
View File

@ -0,0 +1,70 @@
#!/bin/bash
# ================================================================
# E-Voting System - Docker Compose Stop Script
# ================================================================
set -e
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
print_header() {
echo -e "${BLUE}================================${NC}"
echo -e "${BLUE}$1${NC}"
echo -e "${BLUE}================================${NC}"
}
print_success() {
echo -e "${GREEN}$1${NC}"
}
print_warning() {
echo -e "${YELLOW}! $1${NC}"
}
# Main
print_header "E-Voting System - Stopping Services"
echo ""
echo "Options:"
echo " 1. Stop services (containers kept)"
echo " 2. Stop and remove containers"
echo " 3. Stop and remove everything (including data)"
echo ""
read -p "Select option (1-3): " option
case $option in
1)
print_warning "Stopping containers..."
docker-compose stop
print_success "Services stopped (data preserved)"
echo ""
echo "To start again: docker-compose up -d"
;;
2)
print_warning "Stopping and removing containers..."
docker-compose down
print_success "Containers removed (data preserved)"
echo ""
echo "To start again: docker-compose up -d"
;;
3)
print_warning "This will DELETE all data!"
read -p "Are you sure? (yes/no): " confirm
if [ "$confirm" = "yes" ]; then
docker-compose down -v
print_success "Services stopped and all data deleted"
else
print_warning "Cancelled"
fi
;;
*)
print_warning "Invalid option"
exit 1
;;
esac