diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..0f4c475 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,38 @@ +# Git +.git/ +.gitignore + +# IDE +.vscode/ +.idea/ +.DS_Store + +# Frontend (not needed for backend image) +admin-panel/node_modules/ + +# Python cache +__pycache__/ +*.py[cod] +*.so +.venv/ +venv/ + +# Docs +docs/ +*.md +!backend/requirements.txt + +# Testing +.pytest_cache/ +.coverage +htmlcov/ + +# Logs and temp +*.log +tmp/ +temp/ + +# Reports (use volume) +reports/ + +# NOTE: categories/ is NOT excluded — it's bundled into the backend image diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7b36846..a6a0767 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -118,7 +118,8 @@ jobs: - name: Build Backend Docker image uses: docker/build-push-action@v5 with: - context: ./backend + context: . + file: backend/Dockerfile push: false tags: trendyol-backend:test cache-from: type=gha @@ -164,7 +165,8 @@ jobs: backend: build: - context: ./backend + context: . + dockerfile: backend/Dockerfile environment: PYTHONUNBUFFERED: 1 DATABASE_URL: postgresql://postgres:testpassword@postgres:5432/trendyol_db diff --git a/backend/Dockerfile b/backend/Dockerfile index 7af08c5..6c30316 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -15,17 +15,20 @@ RUN apt-get update && apt-get install -y \ && rm -rf /var/lib/apt/lists/* # Copy requirements first (Docker layer caching) -COPY requirements.txt . +# Build context is repo root, so path is backend/ +COPY backend/requirements.txt . # Install Python dependencies RUN pip install --no-cache-dir --upgrade pip && \ pip install --no-cache-dir -r requirements.txt -# Copy application code -COPY . . +# Copy application code from backend/ +COPY backend/ . + +# Copy categories data (bundled into image for Coolify deployment) +COPY categories/ /data/initial-categories/ # Create data directories with proper permissions -# These will be mounted as volumes in production RUN mkdir -p /data/categories /data/reports && \ chmod -R 755 /data @@ -41,10 +44,6 @@ USER appuser EXPOSE 8001 # Health check configuration -# - interval: Check every 30 seconds -# - timeout: Wait 10 seconds for response -# - start-period: Give 60 seconds for initialization (PostgreSQL + migrations) -# - retries: Retry 5 times before marking unhealthy HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=5 \ CMD curl -f http://localhost:8001/health || exit 1 @@ -54,5 +53,5 @@ ENV PYTHONUNBUFFERED=1 \ CATEGORIES_DIR=/data/categories \ REPORTS_DIR=/data/reports -# Start with migration script (runs alembic migrations then starts uvicorn) +# Start with migration script CMD ["./startup.sh"] diff --git a/backend/startup.sh b/backend/startup.sh index 6905f96..56f67e0 100644 --- a/backend/startup.sh +++ b/backend/startup.sh @@ -30,6 +30,17 @@ if [ $RETRY_COUNT -eq $MAX_RETRIES ]; then 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 diff --git a/docker-compose.yml b/docker-compose.yml index fb4220b..b8a0d30 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -30,8 +30,8 @@ services: # ============================================ backend: build: - context: ./backend - dockerfile: Dockerfile + context: . + dockerfile: backend/Dockerfile restart: unless-stopped ports: @@ -52,8 +52,7 @@ services: FRONTEND_URL: http://trendyol.194.187.253.230.sslip.io volumes: - # Persistent data volumes - - ./categories:/data/categories + # Persistent data volumes (reports persist across deploys) - ./reports:/data/reports depends_on: