fix: resolve Permission denied for /data/reports in Coolify deployment

- Run container as root initially to fix volume mount permissions
- Use gosu to drop to appuser before starting uvicorn
- chown /data directories at startup (Coolify mounts volumes as root)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
furkanyigit34
2026-03-08 00:44:56 +03:00
parent 344474e763
commit 87d7ea88aa
2 changed files with 7 additions and 2 deletions

View File

@@ -12,6 +12,7 @@ WORKDIR /app
RUN apt-get update && apt-get install -y \ RUN apt-get update && apt-get install -y \
libpq-dev \ libpq-dev \
curl \ curl \
gosu \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
# Copy requirements first (Docker layer caching) # Copy requirements first (Docker layer caching)
@@ -38,7 +39,6 @@ RUN chmod +x startup.sh
# Create non-root user for security # Create non-root user for security
RUN useradd -m -u 1001 appuser && \ RUN useradd -m -u 1001 appuser && \
chown -R appuser:appuser /app /data chown -R appuser:appuser /app /data
USER appuser
# Expose backend port # Expose backend port
EXPOSE 8001 EXPOSE 8001

View File

@@ -6,6 +6,11 @@ set -e
echo "🚀 Starting Trendyol Product Dashboard Backend..." echo "🚀 Starting Trendyol Product Dashboard Backend..."
# Fix permissions on volume-mounted directories (Coolify mounts as root)
echo "🔧 Fixing data directory permissions..."
chown -R appuser:appuser /data 2>/dev/null || true
chmod -R 755 /data 2>/dev/null || true
# Database URL from environment # Database URL from environment
DB_URL="${DATABASE_URL:-postgresql://postgres:trendyol123@postgres:5432/trendyol_db}" DB_URL="${DATABASE_URL:-postgresql://postgres:trendyol123@postgres:5432/trendyol_db}"
echo "📦 Database: PostgreSQL" echo "📦 Database: PostgreSQL"
@@ -48,4 +53,4 @@ echo "✅ Migrations completed!"
# Start the FastAPI application # Start the FastAPI application
echo "🌐 Starting FastAPI server on port 8001..." echo "🌐 Starting FastAPI server on port 8001..."
exec uvicorn main:app --host 0.0.0.0 --port 8001 --log-level info exec gosu appuser uvicorn main:app --host 0.0.0.0 --port 8001 --log-level info