ARG BASE_IMAGE=ubuntu:20.04
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 \
    libgomp1 \
    libosmesa6 \
    curl \
    openssl &&\
  apt-get install -y --no-install-recommends python3.9-dev python3.9-venv python3-pip python3-setuptools && \
  update-alternatives --install /usr/bin/python python /usr/bin/python3 1 && \
  rm -rf /var/lib/apt/lists/*

# Download paraview binaries.
RUN curl \
  "https://www.paraview.org/paraview-downloads/download.php?submit=Download&version=v5.11&type=binary&os=Linux&downloadFile=ParaView-5.11.0-RC2-osmesa-MPI-Linux-Python3.9-x86_64.tar.gz" \
  --output paraview.tar.gz && \
  mkdir -p /opt/paraview/runtime && \
  tar -xzf paraview.tar.gz -C /opt/paraview/runtime --strip-components=1 && \
  rm paraview.tar.gz

RUN curl \
  "https://www.paraview.org/files/ExternalData/SHA512/e6de2c81f7cfda82cdcad65da1a7a5c3817e8c6ced1366e95ab1593cc529e207ff33a9da3b1e4e280a5c4b6c4d5821a9167b90c5f9e8dcc1e07c64f0e1cfe594" \
  --output rock.vti && \
  mkdir -p /opt/paraview/data/Testing/Data && \
  mv rock.vti /opt/paraview/data/Testing/Data/

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

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

# If spack package versions have changed, update the LD path here.
ENV PARAVIEW_DATA_DIR="/opt/paraview/data"
ENV PARAVIEW_RUNTIME_DIR="/opt/paraview/runtime"
ENV PARAVIEW_VENV_DIR="/opt/paraview/runtime/.pvenv"
ENV PARAVIEW_WEB_APP_DIR="/opt/paraview/apps"

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