FROM ubuntu:18.04

RUN apt-get update -qq

RUN apt-get install -y -q gcc-7 g++-7 libmpeg2-4-dev libpq-dev \
                          libssl-dev libcrypto++-dev libyaml-cpp-dev \
                          libboost-dev liba52-dev opus-tools libopus-dev \
                          libsndfile-dev libavformat-dev libavutil-dev ffmpeg \
                          git automake libtool python python3 cmake wget \
                          libcurl4-openssl-dev libcurlpp-dev libcurl4-openssl-dev \
                          libcurlpp-dev

RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 99
RUN update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 99

RUN git clone https://github.com/jtv/libpqxx.git
RUN cd libpqxx && git checkout 6.2.5 && ./configure --enable-documentation=no && make -j3 install

RUN useradd --create-home --shell /bin/bash user

ENV LANG C.UTF-8
ENV LANGUAGE C:en
ENV LC_ALL C.UTF-8

RUN apt-get install python3.7 python3-pip -y
RUN python3.7 -m pip install --upgrade pip
COPY requirements.txt .
RUN python3.7 -m pip install -r requirements.txt
RUN rm requirements.txt

RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.7 7
RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 7

WORKDIR /home/user/puffer
RUN chown -R user:user /home/user/puffer/
RUN chmod 755 /home/user/puffer/
USER user

ENV INFLUXDB_PASSWORD '123456'
ENV PUFFER_PORTAL_SECRET_KEY '123456789'
ENV PUFFER_PORTAL_DB_KEY '123456'
ENV SSLKEYLOGFILE ~/.ssl-key.log

EXPOSE 8086
EXPOSE 5432

# clean and compile only in the docker!
# TODO:
#   support ubuntu:20.04
#   move only executable files

# docker rm $(docker ps -aq)
# docker image rm puffer/build -f