#!/bin/bash # WordPress to Hugging Face Spaces Deployment Script # This script helps you deploy WordPress to Hugging Face Spaces set -e echo "🚀 WordPress to Hugging Face Spaces Deployment Helper" echo "=================================================" # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color # Function to print colored output print_status() { echo -e "${GREEN}[INFO]${NC} $1" } print_warning() { echo -e "${YELLOW}[WARNING]${NC} $1" } print_error() { echo -e "${RED}[ERROR]${NC} $1" } print_step() { echo -e "${BLUE}[STEP]${NC} $1" } # Check if required files exist check_files() { print_step "Checking required files..." local files=("Dockerfile.hf-spaces" "wp-config-hf.php" "db.php" "start-hf.sh" "README-HF-SPACES.md") local missing_files=() for file in "${files[@]}"; do if [ ! -f "$file" ]; then missing_files+=("$file") fi done if [ ${#missing_files[@]} -ne 0 ]; then print_error "Missing required files:" for file in "${missing_files[@]}"; do echo " - $file" done exit 1 fi print_status "All required files found ✓" } # Get user input get_user_input() { print_step "Getting deployment information..." echo -n "Enter your Hugging Face username: " read -r HF_USERNAME echo -n "Enter your Space name: " read -r SPACE_NAME echo -n "Do you want to create a new directory for deployment? (y/n): " read -r CREATE_DIR if [ "$CREATE_DIR" = "y" ] || [ "$CREATE_DIR" = "Y" ]; then DEPLOY_DIR="./hf-spaces-deployment" echo "Deployment directory: $DEPLOY_DIR" else echo -n "Enter deployment directory path: " read -r DEPLOY_DIR fi } # Create deployment directory setup_deployment_dir() { print_step "Setting up deployment directory..." if [ -d "$DEPLOY_DIR" ]; then print_warning "Directory $DEPLOY_DIR already exists" echo -n "Do you want to overwrite it? (y/n): " read -r OVERWRITE if [ "$OVERWRITE" = "y" ] || [ "$OVERWRITE" = "Y" ]; then rm -rf "$DEPLOY_DIR" else print_error "Deployment cancelled" exit 1 fi fi mkdir -p "$DEPLOY_DIR" print_status "Created deployment directory: $DEPLOY_DIR" } # Copy files copy_files() { print_step "Copying files to deployment directory..." # Copy and rename Dockerfile cp "Dockerfile.hf-spaces" "$DEPLOY_DIR/Dockerfile" print_status "Copied Dockerfile.hf-spaces → Dockerfile" # Copy other files cp "wp-config-hf.php" "$DEPLOY_DIR/" cp "db.php" "$DEPLOY_DIR/" cp "start-hf.sh" "$DEPLOY_DIR/" cp "app.py" "$DEPLOY_DIR/" cp "README-HF-SPACES.md" "$DEPLOY_DIR/README.md" print_status "Copied all required files" } # Create .gitignore create_gitignore() { print_step "Creating .gitignore..." cat > "$DEPLOY_DIR/.gitignore" << 'EOF' # WordPress wp-config.php wp-content/uploads/ wp-content/cache/ wp-content/database/ *.log # System files .DS_Store Thumbs.db # IDE .vscode/ .idea/ *.swp *.swo # Temporary files *.tmp *.temp EOF print_status "Created .gitignore" } # Create app.py for HF Spaces compatibility create_app_py() { print_step "Creating app.py for HF Spaces..." cat > "$DEPLOY_DIR/app.py" << 'EOF' #!/usr/bin/env python3 """ Hugging Face Spaces compatibility file for WordPress This file is required by HF Spaces but the actual application runs in Docker """ import subprocess import time import sys def main(): print("🚀 Starting WordPress on Hugging Face Spaces...") print("This is a Docker-based WordPress deployment.") print("The actual WordPress application is running in the Docker container.") # Keep the process alive try: while True: time.sleep(60) print("WordPress container is running...") except KeyboardInterrupt: print("Shutting down...") sys.exit(0) if __name__ == "__main__": main() EOF print_status "Created app.py" } # Initialize git repository init_git() { print_step "Initializing git repository..." cd "$DEPLOY_DIR" if [ ! -d ".git" ]; then git init print_status "Initialized git repository" else print_warning "Git repository already exists" fi # Add HF Spaces remote if provided if [ -n "$HF_USERNAME" ] && [ -n "$SPACE_NAME" ]; then HF_REMOTE="https://huggingface.co/spaces/$HF_USERNAME/$SPACE_NAME" if git remote get-url origin >/dev/null 2>&1; then print_warning "Remote 'origin' already exists" else git remote add origin "$HF_REMOTE" print_status "Added remote: $HF_REMOTE" fi fi cd - > /dev/null } # Create deployment instructions create_instructions() { print_step "Creating deployment instructions..." cat > "$DEPLOY_DIR/DEPLOYMENT.md" << EOF # Deployment Instructions ## Quick Deploy to Hugging Face Spaces ### Method 1: Git Push (Recommended) 1. Commit and push the files: \`\`\`bash cd $DEPLOY_DIR git add . git commit -m "Initial WordPress deployment" git push origin main \`\`\` ### Method 2: Web Upload 1. Go to your HF Space: https://huggingface.co/spaces/$HF_USERNAME/$SPACE_NAME 2. Upload these files: - Dockerfile - wp-config-hf.php - db.php - start-hf.sh - README.md - app.py ## After Deployment 1. Wait for the build to complete (5-10 minutes) 2. Access your WordPress site: - **Main site**: https://$HF_USERNAME-$SPACE_NAME.hf.space/ - **Admin panel**: https://$HF_USERNAME-$SPACE_NAME.hf.space/wp-admin/ - **Health check**: https://$HF_USERNAME-$SPACE_NAME.hf.space/health.html ## Default Login - **Username**: demo - **Password**: demo123 ⚠️ **Important**: Change the default password after first login! ## Troubleshooting If the deployment fails: 1. Check the build logs in your HF Space 2. Ensure all files are uploaded correctly 3. Verify the Dockerfile syntax 4. Check that port 7860 is properly configured EOF print_status "Created deployment instructions" } # Main deployment process main() { echo print_step "Starting deployment process..." check_files get_user_input setup_deployment_dir copy_files create_gitignore create_app_py init_git create_instructions echo print_status "🎉 Deployment preparation completed!" echo echo -e "${GREEN}Next steps:${NC}" echo "1. cd $DEPLOY_DIR" echo "2. Review the files" echo "3. Follow instructions in DEPLOYMENT.md" echo echo -e "${BLUE}Your WordPress will be available at:${NC}" echo "https://$HF_USERNAME-$SPACE_NAME.hf.space/" echo print_warning "Remember to change the default password (demo/demo123) after deployment!" } # Run main function main "$@"