VirtualLabo / deploy.sh
rinogeek's picture
Initial commit: Virtual Labo Chimique - Docker deployment
538d81e
#!/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}"