dynamo-backend / setup /setup_backend.sh
afnhf's picture
Deploy CORS middleware order fix to Hugging Face Space
983f705
Raw History Blame Contribute Delete
2.88 kB
#!/bin/bash
# ─────────────────────────────────────────────
# setup_backend.sh β€” Backend Environment Setup
# Usage: bash setup/setup_backend.sh
# ─────────────────────────────────────────────
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
cd "$PROJECT_ROOT"
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " Dynamo Backend Setup"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
# ── Step 1: Python environment check ─────────
echo "[1/5] Checking Python installation..."
if command -v python3 &>/dev/null; then
PYTHON_CMD="python3"
elif command -v python &>/dev/null; then
PYTHON_CMD="python"
else
echo "❌ Error: Python is not installed or not in PATH."
exit 1
fi
echo " βœ“ Using $($PYTHON_CMD --version)"
echo ""
# ── Step 2: Environment file setup ───────────
echo "[2/5] Setting up environment configuration (.env)..."
if [ ! -f ".env" ]; then
if [ -f ".env.example" ]; then
cp .env.example .env
echo " βœ“ Created .env from .env.example"
else
echo " ⚠️ No .env.example found. Skipping .env creation."
fi
else
echo " βœ“ .env already exists"
fi
echo ""
# ── Step 3: Create required directories ──────
echo "[3/5] Creating runtime directories..."
mkdir -p bin/model
mkdir -p bin/data
echo " βœ“ Created bin/model and bin/data"
echo ""
# ── Step 4: Install Python dependencies ──────
echo "[4/5] Installing Python dependencies..."
if $PYTHON_CMD -m pip install -r requirements.txt -q 2>/dev/null; then
echo " βœ“ Dependencies installed successfully"
else
echo " Installing dependencies with --break-system-packages..."
$PYTHON_CMD -m pip install -r requirements.txt --break-system-packages -q
echo " βœ“ Dependencies installed successfully"
fi
echo ""
# ── Step 5: Django Database Migrations ────────
echo "[5/5] Running database migrations..."
$PYTHON_CMD manage.py migrate
echo " βœ“ Database migrated successfully"
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " Backend Setup Complete! πŸŽ‰"
echo ""
echo " To start the Django server:"
echo " python manage.py runserver"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""