FROM ubuntu:16.04

ENV DEBIAN_FRONTEND noninteractive

RUN apt-get update && \
    apt-get install -y build-essential software-properties-common && \
    add-apt-repository -y ppa:ubuntu-toolchain-r/test
RUN apt-get update && \
    apt-get install -y \
            asciidoctor \
            cmake \
            gcc-snapshot \
            g++-6 \
            git \
            locales \
            man \
            python3 \
            python3-dateutil \
            tzdata

# Setup environment
RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 60 \
                        --slave /usr/bin/g++ g++ /usr/bin/g++-6 && \
    update-alternatives --config gcc && \
    update-alternatives --install /usr/bin/python python /usr/bin/python3 10
RUN ln -fs /usr/share/zoneinfo/Europe/Berlin /etc/localtime
RUN dpkg-reconfigure -f noninteractive tzdata

ENV LC_ALL en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US.UTF-8
RUN locale-gen "en_US.UTF-8"

# Setup timewarrior
ADD . /root/code/
WORKDIR /root/code/
RUN git clean -dfx
RUN git submodule init
RUN git submodule update
RUN cmake -DCMAKE_BUILD_TYPE=debug .
RUN make -j2
RUN make install

# Setup tests
WORKDIR /root/code/test/
RUN make

CMD ["bash", "-c", "./run_all -v ; cat all.log | grep 'not ok' ; ./problems ; FAILED=$? ; echo timew $( timew --version ) ; python --version ; cmake --version ; gcc --version ; exit $FAILED"]
