CIA/e-voting-system/build.sh
E-Voting Developer 8baabf528c feat: Implement Historique and Upcoming Votes pages with styling and data fetching
- Added HistoriquePage component to display user's voting history with detailed statistics and vote cards.
- Created UpcomingVotesPage component to show upcoming elections with a similar layout.
- Developed CSS styles for both pages to enhance visual appeal and responsiveness.
- Integrated API calls to fetch user's votes and upcoming elections.
- Added a rebuild script for Docker environment setup and data restoration.
- Created a Python script to populate the database with sample data for testing.
2025-11-06 05:12:03 +01:00

230 lines
6.1 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# ============================================================================
# E-Voting System - Build Script
# Build le frontend React AVANT Docker pour éviter les problèmes de cache
# ============================================================================
set -e
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
log_info() { echo -e "${BLUE} $1${NC}"; }
log_success() { echo -e "${GREEN}$1${NC}"; }
log_warning() { echo -e "${YELLOW}⚠️ $1${NC}"; }
log_error() { echo -e "${RED}$1${NC}"; }
log_title() { echo -e "${BLUE}\n=== $1 ===${NC}\n"; }
error_exit() {
log_error "$1"
exit 1
}
# Vérifier qu'on est dans le bon répertoire
if [ ! -d "frontend" ] || [ ! -d "backend" ]; then
error_exit "Ce script doit être exécuté depuis la racine du projet (e-voting-system/)"
fi
PROJECT_ROOT="$(pwd)"
BUILD_DIR="$PROJECT_ROOT/build"
log_title "🏗️ Build E-Voting System - Frontend & Backend"
# 1. Arrêter les conteneurs actuels
log_info "Arrêt des conteneurs existants..."
docker-compose down 2>/dev/null || true
# 2. Nettoyer les builds précédents
log_info "Nettoyage des builds précédents..."
rm -rf "$BUILD_DIR"
mkdir -p "$BUILD_DIR"/{frontend,backend}
rm -rf frontend/build frontend/node_modules/.cache
# 3. Installer les dépendances frontend
log_info "Installation des dépendances frontend..."
cd "$PROJECT_ROOT/frontend"
npm install --legacy-peer-deps || error_exit "Échec de l'installation frontend"
# 4. Build React (production)
log_info "Build du frontend React..."
npm run build || error_exit "Échec du build React"
# 5. Copier le build dans le répertoire de déploiement
log_success "Frontend buildé"
cp -r "$PROJECT_ROOT/frontend/build"/* "$BUILD_DIR/frontend/" || error_exit "Erreur lors de la copie du build"
log_success "Build frontend copié vers $BUILD_DIR/frontend/"
# 6. Créer le Dockerfile pour le frontend (serveur avec serve)
log_info "Création du Dockerfile frontend..."
cat > "$BUILD_DIR/frontend/Dockerfile" << 'EOF'
FROM node:20-alpine
WORKDIR /app
# Installer serve pour servir les fichiers statiques
RUN npm install -g serve
# Copier les fichiers buildés
COPY . .
# Port
EXPOSE 3000
# Servir les fichiers sur le port 3000
CMD ["serve", "-s", ".", "-l", "3000"]
EOF
log_success "Dockerfile frontend créé"
# 6.5 Configuration Nginx pour React SPA - SUPPRIMÉE (on utilise serve à la place)
# 8. Copier les fichiers backend
log_info "Préparation du backend..."
cp -r "$PROJECT_ROOT/backend"/* "$BUILD_DIR/backend/" || true
# Copier pyproject.toml et poetry.lock
cp "$PROJECT_ROOT/pyproject.toml" "$BUILD_DIR/backend/" 2>/dev/null || true
cp "$PROJECT_ROOT/poetry.lock" "$BUILD_DIR/backend/" 2>/dev/null || true
# Créer le Dockerfile pour le backend adapté à cette structure
log_info "Création du Dockerfile backend..."
cat > "$BUILD_DIR/backend/Dockerfile" << 'EOF'
FROM python:3.12-slim
WORKDIR /app
# Installer les dépendances système
RUN apt-get update && apt-get install -y \
gcc \
&& rm -rf /var/lib/apt/lists/*
# Installer Poetry
RUN pip install --no-cache-dir poetry
# Copier les fichiers de configuration
COPY pyproject.toml poetry.lock* ./
# Installer les dépendances Python
RUN poetry config virtualenvs.create false && \
poetry install --no-interaction --no-ansi --no-root
# Copier le code backend
COPY . ./backend/
# Exposer le port
EXPOSE 8000
# Démarrer l'application
CMD ["uvicorn", "backend.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]
EOF
log_success "Backend copié vers $BUILD_DIR/backend/"
# 9. Mettre à jour docker-compose.yml pour utiliser les Dockerfiles depuis build/
log_info "Création du docker-compose.yml..."
cat > "$BUILD_DIR/docker-compose.yml" << 'EOF'
version: '3.8'
services:
mariadb:
image: mariadb:latest
container_name: evoting_db
environment:
MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD:-rootpass123}
MYSQL_DATABASE: ${DB_NAME:-evoting_db}
MYSQL_USER: ${DB_USER:-evoting_user}
MYSQL_PASSWORD: ${DB_PASSWORD:-evoting_pass123}
ports:
- "${DB_PORT:-3306}:3306"
volumes:
- evoting_data:/var/lib/mysql
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
networks:
- evoting_network
healthcheck:
test: ["CMD", "mariadb-admin", "ping", "-h", "localhost", "--silent"]
timeout: 20s
retries: 10
start_period: 30s
backend:
build:
context: ./backend
dockerfile: Dockerfile
container_name: evoting_backend
environment:
DB_HOST: mariadb
DB_PORT: 3306
DB_NAME: ${DB_NAME:-evoting_db}
DB_USER: ${DB_USER:-evoting_user}
DB_PASSWORD: ${DB_PASSWORD:-evoting_pass123}
SECRET_KEY: ${SECRET_KEY:-your-secret-key-change-in-production}
DEBUG: ${DEBUG:-false}
ports:
- "${BACKEND_PORT:-8000}:8000"
depends_on:
mariadb:
condition: service_healthy
networks:
- evoting_network
frontend:
build:
context: ./frontend
container_name: evoting_frontend
ports:
- "${FRONTEND_PORT:-3000}:3000"
depends_on:
- backend
networks:
- evoting_network
volumes:
evoting_data:
networks:
evoting_network:
driver: bridge
EOF
log_success "docker-compose.yml créé"
cd "$BUILD_DIR"
# Copier init.sql pour MariaDB
cp "$PROJECT_ROOT/docker/init.sql" "$BUILD_DIR/init.sql" 2>/dev/null || true
# 10. Docker build
log_info "Build des images Docker..."
docker-compose build || error_exit "Erreur lors du build Docker"
log_success "Images Docker buildées"
# 11. Démarrer les conteneurs
log_info "Démarrage des conteneurs..."
docker-compose up -d || error_exit "Erreur lors du démarrage"
log_success "Conteneurs démarrés"
# 12. Afficher le résumé
echo ""
log_title "✅ BUILD COMPLET!"
echo ""
log_info "📊 État des services:"
docker-compose ps
echo ""
log_info "🌐 URLs d'accès:"
echo " Frontend: http://localhost:3000"
echo " Backend: http://localhost:8000"
echo ""
log_info "📝 Pour voir les logs:"
echo " docker-compose logs -f frontend"
echo " docker-compose logs -f backend"
echo ""
log_warning "📁 Les fichiers sont dans: $BUILD_DIR/"
echo " Pour redémarrer: cd $BUILD_DIR && docker-compose up -d"