# based on official Cytoscape image: https://github.com/cytoscape/docker-cytoscape-desktop
# version more compact due to:
# - removed unnecessary packages and instructions --> remote display not used
# - included all environment variables within this Dockerfile, no need to use Docker compose for the build process
FROM ubuntu:22.04

# environment variables
ENV CYTOSCAPE_VERSION=3.10.2
ENV VIRTUAL_SCREEN_WIDTH=1920
ENV VIRTUAL_SCREEN_HEIGHT=1080
ENV CYREST_PORT=1234
ENV SUPERVISOR_CFG="/etc/supervisor/conf.d/supervisord.conf"

# labels
LABEL cytoscape_version="${CYTOSCAPE_VERSION}"
LABEL context="independent CyREST instance for graph rendering"

# change user
USER root
# install necessary packages
RUN apt update && apt full-upgrade -y && apt -y install \
    libxcursor1 \
    openjdk-17-jre \
    supervisor \
    wget \
    xvfb
# set Java home directory as permanently set ENV var
RUN echo "export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64" >> /root/.bashrc
# download and extract Cytoscape
RUN wget https://github.com/cytoscape/cytoscape/releases/download/${CYTOSCAPE_VERSION}/cytoscape-unix-${CYTOSCAPE_VERSION}.tar.gz
RUN tar -xf cytoscape-unix-${CYTOSCAPE_VERSION}.tar.gz && rm cytoscape-unix-${CYTOSCAPE_VERSION}.tar.gz

# supervisord config
# supervisor used to start the virtual display via Xvfb and the Cytoscape process with web server (CyREST)
COPY supervisord.conf ${SUPERVISOR_CFG}
EXPOSE ${CYREST_PORT}
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
