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

FROM rockylinux/rockylinux:8

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

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

# Configure additional repositories
RUN dnf install -y epel-release && \
        sudo dnf install -y dnf-plugins-core && \
        sudo dnf config-manager -y --set-enabled powertools

# Update
RUN sudo dnf makecache --refresh && dnf -y update

# Install development tools
RUN sudo dnf -y install \
                   bzip2 \
                   ccache \
                   clang-20.1.8 \
                   cmake \
                   c-ares-devel \
                   doxygen \
                   gcc-toolset-14 \
                   gcc-toolset-14-libasan-devel \
                   gcc-toolset-14-libubsan-devel \
                   gcc-toolset-14-gdb \
                   git \
                   libasan \
                   libev-devel \
                   libubsan \
                   libuv-devel \
                   llvm-20.1.8 \
                   make \
                   ninja-build \
                   python3 \
                   python3-pip \
                   rpm-build \
                   yasm \
                   zlib-devel \
                 # Install all dependencies needed for Flexisip
                   systemd-devel \
                   openssl-devel \
                   boost-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
                   mariadb-server \
                   rsync \
                   squid \
               &&  dnf -y module install redis:6 \
               &&  dnf -y clean all

# 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-14 environment on starting
RUN echo 'source /opt/rh/gcc-toolset-14/enable' >> /home/bc/.bashrc && \
    echo 'source /opt/rh/gcc-toolset-14/enable' >> /home/bc/.shrc


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

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

# Example build commands
#
# export CC=clang
# export CXX=clang++
# export BUILD_DIR_NAME="build.rocky8"
# cd flexisip/
# cmake -S . -B ./$BUILD_DIR_NAME -G "Ninja" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX="$PWD/$BUILD_DIR_NAME/install" -DENABLE_UNIT_TESTS=ON -DINTERNAL_LIBHIREDIS=ON -DINTERNAL_JSONCPP=ON -DENABLE_G729=ON
# cd $BUILD_DIR_NAME
# cmake --build . --target install
