# Use an official Ubuntu as the base image
FROM nvidia/cuda:12.6.1-cudnn-runtime-ubuntu20.04

# Set environment variables to non-interactive
ENV DEBIAN_FRONTEND=noninteractive

# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
    wget \
    bzip2 \
    ca-certificates \
    curl \
    git \
    build-essential \
    libgl1-mesa-glx \
    libglib2.0-0 \
    && rm -rf /var/lib/apt/lists/*

# Install Miniconda
ENV CONDA_DIR=/opt/conda
RUN wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O /tmp/miniconda.sh && \
    bash /tmp/miniconda.sh -b -p $CONDA_DIR && \
    rm /tmp/miniconda.sh && \
    ln -s $CONDA_DIR/bin/conda /usr/local/bin/conda

ENV PATH=$CONDA_DIR/bin:$PATH

# Create the Conda environment
COPY environment.yml /tmp/environment.yml
RUN conda env create -f /tmp/environment.yml && conda clean -a -y

# Install GPU-compatible PyTorch
RUN conda install -n nowcasting pytorch torchvision torchaudio pytorch-cuda=12.4 -c pytorch -c nvidia && \
    conda clean -a -y

# Allow using the environment without activating it
SHELL ["conda", "run", "-n", "nowcasting", "/bin/bash", "-c"]

# Set the working directory
WORKDIR /app

# No COPY command for application code

# Set entrypoint to allow dynamic command execution
ENTRYPOINT ["conda", "run", "-n", "nowcasting"]