FROM python:3.11-slim # Set environment variables ENV PYTHONUNBUFFERED=1 \ PYTHONDONTWRITEBYTECODE=1 \ ENV_MODE="LOCAL" \ PYTHONPATH=/app \ REDIS_HOST=localhost \ REDIS_PORT=6379 WORKDIR /app # Install system dependencies + Redis RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ curl \ git \ redis-server \ && rm -rf /var/lib/apt/lists/* # Configure Redis to run in foreground and allow remote connections RUN sed -i 's/bind 127.0.0.1/bind 0.0.0.0/g' /etc/redis/redis.conf && \ sed -i 's/protected-mode yes/protected-mode no/g' /etc/redis/redis.conf && \ sed -i 's/daemonize yes/daemonize no/g' /etc/redis/redis.conf # Create non-root user and set up directories RUN useradd -m -u 1000 appuser && \ mkdir -p /app/logs && \ chown -R appuser:appuser /app && \ chown -R appuser:appuser /var/lib/redis && \ chown -R appuser:appuser /var/log/redis && \ chown -R appuser:appuser /etc/redis # Clone the repository RUN git clone https://github.com/mfoud444/suna.git /tmp/suna && \ cp -r /tmp/suna/backend/. /app && \ rm -rf /tmp/suna # Install Python dependencies COPY --chown=appuser:appuser requirements.txt . RUN pip install --no-cache-dir -r requirements.txt gunicorn # Switch to non-root user USER appuser # Expose ports (8000 for app, 6379 for Redis) EXPOSE 7860 6379 # Calculate optimal worker count ENV WORKERS=33 ENV THREADS=2 ENV WORKER_CONNECTIONS=2000 # Combined startup command for both services CMD ["sh", "-c", \ "redis-server /etc/redis/redis.conf & \ gunicorn api:app \ --workers $WORKERS \ --worker-class uvicorn.workers.UvicornWorker \ --bind 0.0.0.0:7860 \ --timeout 600 \ --graceful-timeout 300 \ --keep-alive 250 \ --max-requests 2000 \ --max-requests-jitter 400 \ --forwarded-allow-ips '*' \ --worker-connections $WORKER_CONNECTIONS \ --worker-tmp-dir /dev/shm \ --preload \ --log-level info \ --access-logfile - \ --error-logfile - \ --capture-output \ --enable-stdio-inheritance \ --threads $THREADS"]