fix: bundle categories into Docker image for Coolify deployment

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>
This commit is contained in:
furkanyigit34
2026-03-07 23:32:34 +03:00
parent 99a132879f
commit f85fb75830
5 changed files with 64 additions and 15 deletions

38
.dockerignore Normal file
View File

@@ -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

View File

@@ -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

View File

@@ -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"]

View File

@@ -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

View File

@@ -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: