FROM ocaml/opam2:debian-10

LABEL maintainer="David Trattnig <david.trattnig@subsquare.at>"

# Engine System Dependencies

RUN sudo apt-get update && sudo apt-get -y install \
      apt-utils \
      redis-server \
      ffmpeg \
      quelcom \
      python3 \
      python3-pip \      
      build-essential \
      libmariadbclient-dev \
      default-libmysqlclient-dev

# Liquidsoap System Dependencies

RUN sudo apt-get install -qq -yy \
    libasound2-dev \
    libflac-dev \
    libjack-dev \
    libmad0-dev \
    libmp3lame-dev \
    libogg-dev \
    libopus-dev \
    libpcre3-dev \
    libpulse-dev \
    libsamplerate0-dev \
    libssl-dev \
    libtag1-dev \
    libvorbis-dev \
    m4 \
    pkg-config

# Update OPAM

RUN opam init --disable-sandboxing -y
RUN opam switch create 4.08.0
RUN opam update -y
RUN opam install depext -y

# Liquidsoap Dependencies

RUN opam depext taglib mad lame vorbis flac opus cry samplerate pulseaudio bjack alsa ssl liquidsoap -y 
RUN opam install taglib mad lame vorbis flac opus cry samplerate pulseaudio bjack alsa ssl liquidsoap -y

# Print Debug Information

RUN echo $(python3 -V)
RUN echo $(python3.7 -V)
RUN echo $(ls /home/opam/.opam/4.08.0/bin/liquidsoap)

# Setup Engine

RUN mkdir -p /srv
RUN mkdir -p /home/opam/audio
RUN mkdir -p /home/opam/audio/source
COPY . /srv
WORKDIR /srv
ENV PATH="/home/opam/.local/bin:${PATH}"
RUN sudo usermod -a -G audio opam
RUN python3.7 $(which pip3) install -r requirements.txt
COPY configuration/sample-docker.engine.ini /srv/configuration/engine.ini

# Start the Engine

ENTRYPOINT ["./run.sh"]