FROM debian:bookworm-slim

# Avoid prompts from apt
ENV DEBIAN_FRONTEND=noninteractive

# Install base packages for weather tools
RUN apt-get update && apt-get install -y \
    bash \
    curl \
    wget \
    git \
    python3 \
    python3-pip \
    build-essential \
    sudo \
    ca-certificates \
    && rm -rf /var/lib/apt/lists/*

# Create symbolic link for python
RUN ln -s /usr/bin/python3 /usr/bin/python

# Install weather data processing tools
RUN apt-get update && apt-get install -y \
    ftp \
    gfortran \
    libgfortran5 \
    && rm -rf /var/lib/apt/lists/*

# Install Python weather libraries
RUN pip3 install --break-system-packages \
    xarray \
    cfgrib \
    netcdf4 \
    metpy \
    siphon \
    numpy \
    pandas \
    scipy \
    matplotlib \
    seaborn \
    requests \
    cdo-python

# Install Climate Data Operators (CDO)
RUN apt-get update && apt-get install -y \
    cdo \
    && rm -rf /var/lib/apt/lists/*

# Install additional tools for weather data operations
RUN apt-get update && apt-get install -y \
    nco \
    ncl-ncarg \
    && rm -rf /var/lib/apt/lists/*

# Install R for statistical analysis
RUN apt-get update && apt-get install -y \
    r-base \
    r-base-dev \
    && rm -rf /var/lib/apt/lists/*

# Install R weather packages
RUN R --slave -e "install.packages(c('raster', 'rgdal', 'ncdf4', 'rasterVis', 'ncmeta'), repos='https://cran.rstudio.com/', dependencies=TRUE)"

# Add entrypoint script
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

# Create a working directory
WORKDIR /workspace

# Use the entrypoint script to handle user creation
ENTRYPOINT ["/entrypoint.sh"]