File size: 5,020 Bytes
538d81e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/bin/bash

# Script de déploiement automatisé pour HuggingFace Spaces
# Usage: ./deploy.sh

set -e  # Exit on error

# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color

# Configuration
SPACE_URL="https://huggingface.co/spaces/rinogeek/VirtualLabo"
REPO_PATH="${1:-.}"
COMMIT_MSG="${2:-'Update: Automated deployment'}"

echo -e "${BLUE}╔════════════════════════════════════════════╗${NC}"
echo -e "${BLUE}║   Virtual Labo Chimique - Deploy Script   ║${NC}"
echo -e "${BLUE}╚════════════════════════════════════════════╝${NC}"
echo ""

# Check if git is installed
if ! command -v git &> /dev/null; then
    echo -e "${RED}✗ Git is not installed${NC}"
    exit 1
fi

# Navigate to repo path
if [ ! -d "$REPO_PATH" ]; then
    echo -e "${RED}✗ Directory not found: $REPO_PATH${NC}"
    exit 1
fi

cd "$REPO_PATH"
echo -e "${GREEN}✓ Working directory: $(pwd)${NC}"
echo ""

# Check if Dockerfile exists
if [ ! -f "Dockerfile" ]; then
    echo -e "${RED}✗ Dockerfile not found in $REPO_PATH${NC}"
    exit 1
fi
echo -e "${GREEN}✓ Dockerfile found${NC}"

# Check if server.js exists
if [ ! -f "server.js" ]; then
    echo -e "${RED}✗ server.js not found in $REPO_PATH${NC}"
    exit 1
fi
echo -e "${GREEN}✓ server.js found${NC}"

# Check if package.json exists
if [ ! -f "package.json" ]; then
    echo -e "${RED}✗ package.json not found in $REPO_PATH${NC}"
    exit 1
fi
echo -e "${GREEN}✓ package.json found${NC}"

echo ""
echo -e "${YELLOW}Testing Docker build locally...${NC}"

if command -v docker &> /dev/null; then
    echo "Building Docker image..."
    if docker build -t virtual-labo-test . > /dev/null 2>&1; then
        echo -e "${GREEN}✓ Docker build successful${NC}"
    else
        echo -e "${YELLOW}⚠ Docker build failed (continuing anyway)${NC}"
    fi
else
    echo -e "${YELLOW}⚠ Docker not installed (skipping Docker test)${NC}"
fi

echo ""
echo -e "${YELLOW}Preparing Git repository...${NC}"

# Check git status
if [ -z "$(git status --porcelain)" ]; then
    echo -e "${YELLOW}⚠ No changes detected${NC}"
    read -p "Continue anyway? (y/n) " -n 1 -r
    echo
    if [[ ! $REPLY =~ ^[Yy]$ ]]; then
        echo -e "${RED}✗ Deployment cancelled${NC}"
        exit 1
    fi
fi

# Check if we're in a git repo
if [ ! -d ".git" ]; then
    echo -e "${RED}✗ Not a git repository${NC}"
    echo "Initialize git repo first:"
    echo "  git init"
    echo "  git add ."
    echo "  git commit -m 'Initial commit'"
    exit 1
fi

echo ""
echo -e "${YELLOW}Current status:${NC}"
git status --short | head -10 || true

echo ""
echo -e "${YELLOW}Git log (last 3 commits):${NC}"
git log --oneline -3 || true

echo ""
echo -e "${BLUE}═══════════════════════════════════════════${NC}"
echo -e "${YELLOW}Deployment Summary:${NC}"
echo -e "  Space URL:  $SPACE_URL"
echo -e "  Repo Path:  $REPO_PATH"
echo -e "  Commit:     $COMMIT_MSG"
echo -e "${BLUE}═══════════════════════════════════════════${NC}"
echo ""

# Confirmation
read -p "Proceed with deployment? (y/n) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
    echo -e "${RED}✗ Deployment cancelled${NC}"
    exit 1
fi

echo ""
echo -e "${YELLOW}Staging changes...${NC}"
git add . || true
echo -e "${GREEN}✓ Changes staged${NC}"

echo ""
echo -e "${YELLOW}Creating commit...${NC}"
if git commit -m "$COMMIT_MSG" 2>/dev/null; then
    echo -e "${GREEN}✓ Commit created${NC}"
else
    echo -e "${YELLOW}⚠ No new changes to commit${NC}"
fi

echo ""
echo -e "${YELLOW}Pushing to origin...${NC}"
if git push origin main 2>/dev/null || git push origin master 2>/dev/null; then
    echo -e "${GREEN}✓ Changes pushed successfully${NC}"
else
    echo -e "${RED}✗ Failed to push changes${NC}"
    echo "Try manual push: git push origin main"
    exit 1
fi

echo ""
echo -e "${BLUE}═══════════════════════════════════════════${NC}"
echo -e "${GREEN}✓ Deployment initiated successfully!${NC}"
echo -e "${BLUE}═══════════════════════════════════════════${NC}"
echo ""
echo -e "Next steps:"
echo -e "  1. Visit: ${YELLOW}$SPACE_URL${NC}"
echo -e "  2. Check the build logs"
echo -e "  3. Your app will be live in a few minutes"
echo ""
echo -e "Return to HuggingFace to see:"
echo -e "  - Build logs: Space Settings → Build logs"
echo -e "  - Status: Check top-right corner"
echo -e "  - Application: Live at the Space URL"
echo ""

# Wait for user to check
read -p "Press Enter to finish..."
echo -e "${GREEN}✓ Done!${NC}"