# Use pre-built PyTorch image to avoid massive downloads and build overhead
FROM pytorch/pytorch:2.1.1-cuda12.1-cudnn8-runtime

# Set non-interactive for apt
ENV DEBIAN_FRONTEND=noninteractive

# Install system dependencies and clean up in one layer
RUN apt-get update && apt-get install -y --no-install-recommends \
    libexpat1 \
    libgomp1 \
    libgdal-dev \
    libgeos-dev \
    libproj-dev \
    libspatialindex-dev \
    libcurl4-openssl-dev \
    libssl-dev \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app

# Set Python path to include /app
ENV PYTHONPATH=/app

# Copy requirements and install dependencies
# We use --no-cache-dir to keep the image small
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy the application code
COPY . .

# Start the RQ worker
CMD ["python", "worker.py", "--worker"]
