mirror of
https://github.com/nethunterzist/trendyol-analiz
synced 2026-07-02 17:57:03 +00:00
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:
38
.dockerignore
Normal file
38
.dockerignore
Normal 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
|
||||||
6
.github/workflows/ci.yml
vendored
6
.github/workflows/ci.yml
vendored
@@ -118,7 +118,8 @@ jobs:
|
|||||||
- name: Build Backend Docker image
|
- name: Build Backend Docker image
|
||||||
uses: docker/build-push-action@v5
|
uses: docker/build-push-action@v5
|
||||||
with:
|
with:
|
||||||
context: ./backend
|
context: .
|
||||||
|
file: backend/Dockerfile
|
||||||
push: false
|
push: false
|
||||||
tags: trendyol-backend:test
|
tags: trendyol-backend:test
|
||||||
cache-from: type=gha
|
cache-from: type=gha
|
||||||
@@ -164,7 +165,8 @@ jobs:
|
|||||||
|
|
||||||
backend:
|
backend:
|
||||||
build:
|
build:
|
||||||
context: ./backend
|
context: .
|
||||||
|
dockerfile: backend/Dockerfile
|
||||||
environment:
|
environment:
|
||||||
PYTHONUNBUFFERED: 1
|
PYTHONUNBUFFERED: 1
|
||||||
DATABASE_URL: postgresql://postgres:testpassword@postgres:5432/trendyol_db
|
DATABASE_URL: postgresql://postgres:testpassword@postgres:5432/trendyol_db
|
||||||
|
|||||||
@@ -15,17 +15,20 @@ RUN apt-get update && apt-get install -y \
|
|||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Copy requirements first (Docker layer caching)
|
# 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
|
# Install Python dependencies
|
||||||
RUN pip install --no-cache-dir --upgrade pip && \
|
RUN pip install --no-cache-dir --upgrade pip && \
|
||||||
pip install --no-cache-dir -r requirements.txt
|
pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
# Copy application code
|
# Copy application code from backend/
|
||||||
COPY . .
|
COPY backend/ .
|
||||||
|
|
||||||
|
# Copy categories data (bundled into image for Coolify deployment)
|
||||||
|
COPY categories/ /data/initial-categories/
|
||||||
|
|
||||||
# Create data directories with proper permissions
|
# Create data directories with proper permissions
|
||||||
# These will be mounted as volumes in production
|
|
||||||
RUN mkdir -p /data/categories /data/reports && \
|
RUN mkdir -p /data/categories /data/reports && \
|
||||||
chmod -R 755 /data
|
chmod -R 755 /data
|
||||||
|
|
||||||
@@ -41,10 +44,6 @@ USER appuser
|
|||||||
EXPOSE 8001
|
EXPOSE 8001
|
||||||
|
|
||||||
# Health check configuration
|
# 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 \
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=5 \
|
||||||
CMD curl -f http://localhost:8001/health || exit 1
|
CMD curl -f http://localhost:8001/health || exit 1
|
||||||
|
|
||||||
@@ -54,5 +53,5 @@ ENV PYTHONUNBUFFERED=1 \
|
|||||||
CATEGORIES_DIR=/data/categories \
|
CATEGORIES_DIR=/data/categories \
|
||||||
REPORTS_DIR=/data/reports
|
REPORTS_DIR=/data/reports
|
||||||
|
|
||||||
# Start with migration script (runs alembic migrations then starts uvicorn)
|
# Start with migration script
|
||||||
CMD ["./startup.sh"]
|
CMD ["./startup.sh"]
|
||||||
|
|||||||
@@ -30,6 +30,17 @@ if [ $RETRY_COUNT -eq $MAX_RETRIES ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
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
|
# Run migrations
|
||||||
echo "🔄 Running database migrations..."
|
echo "🔄 Running database migrations..."
|
||||||
alembic upgrade head
|
alembic upgrade head
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ services:
|
|||||||
# ============================================
|
# ============================================
|
||||||
backend:
|
backend:
|
||||||
build:
|
build:
|
||||||
context: ./backend
|
context: .
|
||||||
dockerfile: Dockerfile
|
dockerfile: backend/Dockerfile
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|
||||||
ports:
|
ports:
|
||||||
@@ -52,8 +52,7 @@ services:
|
|||||||
FRONTEND_URL: http://trendyol.194.187.253.230.sslip.io
|
FRONTEND_URL: http://trendyol.194.187.253.230.sslip.io
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
# Persistent data volumes
|
# Persistent data volumes (reports persist across deploys)
|
||||||
- ./categories:/data/categories
|
|
||||||
- ./reports:/data/reports
|
- ./reports:/data/reports
|
||||||
|
|
||||||
depends_on:
|
depends_on:
|
||||||
|
|||||||
Reference in New Issue
Block a user