Spaces:
Sleeping
Sleeping
| # 🚀 Déploiement automatique sur Hugging Face Spaces | |
| # Script pour déployer le jeu RTS sur HF Spaces avec Docker | |
| set -e # Exit on error | |
| # Couleurs | |
| RED='\033[0;31m' | |
| GREEN='\033[0;32m' | |
| YELLOW='\033[1;33m' | |
| BLUE='\033[0;34m' | |
| NC='\033[0m' # No Color | |
| # Variables (à modifier selon vos besoins) | |
| HF_USERNAME="" | |
| SPACE_NAME="rts-commander" | |
| SPACE_URL="" | |
| echo -e "${BLUE}╔════════════════════════════════════════════════════════════╗${NC}" | |
| echo -e "${BLUE}║ 🎮 RTS Commander - Déploiement HF Spaces (Docker) ║${NC}" | |
| echo -e "${BLUE}╚════════════════════════════════════════════════════════════╝${NC}" | |
| echo "" | |
| # Fonction pour afficher les erreurs | |
| error() { | |
| echo -e "${RED}❌ ERREUR: $1${NC}" | |
| exit 1 | |
| } | |
| # Fonction pour afficher les succès | |
| success() { | |
| echo -e "${GREEN}✅ $1${NC}" | |
| } | |
| # Fonction pour afficher les warnings | |
| warning() { | |
| echo -e "${YELLOW}⚠️ $1${NC}" | |
| } | |
| # Fonction pour afficher les infos | |
| info() { | |
| echo -e "${BLUE}ℹ️ $1${NC}" | |
| } | |
| # Vérification du répertoire | |
| if [ ! -f "Dockerfile" ]; then | |
| error "Dockerfile non trouvé. Êtes-vous dans le répertoire web/ ?" | |
| fi | |
| if [ ! -f "app.py" ]; then | |
| error "app.py non trouvé. Vérifiez que vous êtes dans le bon répertoire." | |
| fi | |
| success "Répertoire web/ détecté" | |
| # Demander les informations HF | |
| echo "" | |
| info "Configuration Hugging Face Spaces" | |
| echo "" | |
| if [ -z "$HF_USERNAME" ]; then | |
| read -p "Entrez votre username Hugging Face: " HF_USERNAME | |
| fi | |
| if [ -z "$SPACE_NAME" ]; then | |
| read -p "Entrez le nom du Space (défaut: rts-commander): " input_space | |
| SPACE_NAME=${input_space:-rts-commander} | |
| fi | |
| SPACE_URL="https://huggingface.co/spaces/$HF_USERNAME/$SPACE_NAME" | |
| echo "" | |
| info "Configuration:" | |
| echo " - Username: $HF_USERNAME" | |
| echo " - Space: $SPACE_NAME" | |
| echo " - URL: $SPACE_URL" | |
| echo "" | |
| # Vérification des fichiers essentiels | |
| echo "" | |
| info "Vérification des fichiers essentiels..." | |
| check_file() { | |
| if [ -f "$1" ]; then | |
| success "$1" | |
| else | |
| error "$1 manquant !" | |
| fi | |
| } | |
| check_file "Dockerfile" | |
| check_file "README.md" | |
| check_file "requirements.txt" | |
| check_file "app.py" | |
| check_file "localization.py" | |
| if [ -d "static" ]; then | |
| success "static/" | |
| else | |
| error "Répertoire static/ manquant !" | |
| fi | |
| if [ -d "backend" ]; then | |
| success "backend/" | |
| else | |
| error "Répertoire backend/ manquant !" | |
| fi | |
| # Vérifier le metadata YAML dans README.md | |
| echo "" | |
| info "Vérification du metadata YAML dans README.md..." | |
| if grep -q "sdk: docker" README.md; then | |
| success "Metadata 'sdk: docker' trouvé" | |
| else | |
| warning "Metadata 'sdk: docker' non trouvé dans README.md" | |
| echo "" | |
| echo "Le README.md doit commencer par:" | |
| echo "---" | |
| echo "title: RTS Commander" | |
| echo "emoji: 🎮" | |
| echo "sdk: docker" | |
| echo "---" | |
| echo "" | |
| read -p "Voulez-vous continuer quand même ? (y/N) " -n 1 -r | |
| echo | |
| if [[ ! $REPLY =~ ^[Yy]$ ]]; then | |
| exit 1 | |
| fi | |
| fi | |
| # Vérifier le port 7860 dans Dockerfile | |
| echo "" | |
| info "Vérification du port 7860 dans Dockerfile..." | |
| if grep -q "7860" Dockerfile; then | |
| success "Port 7860 configuré" | |
| else | |
| error "Le Dockerfile doit exposer le port 7860 (requis par HF Spaces)" | |
| fi | |
| # Test de build Docker local (optionnel) | |
| echo "" | |
| read -p "Voulez-vous tester le build Docker localement ? (y/N) " -n 1 -r | |
| echo | |
| if [[ $REPLY =~ ^[Yy]$ ]]; then | |
| info "Build Docker en cours..." | |
| if docker build -t rts-test . ; then | |
| success "Build Docker réussi !" | |
| # Demander si on veut tester | |
| read -p "Voulez-vous tester localement ? (y/N) " -n 1 -r | |
| echo | |
| if [[ $REPLY =~ ^[Yy]$ ]]; then | |
| info "Lancement du container (Ctrl+C pour arrêter)..." | |
| info "Ouvrez http://localhost:7860 dans votre navigateur" | |
| docker run -p 7860:7860 rts-test | |
| fi | |
| else | |
| error "Build Docker échoué ! Vérifiez les erreurs ci-dessus." | |
| fi | |
| fi | |
| # Git setup | |
| echo "" | |
| info "Configuration Git pour HF Spaces..." | |
| # Vérifier si git est initialisé | |
| if [ ! -d ".git" ]; then | |
| info "Initialisation du dépôt Git..." | |
| git init | |
| success "Git initialisé" | |
| fi | |
| # Vérifier si le remote existe déjà | |
| if git remote get-url space 2>/dev/null; then | |
| warning "Remote 'space' existe déjà" | |
| read -p "Voulez-vous le supprimer et le recréer ? (y/N) " -n 1 -r | |
| echo | |
| if [[ $REPLY =~ ^[Yy]$ ]]; then | |
| git remote remove space | |
| git remote add space "https://huggingface.co/spaces/$HF_USERNAME/$SPACE_NAME" | |
| success "Remote 'space' reconfiguré" | |
| fi | |
| else | |
| git remote add space "https://huggingface.co/spaces/$HF_USERNAME/$SPACE_NAME" | |
| success "Remote 'space' ajouté" | |
| fi | |
| # Préparation du commit | |
| echo "" | |
| info "Préparation du commit..." | |
| # Vérifier s'il y a des changements | |
| if git diff-index --quiet HEAD -- 2>/dev/null; then | |
| info "Aucun changement à committer" | |
| else | |
| # Ajouter tous les fichiers | |
| git add . | |
| # Commit | |
| read -p "Message de commit (défaut: 'Deploy RTS Commander v2.0'): " commit_msg | |
| commit_msg=${commit_msg:-"Deploy RTS Commander v2.0"} | |
| git commit -m "$commit_msg" | |
| success "Commit créé" | |
| fi | |
| # Push vers HF Spaces | |
| echo "" | |
| warning "Prêt à déployer sur Hugging Face Spaces !" | |
| echo "" | |
| info "Le Space sera accessible à: $SPACE_URL" | |
| echo "" | |
| read -p "Voulez-vous continuer avec le push ? (y/N) " -n 1 -r | |
| echo | |
| if [[ $REPLY =~ ^[Yy]$ ]]; then | |
| info "Push vers HF Spaces en cours..." | |
| echo "" | |
| # Vérifier si la branche main existe | |
| if git rev-parse --verify main >/dev/null 2>&1; then | |
| BRANCH="main" | |
| else | |
| BRANCH="master" | |
| fi | |
| # Push (peut demander authentification) | |
| if git push space $BRANCH --force; then | |
| echo "" | |
| success "Déploiement réussi ! 🎉" | |
| echo "" | |
| info "Le build Docker va commencer automatiquement sur HF Spaces" | |
| info "Cela peut prendre 2-5 minutes" | |
| echo "" | |
| info "Suivez le build ici: $SPACE_URL" | |
| echo "" | |
| info "Une fois le build terminé, votre jeu sera accessible à:" | |
| echo " 🎮 https://$HF_USERNAME-$SPACE_NAME.hf.space" | |
| echo "" | |
| success "Déploiement terminé avec succès !" | |
| else | |
| echo "" | |
| error "Push échoué. Vérifiez:" | |
| echo " 1. Que le Space existe sur HF" | |
| echo " 2. Que vous avez les permissions d'écriture" | |
| echo " 3. Que vous êtes authentifié (huggingface-cli login)" | |
| echo "" | |
| info "Pour vous authentifier:" | |
| echo " pip install huggingface_hub" | |
| echo " huggingface-cli login" | |
| fi | |
| else | |
| warning "Déploiement annulé" | |
| info "Pour déployer manuellement:" | |
| echo " git push space main" | |
| fi | |
| echo "" | |
| info "Pour voir les logs du Space:" | |
| echo " huggingface-cli space logs $HF_USERNAME/$SPACE_NAME --follow" | |
| echo "" | |
| echo -e "${GREEN}╔════════════════════════════════════════════════════════════╗${NC}" | |
| echo -e "${GREEN}║ Script terminé ! 🚀 ║${NC}" | |
| echo -e "${GREEN}╚════════════════════════════════════════════════════════════╝${NC}" | |