
################################################################################
#
# MIT License
#
# Copyright 2024-2025 AMD ROCm(TM) Software
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell cop-
# ies of the Software, and to permit persons to whom the Software is furnished
# to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IM-
# PLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNE-
# CTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
################################################################################

# See here for image contents: https://github.com/devcontainers/images/tree/main/src/base-ubuntu

##
## Common with other Dockerfiles.
##

# ubuntu-20.04 = focal
# ubuntu-22.04 = jammy
FROM mcr.microsoft.com/devcontainers/base:jammy

ARG DEBIAN_FRONTEND=noninteractive

# Propagate the environment variable HTTP_PROXY into the apt config if it's set.
RUN [ -z ${HTTP_PROXY} ] || (echo "Acquire::http::Proxy \"${HTTP_PROXY}\";" > /etc/apt/apt.conf.d/proxy)

# Add PPA with g++-13
RUN apt-get update && apt-get reinstall -y software-properties-common && add-apt-repository -y ppa:ubuntu-toolchain-r/test

RUN apt-get update && apt-get install -y \
   bc \
   gdb \
   libopenblas-dev \
   libncurses-dev \
   m4 \
   make \
   nano \
   netcat-traditional \
   ninja-build \
   python3-dev \
   python3-venv \
   vim \
   wget \
   xz-utils

# Needed for clang-format from ROCm 4.3.1
RUN wget -nv --show-progress --progress=dot:mega -O /tmp/libtinfo5.deb http://security.ubuntu.com/ubuntu/pool/universe/n/ncurses/libtinfo5_6.3-2ubuntu0.1_amd64.deb \
    && apt-get install -y /tmp/libtinfo5.deb

# cmake 3.24.4
 RUN wget -nv --show-progress --progress=dot:mega -O /tmp/cmake-install.sh https://github.com/Kitware/CMake/releases/download/v3.24.4/cmake-3.24.4-linux-x86_64.sh \
   && sh /tmp/cmake-install.sh --prefix=/usr/local --skip-license \
   && rm /tmp/cmake-install.sh

# clang-format from ROCm 4.3.1
ADD docker/install-clang-format /tmp
RUN /tmp/install-clang-format && rm /tmp/install-clang-format
ENV PATH="/opt/clang-format/bin:${PATH}"

# ccache
RUN apt-get update && apt-get install -y \
      libzstd-dev
RUN wget -nv --show-progress --progress=dot:mega https://github.com/ccache/ccache/releases/download/v4.11/ccache-4.11.tar.gz -O /tmp/ccache-4.11.tar.gz && \
    tar xf /tmp/ccache-4.11.tar.gz -C /tmp && \
    cmake -S/tmp/ccache-4.11 -B/tmp/ccache-4.11/build -GNinja \
      -DCMAKE_BUILD_TYPE=Release \
      -DENABLE_TESTING=OFF \
      -DREDIS_STORAGE_BACKEND=OFF && \
    ninja -C /tmp/ccache-4.11/build install && \
    rm -r /tmp/ccache-4.11 /tmp/ccache-4.11.tar.gz

# cppcheck
ADD docker/install-cppcheck /tmp
RUN /tmp/install-cppcheck && rm /tmp/install-cppcheck

# graph & documentation & perf
RUN apt-get update && apt-get install -y \
      graphviz \
      doxygen \
      linux-tools-common linux-tools-generic

# Python
RUN python3 -m venv /opt/rr-python-venv
ENV PATH="/opt/rr-python-venv/bin:$PATH"
COPY requirements.txt /tmp/requirements.txt
RUN pip install --no-cache-dir -r /tmp/requirements.txt && rm /tmp/requirements.txt

# Install newer version of npm than is available on apt.
# This includes diff2html-cli for code coverage report.
ADD docker/setup-node /tmp
RUN bash --login -ex /tmp/setup-node install && rm /tmp/setup-node

# HipBLASLt
RUN apt-get update && apt-get install -y \
    libmsgpack-dev \
    libboost-program-options-dev \
    libboost-filesystem-dev \
    kmod

##
## Specific to this Dockerfile.  Put faster-changing-things last.
##

# ROCm
ARG ROCROLLER_AMDGPU_URL=https://repo.radeon.com/amdgpu-install/6.2.2/ubuntu/jammy/amdgpu-install_6.2.60202-1_all.deb
ARG ROCROLLER_AMDGPU_BUILD_NUMBER=
ARG ROCROLLER_AMDGPU_BUILD_URI=

RUN wget -nv --show-progress --progress=dot:mega -O /tmp/amdgpu_install.deb ${ROCROLLER_AMDGPU_URL} \
    && apt-get update \
    && apt-get install -y /tmp/amdgpu_install.deb \
    && rm /tmp/amdgpu_install.deb \
    && if test -n "${ROCROLLER_AMDGPU_BUILD_NUMBER}"; then amdgpu-repo --amdgpu-build=${ROCROLLER_AMDGPU_BUILD_NUMBER} --rocm-build=${ROCROLLER_AMDGPU_BUILD_URI}; fi \
    && amdgpu-install -y --usecase=rocmdev --no-dkms
RUN apt-get update && apt-get install -y rocm-llvm-dev

# g++-13
RUN apt-get update && apt-get install -y \
      g++-13

RUN ( \
    echo "base_image: ${base_image}" && \
    echo "rocroller: gcc-13" \
    ) > /.container_info.txt

ENV CXX=/usr/bin/g++-13
ENV CC=/usr/bin/gcc-13

# Clean image
RUN apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/*
