FROM ubuntu:16.04
MAINTAINER Adrien Béraud <adrien.beraud@savoirfairelinux.com>
RUN apt-get update && apt-get install -y \
        build-essential cmake git wget libncurses5-dev libreadline-dev nettle-dev \
        libgnutls28-dev libuv1-dev cython3 python3-dev python3-setuptools libcppunit-dev libjsoncpp-dev \
        autotools-dev autoconf libssl-dev \
    && apt-get clean

RUN echo "*** Installing libfmt ***" \
    && wget https://github.com/fmtlib/fmt/archive/5.3.0.tar.gz \
    && tar -xzf 5.3.0.tar.gz && cd fmt-5.3.0/ \
    && cmake -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_SHARED_LIBS=On -DFMT_TEST=Off -DFMT_DOC=Off . \
    && make -j8 && make install \
    && cd ../ && rm -rf fmt*

# libhttp-parser-dev is 2.1-2 which is too old
RUN echo "*** Building nodejs/http_parser dependency ***" \
    && wget https://github.com/nodejs/http-parser/archive/v2.9.2.tar.gz \
    && tar xvf v2.9.2.tar.gz && cd http-parser-2.9.2/ \
    && PREFIX=/usr make -j8 install \
    && cd ../ && rm -rf http-parser*

# libasio-dev (1.10.6-3) is too old
RUN echo "** Building a recent version of asio ***" \
    && wget https://github.com/aberaud/asio/archive/a7d66ef4017d8f1b7f2cef1bb4ba8e23b0961571.tar.gz \
    && tar -xvf a7d66ef4017d8f1b7f2cef1bb4ba8e23b0961571.tar.gz && cd asio-a7d66ef4017d8f1b7f2cef1bb4ba8e23b0961571/asio \
    && ./autogen.sh && ./configure --prefix=/usr --without-boost --disable-examples --disable-tests  \
    && make install \
    && cd ../../ && rm -rf asio*

RUN echo "*** Downloading RESTinio ***" \
    && mkdir restinio && cd restinio \
    && wget https://github.com/aberaud/restinio/archive/a7a10e419d9089c5b8ee63f5e3098c892f22fae4.tar.gz \
    && ls -l && tar -xzf a7a10e419d9089c5b8ee63f5e3098c892f22fae4.tar.gz \
    && cd restinio-a7a10e419d9089c5b8ee63f5e3098c892f22fae4/dev \
    && cmake -DCMAKE_INSTALL_PREFIX=/usr -DRESTINIO_TEST=OFF -DRESTINIO_SAMPLE=OFF \
             -DRESTINIO_INSTALL_SAMPLES=OFF -DRESTINIO_BENCH=OFF -DRESTINIO_INSTALL_BENCHES=OFF \
             -DRESTINIO_FIND_DEPS=ON -DRESTINIO_ALLOW_SOBJECTIZER=Off -DRESTINIO_USE_BOOST_ASIO=none . \
    && make -j8 && make install \
    && cd ../../ && rm -rf restinio*


# build restbed from sources
RUN git clone --recursive https://github.com/corvusoft/restbed.git \
	&& cd restbed && mkdir build && cd build \
	&& cmake -DBUILD_TESTS=NO -DBUILD_EXAMPLES=NO -DBUILD_SSL=NO -DBUILD_SHARED=YES -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_INSTALL_LIBDIR=lib .. \
	&& make -j8 install \
	&& cd .. && rm -rf restbed

#build msgpack from source
RUN wget https://github.com/msgpack/msgpack-c/releases/download/cpp-2.1.5/msgpack-2.1.5.tar.gz \
    && tar -xzf msgpack-2.1.5.tar.gz \
    && cd msgpack-2.1.5 && mkdir build && cd build \
    && cmake -DMSGPACK_CXX11=ON -DMSGPACK_BUILD_EXAMPLES=OFF -DCMAKE_INSTALL_PREFIX=/usr .. \
    && make -j8 && make install \
    && cd ../.. && rm -rf msgpack-2.1.5 msgpack-2.1.5.tar.gz
