FROM ubuntu:16.04

ENV ROCKSDB_VERSION=5.14.3
ENV GFLAGS_VERSION=2.2.1

RUN \
    apt-get update && \
    apt-get install -y software-properties-common python-software-properties && \
    add-apt-repository -y ppa:mhier/libboost-latest && \
    add-apt-repository -y ppa:ubuntu-toolchain-r/test && \
    apt-get update && \
    apt-get install -y boost1.67 gcc-6 g++-6 cmake && \
    apt-get install -y xz-utils build-essential git curl ninja-build \
                       libgflags-dev libsnappy-dev zlib1g-dev libbz2-dev libzstd-dev \
                       libsodium-dev libssl-dev openssl \
                       libtool automake autotools-dev libmagic-dev \
                       autoconf autoconf2.13 autoconf-archive shtool

# Install gflags from source to provide the cmake modules needed by RocksDB.
RUN \
    mkdir -p /tmpbuild/gflags && \
    cd /tmpbuild/gflags && \
    curl -L https://github.com/gflags/gflags/archive/v${GFLAGS_VERSION}.tar.gz -o gflags-${GFLAGS_VERSION}.tar.gz && \
    tar xfvz gflags-${GFLAGS_VERSION}.tar.gz && \
    cd /tmpbuild/gflags/gflags-${GFLAGS_VERSION} && \
    cmake -H. -Bbuild -GNinja -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=1 && \
    cmake --build build --target install && \
    rm -Rf /tmpbuild/


# Install RocksDB from source.
RUN \
    mkdir -p /tmpbuild/rocksdb && \
    cd /tmpbuild/rocksdb && \
    curl -L https://github.com/facebook/rocksdb/archive/v${ROCKSDB_VERSION}.tar.gz -o rocksdb-${ROCKSDB_VERSION}.tar.gz && \
    tar xfvz rocksdb-${ROCKSDB_VERSION}.tar.gz && \
    cd /tmpbuild/rocksdb/rocksdb-${ROCKSDB_VERSION} && \
    export CXX=g++-6 CC=gcc-6 && \
    cmake -H. -Bbuild -GNinja \
        -DCMAKE_BUILD_TYPE=Release \
        -DWITH_TESTS=0 \
        -DBUILD_SHARED_LIBS=1 \
        -DUSE_RTTI=1 && \
    cmake --build build --target install && \
    rm -Rf /tmpbuild/

RUN mkdir /build

WORKDIR /build

CMD [ "/bin/bash" ]