mirror of
https://github.com/nethunterzist/trendyol-analiz
synced 2026-07-01 01:17:04 +00:00
Coolify remaps volume mounts to its own managed directories, so ./categories was mapped to an empty dir instead of the repo data. Changes: - Backend build context changed to repo root (.) so categories/ is accessible - Dockerfile copies categories into /data/initial-categories/ - startup.sh seeds /data/categories from bundled data if empty - Removed categories volume mount (reports still persisted via volume) - Added root .dockerignore (categories NOT excluded) - Updated CI workflow to match new build context Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
52 lines
1.7 KiB
Bash
52 lines
1.7 KiB
Bash
#!/bin/bash
|
|
# Startup script for Trendyol Product Dashboard Backend
|
|
# Handles database migrations before starting the application
|
|
|
|
set -e
|
|
|
|
echo "🚀 Starting Trendyol Product Dashboard Backend..."
|
|
|
|
# Database URL from environment
|
|
DB_URL="${DATABASE_URL:-postgresql://postgres:trendyol123@postgres:5432/trendyol_db}"
|
|
echo "📦 Database: PostgreSQL"
|
|
|
|
# Wait for PostgreSQL to be ready (in case depends_on isn't enough)
|
|
echo "⏳ Waiting for PostgreSQL to be ready..."
|
|
MAX_RETRIES=30
|
|
RETRY_COUNT=0
|
|
|
|
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
|
|
if python -c "from sqlalchemy import create_engine; e = create_engine('$DB_URL'); e.connect()" 2>/dev/null; then
|
|
echo "✅ PostgreSQL is ready!"
|
|
break
|
|
fi
|
|
RETRY_COUNT=$((RETRY_COUNT + 1))
|
|
echo " Attempt $RETRY_COUNT/$MAX_RETRIES - PostgreSQL not ready, waiting..."
|
|
sleep 2
|
|
done
|
|
|
|
if [ $RETRY_COUNT -eq $MAX_RETRIES ]; then
|
|
echo "❌ Failed to connect to PostgreSQL after $MAX_RETRIES attempts"
|
|
exit 1
|
|
fi
|
|
|
|
# Seed categories data from bundled initial-categories if /data/categories is empty
|
|
if [ -d "/data/initial-categories" ] && [ "$(ls -A /data/initial-categories 2>/dev/null)" ]; then
|
|
if [ -z "$(ls -A /data/categories 2>/dev/null)" ]; then
|
|
echo "📂 Seeding categories from bundled data..."
|
|
cp -r /data/initial-categories/* /data/categories/
|
|
echo "✅ $(ls /data/categories | wc -l) category files copied!"
|
|
else
|
|
echo "📂 Categories directory already has data, skipping seed."
|
|
fi
|
|
fi
|
|
|
|
# Run migrations
|
|
echo "🔄 Running database migrations..."
|
|
alembic upgrade head
|
|
echo "✅ Migrations completed!"
|
|
|
|
# Start the FastAPI application
|
|
echo "🌐 Starting FastAPI server on port 8001..."
|
|
exec uvicorn main:app --host 0.0.0.0 --port 8001 --log-level info
|