ARG BASE_IMAGE=ubuntu:20.04
ARG DEV_IMAGE=paraview-async-osmesa-dev

FROM ${DEV_IMAGE} AS devimage
FROM ${BASE_IMAGE}

LABEL maintainer="Jaswant Panchumarti <jaswant.panchumarti@kitware.com>"

ENV TZ "America/New_York"

# -----------------------------------------------------------------------------
# System package
# -----------------------------------------------------------------------------
RUN apt-get update  && \
  DEBIAN_FRONTEND="noninteractive" apt-get install -y tzdata && \
  ln -fs /usr/share/zoneinfo/America/New_York /etc/localtime && \
  dpkg-reconfigure --frontend noninteractive tzdata && \
  apt-get install -y --no-install-recommends \
    ca-certificates \
    libatomic1 \
    libjson-c-dev=0.13.1+dfsg-7ubuntu0.3 \
    libosmesa6 \
    libsigsegv-dev=2.12-2 \
    openssl &&\
  apt-get install -y --no-install-recommends python3-dev python3.8-venv python3-pip python3-setuptools && \
  update-alternatives --install /usr/bin/python python /usr/bin/python3 1 && \
  rm -rf /var/lib/apt/lists/*

# Trame for web app.
RUN python3 -m venv /opt/paraview-async/runtime/.pvenv && \
  . /opt/paraview-async/runtime/.pvenv/bin/activate && \
  pip install -U pip && \
  pip install trame

# Populate paraview async runtime, data.
COPY --from=devimage  /opt/scripts                           /opt/scripts
# Preserve spack directory structure, but do not copy sources, the `rpath` of libvtkServicesThallium contains `/opt/spack/opt/spack` entries.
COPY --from=devimage  /opt/spack/opt/spack                   /opt/spack/opt/spack
COPY --from=devimage  /opt/paraview-async/build/ExternalData /opt/paraview-async/data
COPY --from=devimage  /opt/paraview-async/install            /opt/paraview-async/runtime

# Copy the server script.
COPY docker/scripts/server.sh /opt/scripts/server.sh
# Copy the python examples.
COPY python /opt/paraview-async/apps

ENV PARAVIEW_ASYNC_DATA_DIR="/opt/paraview-async/data"
ENV PARAVIEW_ASYNC_RUNTIME_DIR="/opt/paraview-async/runtime"
ENV PARAVIEW_ASYNC_VENV_DIR="/opt/paraview-async/runtime/.pvenv"
ENV PARAVIEW_ASYNC_WEB_APP_DIR="/opt/paraview-async/apps"

ENTRYPOINT [ "/bin/bash", "/opt/scripts/server.sh" ]
