# syntax=docker/dockerfile:1
FROM ubuntu:22.04

# Set environment variables
ENV EGL_PLATFORM=surfaceless
ENV CPLUS_INCLUDE_PATH=/usr/local/include
ENV LIBRARY_PATH=/usr/local/lib
ENV CPATH=/usr/local/include
ENV __NV_PRIME_RENDER_OFFLOAD=1
ENV __GLX_VENDOR_LIBRARY_NAME=nvidia

# Update and install sudo separately to debug the error
RUN apt-get update && apt-get install -y sudo

# Create a non-root user and add them to the sudo group, allow passwordless sudo
RUN useradd -m -s /bin/bash newuser && \
    echo 'newuser:password' | chpasswd && \
    usermod -aG sudo newuser && \
    echo 'newuser ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers

# Install app dependencies
RUN apt-get update && apt-get install -y \
    apt-utils \
    python3 \
    python3-pip \
    git \
    xvfb \
    cmake \
    python3-venv \
    libglm-dev \
    libglobjects-dev \
    cmake \
    libgtest-dev \
    libgl1-mesa-dev \
    libglu1-mesa-dev \
    libglfw3-dev \
    freeglut3-dev \
    libstdc++-12-dev \
    wget \
    libc6-dev \
    libpci3 \
    libelf-dev \
    libglvnd-dev \
    libxau6 \
    libxdmcp6 \
    libxcb1 \
    libxext6 \
    libx11-6 \
    libxv1 \
    libxtst6 \
    libdrm2 \
    libegl1 \
    libgl1 \
    libopengl0 \
    libgles1 \
    libgles2 \
    libglvnd0 \
    libglx0 \
    libglu1 \
    libsm6 \
    libegl-mesa0 \
    libegl1-mesa-dev \
    libgles2-mesa-dev \
    libgl1-mesa-dri \
    libglx-mesa0 \
    pkg-config \
    libsdl2-dev \
    libsdl2-image-dev \
    libsdl2-mixer-dev \
    mesa-utils && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

# Set clang++ as the default C++ compiler
RUN apt-get remove -y gcc && apt-get update -y && apt-get install -y clang
RUN apt-get install -y libgbm-dev libdrm-dev
ENV CXX=clang++

# Install GLM
RUN mkdir -p build && cd build && \
    git clone https://github.com/g-truc/glm && \
    cd glm && \
    cmake -DGLM_BUILD_TESTS=OFF -DBUILD_SHARED_LIBS=OFF -B build . && \
    cmake --build build --target all && \
    cmake --build build --target install

# Install Python dependencies
RUN python3 -m pip install --upgrade pip && \
    pip3 install stable_baselines3==2.3.2 tyro==0.8.5 wandb==0.17.3 tensorboard==2.17.0 gymnasium==0.29.1

# Additional tools
RUN apt install -y nano
RUN sudo apt-get install -y libglib2.0-0
RUN pip install tqdm
RUN pip install opencv-python

# Additional packages for running the agents
RUN pip install torch==2.5.1 torchvision==0.20.1 torchaudio==2.5.1 --index-url https://download.pytorch.org/whl/cu124
RUN pip install git+https://github.com/AgarCL/pfrl.git@main

RUN pip install matplotlib
RUN pip install packaging
RUN pip install wandb

# change the directory
WORKDIR /home/newuser/
