File size: 7,604 Bytes
12d64f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
#!/bin/bash

# 🚀 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}"