FROM python:3.11-slim # Install system dependencies RUN apt-get update && apt-get install -y \ build-essential \ libpq-dev \ curl \ netcat-traditional \ && rm -rf /var/lib/apt/lists/* # Create a non-root user RUN useradd -m -u 1000 celery # Set working directory WORKDIR /app # Copy requirements first to leverage Docker cache COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Copy application code COPY . . # Debug: List files and check tasks.py RUN ls -la /app && \ echo "Checking tasks.py:" && \ if [ -f /app/tasks.py ]; then \ echo "tasks.py exists" && \ cat /app/tasks.py; \ else \ echo "tasks.py does not exist"; \ fi # Create necessary directories and set permissions RUN mkdir -p /app/uploads /app/static/uploads && \ chown -R celery:celery /app # Create startup script RUN echo '#!/bin/sh\n\ echo "Waiting for database..."\n\ while ! nc -z db 5432; do\n\ sleep 0.1\n\ done\n\ echo "Database is ready!"\n\ \n\ echo "Waiting for Redis..."\n\ while ! nc -z redis 6379; do\n\ sleep 0.1\n\ done\n\ echo "Redis is ready!"\n\ \n\ echo "Running database migrations..."\n\ flask db upgrade\n\ \n\ echo "Creating admin user..."\n\ flask create-admin\n\ \n\ echo "Starting application..."\n\ exec "$@"' > /app/entrypoint.sh && \ chmod +x /app/entrypoint.sh # Set environment variables ENV PYTHONPATH=/app ENV FLASK_APP=app.py ENV FLASK_ENV=production # Make sure tasks.py is executable and has correct permissions RUN chmod 644 /app/tasks.py && \ chown celery:celery /app/tasks.py # Switch to non-root user USER celery # Set entrypoint ENTRYPOINT ["/bin/sh", "/app/entrypoint.sh"]