Upload 2 files
Browse files- app.py +35 -0
- deploy-to-hf.sh +301 -0
app.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Hugging Face Spaces compatibility file for WordPress
|
| 4 |
+
This file is required by HF Spaces but the actual application runs in Docker
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import subprocess
|
| 8 |
+
import time
|
| 9 |
+
import sys
|
| 10 |
+
import os
|
| 11 |
+
|
| 12 |
+
def main():
|
| 13 |
+
print("π Starting WordPress on Hugging Face Spaces...")
|
| 14 |
+
print("This is a Docker-based WordPress deployment.")
|
| 15 |
+
print("The actual WordPress application is running in the Docker container.")
|
| 16 |
+
print("Access your WordPress site at the provided URL above.")
|
| 17 |
+
print("")
|
| 18 |
+
print("π Default Login Information:")
|
| 19 |
+
print("Username: demo")
|
| 20 |
+
print("Password: demo123")
|
| 21 |
+
print("")
|
| 22 |
+
print("β οΈ Important: Change the default password after first login!")
|
| 23 |
+
print("")
|
| 24 |
+
|
| 25 |
+
# Keep the process alive
|
| 26 |
+
try:
|
| 27 |
+
while True:
|
| 28 |
+
time.sleep(60)
|
| 29 |
+
print(f"WordPress container is running... {time.strftime('%Y-%m-%d %H:%M:%S')}")
|
| 30 |
+
except KeyboardInterrupt:
|
| 31 |
+
print("Shutting down...")
|
| 32 |
+
sys.exit(0)
|
| 33 |
+
|
| 34 |
+
if __name__ == "__main__":
|
| 35 |
+
main()
|
deploy-to-hf.sh
ADDED
|
@@ -0,0 +1,301 @@
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
# WordPress to Hugging Face Spaces Deployment Script
|
| 4 |
+
# This script helps you deploy WordPress to Hugging Face Spaces
|
| 5 |
+
|
| 6 |
+
set -e
|
| 7 |
+
|
| 8 |
+
echo "π WordPress to Hugging Face Spaces Deployment Helper"
|
| 9 |
+
echo "================================================="
|
| 10 |
+
|
| 11 |
+
# Colors for output
|
| 12 |
+
RED='\033[0;31m'
|
| 13 |
+
GREEN='\033[0;32m'
|
| 14 |
+
YELLOW='\033[1;33m'
|
| 15 |
+
BLUE='\033[0;34m'
|
| 16 |
+
NC='\033[0m' # No Color
|
| 17 |
+
|
| 18 |
+
# Function to print colored output
|
| 19 |
+
print_status() {
|
| 20 |
+
echo -e "${GREEN}[INFO]${NC} $1"
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
print_warning() {
|
| 24 |
+
echo -e "${YELLOW}[WARNING]${NC} $1"
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
print_error() {
|
| 28 |
+
echo -e "${RED}[ERROR]${NC} $1"
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
print_step() {
|
| 32 |
+
echo -e "${BLUE}[STEP]${NC} $1"
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
# Check if required files exist
|
| 36 |
+
check_files() {
|
| 37 |
+
print_step "Checking required files..."
|
| 38 |
+
|
| 39 |
+
local files=("Dockerfile.hf-spaces" "wp-config-hf.php" "db.php" "start-hf.sh" "README-HF-SPACES.md")
|
| 40 |
+
local missing_files=()
|
| 41 |
+
|
| 42 |
+
for file in "${files[@]}"; do
|
| 43 |
+
if [ ! -f "$file" ]; then
|
| 44 |
+
missing_files+=("$file")
|
| 45 |
+
fi
|
| 46 |
+
done
|
| 47 |
+
|
| 48 |
+
if [ ${#missing_files[@]} -ne 0 ]; then
|
| 49 |
+
print_error "Missing required files:"
|
| 50 |
+
for file in "${missing_files[@]}"; do
|
| 51 |
+
echo " - $file"
|
| 52 |
+
done
|
| 53 |
+
exit 1
|
| 54 |
+
fi
|
| 55 |
+
|
| 56 |
+
print_status "All required files found β"
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
# Get user input
|
| 60 |
+
get_user_input() {
|
| 61 |
+
print_step "Getting deployment information..."
|
| 62 |
+
|
| 63 |
+
echo -n "Enter your Hugging Face username: "
|
| 64 |
+
read -r HF_USERNAME
|
| 65 |
+
|
| 66 |
+
echo -n "Enter your Space name: "
|
| 67 |
+
read -r SPACE_NAME
|
| 68 |
+
|
| 69 |
+
echo -n "Do you want to create a new directory for deployment? (y/n): "
|
| 70 |
+
read -r CREATE_DIR
|
| 71 |
+
|
| 72 |
+
if [ "$CREATE_DIR" = "y" ] || [ "$CREATE_DIR" = "Y" ]; then
|
| 73 |
+
DEPLOY_DIR="./hf-spaces-deployment"
|
| 74 |
+
echo "Deployment directory: $DEPLOY_DIR"
|
| 75 |
+
else
|
| 76 |
+
echo -n "Enter deployment directory path: "
|
| 77 |
+
read -r DEPLOY_DIR
|
| 78 |
+
fi
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
# Create deployment directory
|
| 82 |
+
setup_deployment_dir() {
|
| 83 |
+
print_step "Setting up deployment directory..."
|
| 84 |
+
|
| 85 |
+
if [ -d "$DEPLOY_DIR" ]; then
|
| 86 |
+
print_warning "Directory $DEPLOY_DIR already exists"
|
| 87 |
+
echo -n "Do you want to overwrite it? (y/n): "
|
| 88 |
+
read -r OVERWRITE
|
| 89 |
+
|
| 90 |
+
if [ "$OVERWRITE" = "y" ] || [ "$OVERWRITE" = "Y" ]; then
|
| 91 |
+
rm -rf "$DEPLOY_DIR"
|
| 92 |
+
else
|
| 93 |
+
print_error "Deployment cancelled"
|
| 94 |
+
exit 1
|
| 95 |
+
fi
|
| 96 |
+
fi
|
| 97 |
+
|
| 98 |
+
mkdir -p "$DEPLOY_DIR"
|
| 99 |
+
print_status "Created deployment directory: $DEPLOY_DIR"
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
# Copy files
|
| 103 |
+
copy_files() {
|
| 104 |
+
print_step "Copying files to deployment directory..."
|
| 105 |
+
|
| 106 |
+
# Copy and rename Dockerfile
|
| 107 |
+
cp "Dockerfile.hf-spaces" "$DEPLOY_DIR/Dockerfile"
|
| 108 |
+
print_status "Copied Dockerfile.hf-spaces β Dockerfile"
|
| 109 |
+
|
| 110 |
+
# Copy other files
|
| 111 |
+
cp "wp-config-hf.php" "$DEPLOY_DIR/"
|
| 112 |
+
cp "db.php" "$DEPLOY_DIR/"
|
| 113 |
+
cp "start-hf.sh" "$DEPLOY_DIR/"
|
| 114 |
+
cp "app.py" "$DEPLOY_DIR/"
|
| 115 |
+
cp "README-HF-SPACES.md" "$DEPLOY_DIR/README.md"
|
| 116 |
+
|
| 117 |
+
print_status "Copied all required files"
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
# Create .gitignore
|
| 121 |
+
create_gitignore() {
|
| 122 |
+
print_step "Creating .gitignore..."
|
| 123 |
+
|
| 124 |
+
cat > "$DEPLOY_DIR/.gitignore" << 'EOF'
|
| 125 |
+
# WordPress
|
| 126 |
+
wp-config.php
|
| 127 |
+
wp-content/uploads/
|
| 128 |
+
wp-content/cache/
|
| 129 |
+
wp-content/database/
|
| 130 |
+
*.log
|
| 131 |
+
|
| 132 |
+
# System files
|
| 133 |
+
.DS_Store
|
| 134 |
+
Thumbs.db
|
| 135 |
+
|
| 136 |
+
# IDE
|
| 137 |
+
.vscode/
|
| 138 |
+
.idea/
|
| 139 |
+
*.swp
|
| 140 |
+
*.swo
|
| 141 |
+
|
| 142 |
+
# Temporary files
|
| 143 |
+
*.tmp
|
| 144 |
+
*.temp
|
| 145 |
+
EOF
|
| 146 |
+
|
| 147 |
+
print_status "Created .gitignore"
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
# Create app.py for HF Spaces compatibility
|
| 151 |
+
create_app_py() {
|
| 152 |
+
print_step "Creating app.py for HF Spaces..."
|
| 153 |
+
|
| 154 |
+
cat > "$DEPLOY_DIR/app.py" << 'EOF'
|
| 155 |
+
#!/usr/bin/env python3
|
| 156 |
+
"""
|
| 157 |
+
Hugging Face Spaces compatibility file for WordPress
|
| 158 |
+
This file is required by HF Spaces but the actual application runs in Docker
|
| 159 |
+
"""
|
| 160 |
+
|
| 161 |
+
import subprocess
|
| 162 |
+
import time
|
| 163 |
+
import sys
|
| 164 |
+
|
| 165 |
+
def main():
|
| 166 |
+
print("π Starting WordPress on Hugging Face Spaces...")
|
| 167 |
+
print("This is a Docker-based WordPress deployment.")
|
| 168 |
+
print("The actual WordPress application is running in the Docker container.")
|
| 169 |
+
|
| 170 |
+
# Keep the process alive
|
| 171 |
+
try:
|
| 172 |
+
while True:
|
| 173 |
+
time.sleep(60)
|
| 174 |
+
print("WordPress container is running...")
|
| 175 |
+
except KeyboardInterrupt:
|
| 176 |
+
print("Shutting down...")
|
| 177 |
+
sys.exit(0)
|
| 178 |
+
|
| 179 |
+
if __name__ == "__main__":
|
| 180 |
+
main()
|
| 181 |
+
EOF
|
| 182 |
+
|
| 183 |
+
print_status "Created app.py"
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
# Initialize git repository
|
| 187 |
+
init_git() {
|
| 188 |
+
print_step "Initializing git repository..."
|
| 189 |
+
|
| 190 |
+
cd "$DEPLOY_DIR"
|
| 191 |
+
|
| 192 |
+
if [ ! -d ".git" ]; then
|
| 193 |
+
git init
|
| 194 |
+
print_status "Initialized git repository"
|
| 195 |
+
else
|
| 196 |
+
print_warning "Git repository already exists"
|
| 197 |
+
fi
|
| 198 |
+
|
| 199 |
+
# Add HF Spaces remote if provided
|
| 200 |
+
if [ -n "$HF_USERNAME" ] && [ -n "$SPACE_NAME" ]; then
|
| 201 |
+
HF_REMOTE="https://huggingface.co/spaces/$HF_USERNAME/$SPACE_NAME"
|
| 202 |
+
|
| 203 |
+
if git remote get-url origin >/dev/null 2>&1; then
|
| 204 |
+
print_warning "Remote 'origin' already exists"
|
| 205 |
+
else
|
| 206 |
+
git remote add origin "$HF_REMOTE"
|
| 207 |
+
print_status "Added remote: $HF_REMOTE"
|
| 208 |
+
fi
|
| 209 |
+
fi
|
| 210 |
+
|
| 211 |
+
cd - > /dev/null
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
# Create deployment instructions
|
| 215 |
+
create_instructions() {
|
| 216 |
+
print_step "Creating deployment instructions..."
|
| 217 |
+
|
| 218 |
+
cat > "$DEPLOY_DIR/DEPLOYMENT.md" << EOF
|
| 219 |
+
# Deployment Instructions
|
| 220 |
+
|
| 221 |
+
## Quick Deploy to Hugging Face Spaces
|
| 222 |
+
|
| 223 |
+
### Method 1: Git Push (Recommended)
|
| 224 |
+
|
| 225 |
+
1. Commit and push the files:
|
| 226 |
+
\`\`\`bash
|
| 227 |
+
cd $DEPLOY_DIR
|
| 228 |
+
git add .
|
| 229 |
+
git commit -m "Initial WordPress deployment"
|
| 230 |
+
git push origin main
|
| 231 |
+
\`\`\`
|
| 232 |
+
|
| 233 |
+
### Method 2: Web Upload
|
| 234 |
+
|
| 235 |
+
1. Go to your HF Space: https://huggingface.co/spaces/$HF_USERNAME/$SPACE_NAME
|
| 236 |
+
2. Upload these files:
|
| 237 |
+
- Dockerfile
|
| 238 |
+
- wp-config-hf.php
|
| 239 |
+
- db.php
|
| 240 |
+
- start-hf.sh
|
| 241 |
+
- README.md
|
| 242 |
+
- app.py
|
| 243 |
+
|
| 244 |
+
## After Deployment
|
| 245 |
+
|
| 246 |
+
1. Wait for the build to complete (5-10 minutes)
|
| 247 |
+
2. Access your WordPress site:
|
| 248 |
+
- **Main site**: https://$HF_USERNAME-$SPACE_NAME.hf.space/
|
| 249 |
+
- **Admin panel**: https://$HF_USERNAME-$SPACE_NAME.hf.space/wp-admin/
|
| 250 |
+
- **Health check**: https://$HF_USERNAME-$SPACE_NAME.hf.space/health.html
|
| 251 |
+
|
| 252 |
+
## Default Login
|
| 253 |
+
|
| 254 |
+
- **Username**: demo
|
| 255 |
+
- **Password**: demo123
|
| 256 |
+
|
| 257 |
+
β οΈ **Important**: Change the default password after first login!
|
| 258 |
+
|
| 259 |
+
## Troubleshooting
|
| 260 |
+
|
| 261 |
+
If the deployment fails:
|
| 262 |
+
1. Check the build logs in your HF Space
|
| 263 |
+
2. Ensure all files are uploaded correctly
|
| 264 |
+
3. Verify the Dockerfile syntax
|
| 265 |
+
4. Check that port 7860 is properly configured
|
| 266 |
+
|
| 267 |
+
EOF
|
| 268 |
+
|
| 269 |
+
print_status "Created deployment instructions"
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
+
# Main deployment process
|
| 273 |
+
main() {
|
| 274 |
+
echo
|
| 275 |
+
print_step "Starting deployment process..."
|
| 276 |
+
|
| 277 |
+
check_files
|
| 278 |
+
get_user_input
|
| 279 |
+
setup_deployment_dir
|
| 280 |
+
copy_files
|
| 281 |
+
create_gitignore
|
| 282 |
+
create_app_py
|
| 283 |
+
init_git
|
| 284 |
+
create_instructions
|
| 285 |
+
|
| 286 |
+
echo
|
| 287 |
+
print_status "π Deployment preparation completed!"
|
| 288 |
+
echo
|
| 289 |
+
echo -e "${GREEN}Next steps:${NC}"
|
| 290 |
+
echo "1. cd $DEPLOY_DIR"
|
| 291 |
+
echo "2. Review the files"
|
| 292 |
+
echo "3. Follow instructions in DEPLOYMENT.md"
|
| 293 |
+
echo
|
| 294 |
+
echo -e "${BLUE}Your WordPress will be available at:${NC}"
|
| 295 |
+
echo "https://$HF_USERNAME-$SPACE_NAME.hf.space/"
|
| 296 |
+
echo
|
| 297 |
+
print_warning "Remember to change the default password (demo/demo123) after deployment!"
|
| 298 |
+
}
|
| 299 |
+
|
| 300 |
+
# Run main function
|
| 301 |
+
main "$@"
|