###############################################################################
# Dockerfile used to make gitlab.linphone.org:4567/bc/public/linphone-sdk/bc-dev-ubuntu-18-04-lts:20230915_gcc_10
###############################################################################

FROM ubuntu:18.04

ARG QT_VERSION=5.15.2
ARG QT_MODULES=qtwebengine qtnetworkauth qtquick3d

MAINTAINER Julien Wadel <julien.wadel@belledonne-communications.com>

# add fallbacks for timeout connections.
RUN apt-get -y --fix-missing update \
 && apt-get -y install software-properties-common python-pip \
#Swiss
 && add-apt-repository "deb http://ch.archive.ubuntu.com/ubuntu/ bionic main restricted universe multiverse" \
 && add-apt-repository "deb http://ch.archive.ubuntu.com/ubuntu/ bionic-updates main restricted universe multiverse" \
#Belgium
 && add-apt-repository "deb http://be.archive.ubuntu.com/ubuntu/ bionic main restricted" \
 && add-apt-repository "deb http://be.archive.ubuntu.com/ubuntu/ bionic-updates main restricted" \
#International
 && add-apt-repository "deb http://archive.archive.ubuntu.com/ubuntu/ bionic main restricted" \
 && add-apt-repository "deb http://archive.archive.ubuntu.com/ubuntu/ bionic-updates main restricted" \
 && add-apt-repository "deb http://security.archive.ubuntu.com/ubuntu/ bionic-security main restricted" \
 && add-apt-repository ppa:ubuntu-toolchain-r/test \
 && pip install apt-mirror-updater

# Configure locale
RUN apt-mirror-updater --auto-change-mirror && \
    apt-mirror-updater --update && \
    apt-get update && \
    apt-get install -y locales && \
    apt-get clean && \
    echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && \
    locale-gen
ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en' LC_ALL='en_US.UTF-8'
ENV TZ=Europe/Paris
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
ARG DEBIAN_FRONTEND=noninteractive

ENV SHELL=/bin/bash
#ENV PS1='\[\e[33m\]\u@bc-dev-ubuntu-18-04>\[\e[0m\] '

# Install common general tools
RUN apt-get update && \
    apt-get install -y nano sudo vim && \
    apt-get clean

# Install development tools
RUN apt-get update && \
    apt-get -y --fix-missing install alien at autoconf bison ccache clang-10 llvm-10 cmake doxygen elfutils gcc-10 g++-10 gdb git graphviz intltool libtool lsb-release make nasm ninja-build openssh-client patch perl python3-pip python3-pystache python-six yasm && \
    apt-get clean

# Install linphone & flexisip dependencies development packages
RUN apt-get update && \
    apt-get -y --fix-missing install libasound2-dev libavcodec-dev libavutil-dev libbsd-dev libegl1-mesa-dev libglew-dev libgsm1-dev libjansson-dev libmariadb-dev-compat libmbedtls-dev libopus-dev libpq-dev libprotobuf-dev libpulse-dev libqt5svg5-dev libsnmp-dev libspeex-dev libspeexdsp-dev libsqlite3-dev libsrtp2-dev libssl-dev libswscale-dev libturbojpeg0-dev libv4l-dev libvpx-dev libxerces-c-dev libxml2-dev libxv-dev protobuf-compiler qttools5-dev qttools5-dev-tools xsdcxx && \
    apt-get clean

# Install signing tools
RUN sudo apt-get install -y gnupg2

# Install configuration tools
RUN sudo apt-get install -y wget

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

#Update certificates
RUN sudo sed -i '/^mozilla\/DST_Root_CA_X3/s/^/!/' /etc/ca-certificates.conf
RUN sudo update-ca-certificates -f

# Install newest cmake. Documented at https://gist.github.com/bmegli/4049b7394f9cfa016c24ed67e5041930
RUN wget https://github.com/Kitware/CMake/releases/download/v3.25.3/cmake-3.25.3.tar.gz && \
	tar -zvxf cmake-3.25.3.tar.gz && \
	cd cmake-3.25.3 && ./bootstrap && make -j8 && \
	sudo apt-get install checkinstall && sudo checkinstall --pkgname=cmake --pkgversion="3.25-custom" --default && hash -r && \
	cd .. && sudo rm -rf cmake-3.25.3 && rm -rf cmake-3.25.3.tar.gz

# Install nasm from source as we need a newer version than the one being packaged
RUN curl --fail --silent --show-error --location https://www.nasm.us/pub/nasm/releasebuilds/2.16.01/nasm-2.16.01.tar.gz | \
    tar --extract --gzip --file - && cd nasm-2.16.01 && \
    ./configure --prefix=/usr/local && make && make install && \
    cd .. && rm -rf nasm-2.16.01
	
###########				QT

RUN sudo apt-get update && sudo apt-get install -y libxkbcommon* flite1-dev libspeechd-dev speech-dispatcher libfontconfig1-dev libfreetype6-dev libx11-dev libxext-dev libxfixes-dev libxi-dev libxrender-dev libx11-xcb* libxcb* qdbus-qt5 libqt5dbus5 libdbus-1-dev libdbus-glib-1-dev libatspi2.0-0 libatspi2.0-dev
RUN sudo apt-get update && sudo apt-get install -y libxcb-keysyms1-dev libxcb-image0-dev libxcb-shm0-dev libxcb-icccm4-dev libxcb-sync0-dev libxcb-xfixes0-dev libxcb-shape0-dev libxcb-randr0-dev libxcb-render-util0-dev 

# Configure clang
RUN sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-10 100 && \
    sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-10 100 && \
    sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 100 && \
    sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 100

USER bc
WORKDIR /home/bc

#	Manual
## avoid error 104 while installing, and egg_info issue.
RUN sudo python3 -m pip install "requests[security]"
RUN sudo pip3 install --upgrade setuptools
RUN sudo pip3 install ez_setup

## For mbedtls build
RUN sudo pip3 install jsonschema jinja2

## Install meson through pip to have a newer version
RUN sudo pip3 install meson

## Install Qt download tool
RUN sudo pip3 install py7zr aqtinstall
RUN sudo python3 -m aqt install $QT_VERSION linux desktop -O /opt/Qt -m $QT_MODULES

RUN sudo chown -R bc:bc /opt/Qt/

ENV Qt5_DIR=/opt/Qt/$QT_VERSION/gcc_64/lib/cmake
ENV PATH=/opt/Qt/$QT_VERSION/gcc_64/bin:$PATH

CMD bash
