###############################################################################
# Dockerfile used to make gitlab.linphone.org:4567/bc/public/flexisip/bc-dev-rocky9:20260619_remove_nghttp2_asio
###############################################################################

FROM rockylinux:9

LABEL org.opencontainers.image.authors="Belledonne Communications <flexisip@belledonne-communications.com>"

# Install common general tools
RUN dnf install -y sudo vim wget curl-minimal tar

# Configure additional repositories
RUN dnf install -y \
        epel-release \
        dnf-plugins-core \
  # Code Ready Builder
 && dnf config-manager -y --set-enabled crb

# Update
RUN dnf makecache --refresh \
 && dnf -y update \
 # Install development tools
 && dnf -y install \
        bzip2 \
        ccache \
        clang \
        cmake \
        c-ares-devel \
        doxygen \
        gcc-toolset-15 \
        gcc-toolset-15-libasan-devel \
        gcc-toolset-15-libubsan-devel \
        git \
        libasan \
        libev-devel \
        libubsan \
        libuv-devel \
        llvm \
        make \
        ninja-build \
        python3 \
        python3-pip \
        rpm-build \
        yasm \
        zlib-devel \
      # Install all dependencies needed for Flexisip
        systemd-devel \
        openssl-devel \
        cpp-jwt-devel \
      # json-devel is a depency of cpp-jwt but not declared in its package dependencies
        json-devel \
        hiredis-devel \
        jansson-devel \
        libsqlite3x-devel \
        libpq-devel \
        mariadb-devel \
        nghttp2 \
        libnghttp2-devel \
        net-snmp-devel \
        xerces-c-devel \
        gsm-devel \
        opus-devel \
        mbedtls-devel \
        speex-devel \
        speexdsp-devel \
        libxml2-devel \
      # Dependencies of the B2BUA
        libvpx-devel  \
        jsoncpp-devel \
      # Dependencies of the tester
        mysql-server \
        rsync \
        squid \
 && dnf -y module install redis \
 && dnf -y clean all

# Install boost 1.81 (version available from repo is only 1.75, which is not compatible with GCC 15).
RUN wget -O boost_1_81_0.tar.gz https://sourceforge.net/projects/boost/files/boost/1.81.0/boost_1_81_0.tar.gz/download \
 && tar xzf boost_1_81_0.tar.gz \
 && cd boost_1_81_0 \
 && ./bootstrap.sh --prefix=/usr/local \
 && ./b2 --with=all -j 8 install \
 && cd .. \
 && rm -rf boost_1_81_0 boost_1_81_0.tar.gz \
 && export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

# Set rights to mysqld binary. For some unkown reason, mysqld is not executable even by root.
# Resetting the ownership solves the problem.
RUN chown root:root /usr/sbin/mysqld

# Configure user bc
RUN useradd -ms /bin/bash bc && \
    echo 'bc:cotcot' | chpasswd && \
    echo 'bc ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers

# Switch to 'bc' user
USER bc
WORKDIR /home/bc

# Install python3 modules.
# This must be done as user 'bc' because python modules are installed in /usr/local/lib when pip is invoked
# as root, and rpmbuild prevents python from searching its modules in this prefix. Installing with user 'bc' puts
# the modules in /home/bc/.local/bin.
RUN python3 -m pip install --user pystache six
ENV PATH=$PATH:/home/bc/.local/bin

# Load gcc-toolset-15 environment on starting
RUN echo 'source /opt/rh/gcc-toolset-15/enable' >> /home/bc/.bashrc && \
    echo 'source /opt/rh/gcc-toolset-15/enable' >> /home/bc/.shrc


ENV PS1='\[\e[34m\]\u@bc-dev-rocky9>\[\e[0m\] '

# CVE-2022-24765, from git 2.35.2 onward
RUN git config --global --add safe.directory *


# Example build commands
#
# export CC=gcc
# export CXX=g++
# export BUILD_DIR_NAME="build.rocky9"
# cd flexisip/
# cmake -S . -B ./$BUILD_DIR_NAME -G "Ninja" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX="$PWD/$BUILD_DIR_NAME/install" -DINTERNAL_LIBHIREDIS=ON -DENABLE_UNIT_TESTS=ON -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=ON
# cd $BUILD_DIR_NAME
# cmake --build . --target install
