diff --git a/Dockerfile b/Dockerfile index cc5893a..76785dd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,52 @@ FROM python:3.11-slim-buster -RUN apt-get update && apt-get install -y build-essential +# Install system dependencies +RUN apt-get update && \ + apt-get install -y build-essential && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* +# Set working directory WORKDIR /rideaware_landing +# Copy requirements first for better caching COPY requirements.txt . +# Install Python dependencies RUN pip install --no-cache-dir -r requirements.txt +# Copy application code COPY . . +# Set environment variables ENV FLASK_APP=server.py +ENV PYTHONUNBUFFERED=1 +ENV PYTHONPATH=/rideaware_landing +# Create non-root user for security +RUN useradd --create-home --shell /bin/bash app && \ + chown -R app:app /rideaware_landing +USER app + +# Expose port EXPOSE 5000 -CMD ["gunicorn", "--bind", "0.0.0.0:5000", "--workers", "4", "server:app"] \ No newline at end of file +# Health check +HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ + CMD curl -f http://localhost:5000/health || exit 1 + +# Run with optimized Gunicorn settings +CMD ["gunicorn", \ + "--bind", "0.0.0.0:5000", \ + "--workers", "4", \ + "--worker-class", "sync", \ + "--worker-connections", "1000", \ + "--max-requests", "1000", \ + "--max-requests-jitter", "50", \ + "--preload", \ + "--timeout", "30", \ + "--keep-alive", "2", \ + "--access-logfile", "-", \ + "--error-logfile", "-", \ + "--log-level", "info", \ + "server:app"] \ No newline at end of file