# Base image for cmpt 745 projects
FROM ubuntu:questing AS build

# Pull in uv from the official repo
COPY --from=ghcr.io/astral-sh/uv:0.9.21 /uv /uvx /bin/

RUN apt-get update \
    \
    && `# Start with all normal ubuntu packages` \
    && DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends apt-utils \
         ca-certificates \
         software-properties-common \
         lsb-release \
         gnupg2 \
         wget \
         git \
         make \
         ninja-build \
         cmake \
         valgrind \
         heaptrack \
         cppcheck \
         libc6-dev \
         zlib1g-dev \
         googletest \
         libfmt-dev \
         libzstd-dev \
         python3 \
         python3-pip \
         python3-dev \
         libbpf-dev \
         python3-virtualenv \
         linux-tools-common \
         linux-tools-generic \
         libbpfcc-dev \
         gcc-15 \
         g++-15 \
         gdb \
         openjdk-25-jdk \
         maven \
         llvm-21 \
         clang-21 \
         lldb-21 \
         python3-clang-21 \
         llvm-21-dev \
         libclang-21-dev \
         liblldb-21-dev \
         clang-tidy-21 \
         clang-format-21 \
         clang-tools-21 \
         valgrind \
    \
     `# Configure the latest version of GCC as the default` \
    && update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-15 1000 \
    && update-alternatives --install /usr/bin/x86_64-linux-gnu-gcc x86_64-linux-gnu-gcc /usr/bin/x86_64-linux-gnu-gcc-15 1000 \
    && update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-15 1000 \
    \
    && `# Configure the latest version of LLVM as the default` \
    && update-alternatives --install /usr/bin/clang clang /usr/bin/clang-21 1000 \
    && update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-21 1000 \
    && update-alternatives --install /usr/bin/llvm-profdata llvm-profdata /usr/bin/llvm-profdata-21 1000 \
    && update-alternatives --install /usr/bin/llvm-cov llvm-cov /usr/bin/llvm-cov-21 1000 \
    && update-alternatives --install /usr/bin/opt opt /usr/bin/opt-21 1000 \
    \
    && `# Final apt cleanup` \
    && rm -rf /var/lib/apt/lists/* \
    \
    && `# Build Google Benchmark from source for a release build` \
    && git clone https://github.com/google/benchmark.git \
    && cd benchmark \
    && cmake -E make_directory "build" \
    && cmake -DBENCHMARK_ENABLE_TESTING=off \
             -DBENCHMARK_DOWNLOAD_DEPENDENCIES=on \
             -DCMAKE_BUILD_TYPE=Release -S . -B "build" \
    && cmake --build "build" --config Release \
    && cmake --install "build" \
    && cd .. \
    && rm -rf ./benchmark



ENV PATH="/opt/env745/bin:$PATH"


# Set up the non-root user
ARG USERNAME=student
ARG USER_UID=9000
ARG USER_GID=$USER_UID

RUN groupadd --gid $USER_GID $USERNAME \
    && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
    && echo "$USERNAME ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers

WORKDIR /home/$USERNAME/
USER $USERNAME

# Spin up a bash shell by default
CMD ["/bin/bash"]

