FROM ubuntu:16.04

ARG HOST_USER_UID=1000
ARG HOST_USER_GID=1000

# Password of hostuser is 'mypassword'
# The encrypted password was generated by 'openssl passwd -1 mypassword'
ENV HOST_USER_PASSWD '$1$6wh4yp6s$ug4KmE998wKLYSgM7vH4z.'
ENV LANG=C.UTF-8
ENV CMAKE_VERSION 3.11
ENV CMAKE_BUILD 0

RUN set -ex                                                                         && \
                                                                                       \
    dpkg --add-architecture i386                                                    && \
    apt-get update && apt-get install -y                                               \
        sudo \
        vim-tiny \
        texinfo \
        libglib2.0-dev \
        autoconf \
        libtool \
        libsdl-dev \
        build-essential \
        tofrodos \
        bison \
        g++-multilib \
        git \
        gperf \
        make \
        bc \
        zip \
        zlib1g-dev \
        zlib1g-dev:i386 \
        gdbserver \
        bash-completion \
        ninja \
        wget \
        curl \
        autopoint \
        flex \
        libncurses5-dev \
        python \
        python-sphinx \
    && curl -L -o /tmp/get-pip.py https://bootstrap.pypa.io/get-pip.py \
    && python /tmp/get-pip.py \
    && pip install sphinx_rtd_theme \
    && rm -rf /var/lib/apt/list/*

RUN set -ex                                                                         && \
                                                                                       \
    echo 'Creating non-root user and group from host'                               && \
    groupadd -f -g $HOST_USER_GID hostuser                                          && \
    useradd -lmo -p $HOST_USER_PASSWD -u $HOST_USER_UID -g $HOST_USER_GID hostuser  && \
    usermod -aG sudo hostuser                                                       && \
    echo 'hostuser        ALL=(ALL:ALL) NOPASSWD: ALL' >> /etc/sudoers              && \
    echo 'docker' > /etc/debian_chroot                                              && \
    wget https://cmake.org/files/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}.${CMAKE_BUILD}-Linux-x86_64.tar.gz -P /opt --no-verbose && \
    mkdir /opt/cmake                                                                && \
    tar xzf /opt/cmake-${CMAKE_VERSION}.${CMAKE_BUILD}-Linux-x86_64.tar.gz --strip-components=1 -C /opt/cmake && \
    rm -f /opt/cmake-${CMAKE_VERSION}.${CMAKE_BUILD}-Linux-x86_64.tar.gz            && \
    echo 'export ANDROID_NDK=/home/hostuser/android-ndk' > /home/hostuser/.bashrc_tmp  && \
    echo 'export PATH=/opt/cmake/bin:$PATH' >> /home/hostuser/.bashrc_tmp           && \
    cat /home/hostuser/.bashrc >> /home/hostuser/.bashrc_tmp                        && \
    mv /home/hostuser/.bashrc_tmp /home/hostuser/.bashrc


USER hostuser

VOLUME [ "/home/hostuser/Elastos.ORG.Wallet.Lib.C", "/home/hostuser/android-ndk" ]
WORKDIR /home/hostuser/Elastos.ORG.Wallet.Lib.C
