FROM debian:jessie

ENV GUILE_SCTP_VERSION="1.2.5"

RUN apt-get update
RUN apt-get upgrade -y

RUN apt-get install -y git gcc g++ make autoconf tcsh csh \
  guile-2.0 guile-2.0-dev libsctp-dev libtalloc-dev

RUN mkdir -p /workdir/libosmo-sctp

# Building m3ua-testtool
WORKDIR /workdir
RUN git clone git://git.osmocom.org/nplab/m3ua-testtool; \
    cd m3ua-testtool; \
    cc -o runm3uatest runm3uatest.c; \
    cp runm3uatest /usr/bin

# fetching sua-testtool
WORKDIR /workdir
RUN git clone git://git.osmocom.org/nplab/sua-testtool

# Building guile-sctp
ADD "https://github.com/nplab/guile-sctp/releases/download/v${GUILE_SCTP_VERSION}/guile-sctp-${GUILE_SCTP_VERSION}.tar.gz /workdir"
WORKDIR /workdir

RUN tar xvfz guile-sctp-${GUILE_SCTP_VERSION}.tar.gz; \
    rm guile-sctp-${GUILE_SCTP_VERSION}.tar.gz; \
    cd guile-sctp-${GUILE_SCTP_VERSION};\
    ./configure --prefix=/usr; \
    make; \
    make install

# setting LD_LIBRARY_PATH of depedencies within libosmo-sctp
ENV LD_LIBRARY_PATH="/workdir/libosmo-sctp/src/.libs/:/workdir/libosmo-sctp/deps/install/lib/"
VOLUME /workdir/libosmo-sctp
WORKDIR /workdir/libosmo-sctp/contrib/test

# Note: spawning a container of this docker image will fail in case one did NOT ensure following prerequisites:
#         - you must mount libosmo-sctp repository to :/workdir/libosmo-sctp, because the default WORKDIR points into it
#           (Of course, on can override this behavior via "docker run ..... -w /workdir ...")
#         - Furthermore libosmo-sctp needs to be compiled via its ./contrib/jenkins.sh buildscript.
#           Otherwise LD_LIBRARY_PATH won't hold dependencies necessary for test run.
#
# The following line will execute tests on jenkins.osmocom setup:
#
# docker run -it --rm --cap-add=NET_ADMIN -v $(pwd):/workdir/libosmo-sctp --name test01 <NAME_OF_BUILT_IMAGE> ./test-m3ua.sh 2>&1 | tee result.plain
#
# IDEA: it would be nice to use the "${JOB_NAME}_${BUILD_NUMBER}" as --name.
#       Then a 'docker ps' would directly show which jobs are running a container.
