###############################################################################
# Dockerfile used to make gitlab.linphone.org:4567/bc/public/linphone-sdk/bc-dev-centos8:20230706_add_deps_for_av1
###############################################################################

FROM centos:8

MAINTAINER Peio Rigaux <peio.rigaux@belledonne-communications.com>

#ENV RPM_BUILD_NCPUS=5
ENV SHELL=/bin/bash

# Changes reposiories as they have been moved since Centos8 end of life (see https://techglimpse.com/failed-metadata-repo-appstream-centos-8/)
# TODO create rockylinux image and deprecate this one)
RUN sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-* && sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.epel.cloud|g' /etc/yum.repos.d/CentOS-* && dnf makecache

# Configure additional repositories and install common general tools
RUN dnf install --refresh -y https://download.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm  && dnf install -y https://download1.rpmfusion.org/free/el/rpmfusion-free-release-8.noarch.rpm && dnf install -y https://download1.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-8.noarch.rpm && rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro && rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm && \
  dnf install -y nano sudo which

#Getting rid of "Failed to download metadata for repo '**BaseOS**'"
RUN rm -f /etc/yum.repos.d/CentOS-Media.repo && \
    rm -f /etc/yum.repos.d/CentOS-Linux-Media.repo

RUN dnf updateinfo -y && dnf install --refresh -y dnf-plugins-core && dnf config-manager --enable powertools

# Install CMake from the tar.gz as it is not packaged anymore in EPEL
ENV CMAKE3_HOME /opt/cmake3
RUN mkdir $CMAKE3_HOME && \
    curl --fail --silent --show-error \
         --location https://cmake.org/files/v3.22/cmake-3.22.6-linux-x86_64.tar.gz | \
    tar --extract --gzip --no-same-owner --file - --strip-components=1 --directory $CMAKE3_HOME

# Install development tools
RUN dnf updateinfo -y && dnf install --refresh -y at bison ccache clang doxygen gcc-c++ gdb gettext-devel git libtool make meson nasm ninja-build patch perl redhat-lsb-core rpm-build yasm

# Install python3 and python modules
RUN dnf install -y python3 python3-pip && \
    python3 -m pip install six && \
    python3 -m pip install pystache && \
    python3 -m pip install graphviz

# Install linphone & flexisp dependencies development packages
RUN dnf updateinfo -y && dnf install -y alsa-lib-devel glew-devel gsm-devel jansson-devel libbsd-devel libsrtp-devel libv4l-devel libvpx-devel libXv-devel libxml2-devel mariadb-devel mbedtls-devel mesa-libEGL-devel net-snmp-devel openssh openssh-clients openssl-devel opus-devel postgresql-devel protobuf-devel pulseaudio-libs-devel speex-devel sqlite-devel xerces-c-devel xsd

# Install ffmpeg without gpg check because of particular repo
RUN dnf updateinfo -y && dnf install --refresh -y ffmpeg-devel

# Install linphone runtime dependencies
RUN dnf updateinfo -y && dnf install --refresh -y mesa-dri-drivers && \
    dbus-uuidgen > /var/lib/dbus/machine-id

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

ENV PATH=$PATH:$CMAKE3_HOME/bin/:/opt/com.belledonne-communications/linphone/bin

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

# Install python3 and python modules.
# This must be done as 'bc' user because some python modules are installed into /usr/local/lib when pip is invoked
# as root, and rpmbuild prevent python from seaching its modules in this prefix. Using 'bc' user make the python
# modules to be installed into /home/bc/.local/lib.
RUN sudo dnf install -y python2-pip python3 python3-pip && sudo dnf clean all && \
    python3 -m pip install --user six pystache graphviz jsonschema jinja2

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