FROM python:3.11-slim

# Install system dependencies
RUN apt-get update && apt-get install -y \
    libspatialindex-dev \
    libgeos-dev \
    libproj-dev \
    wget \
    && rm -rf /var/lib/apt/lists/*

# Set working directory
WORKDIR /app

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

# Copy only necessary Python scripts and web files
COPY *.py ./
COPY web/ ./web/

# Create /data directory (will be mounted as volume)
RUN mkdir -p /data

# Expose port
EXPOSE 5000

# Set environment variables
ENV FLASK_APP=web/server.py
ENV PYTHONUNBUFFERED=1

# Run the Flask server
CMD ["python", "web/server.py"]
