FROM python:3.9-slim

# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
    gcc \
    python3-dev \
    libgl1-mesa-glx \
    libglib2.0-0 \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app

# Install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy and build the C extension
COPY simplified_filter_short_groups.c /app/
COPY direct_setup.py /app/
RUN python direct_setup.py install

# Copy the wrapper module
COPY filter_short_groups_wrapper.py /app/

# Copy application code
COPY well-api.py .

# Create directory and copy data files
RUN mkdir -p /home/app/well_web_storage
COPY well_web_files/* /home/app/well_web_storage/
RUN mkdir -p /app/fonts
COPY fonts/* /app/fonts/

# Environment variables for gunicorn
ENV GUNICORN_CMD_ARGS="--log-level info --timeout 60"
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1

# Expose the port for the API
EXPOSE 8080

# Run with gunicorn
CMD ["gunicorn", "--bind", "0.0.0.0:8080", "well-api:app"]
