FROM --platform=linux/amd64 base
MAINTAINER Stefano Alberto Russo <stefano.russo@inaf.it>

# Switch to root
USER root


#------------------------
# Kasm VNC
#------------------------

# Install xvfb that triggers minimal install of X base packages and xterm as sample application,
# plus Python3 which is required for Kasm VNC
RUN apt-get install xvfb xterm net-tools python3 libjpeg8 libgomp1 -y

# Kasm VNC
COPY files/kasmvnc.ubuntu_focal.tar.gz /tmp
RUN sudo tar xz --strip 1 -C / -f /tmp/kasmvnc.ubuntu_focal.tar.gz && rm /tmp/kasmvnc.ubuntu_focal.tar.gz
RUN rm /usr/local/bin/Xvnc
COPY files/Xkasmvnc /usr/local/bin/Xvnc
RUN chmod 755  /usr/local/bin/Xvnc
RUN cd /tmp && wget http://archive.ubuntu.com/ubuntu/pool/main/n/nettle/libnettle6_3.4.1-0ubuntu0.18.04.1_amd64.deb && dpkg -i libnettle6_3.4.1-0ubuntu0.18.04.1_amd64.deb

# KASM VNC startup script
COPY files/run_kasm.sh /usr/local/bin/run_kasm.sh
RUN chmod 755 /usr/local/bin/run_kasm.sh

# X environment setup/startup
RUN mkdir -p /metauser_home_vanilla/.vnc
COPY files/xstartup /metauser_home_vanilla/.vnc
RUN chmod 755 /metauser_home_vanilla/.vnc/xstartup


#------------------------
# Post-intall
#------------------------

# Fix home permissions
RUN chmod 777 /home

# Set entrypoint command
ENV DEFAULT_ENTRYPOINT_COMMAND="/usr/local/bin/run_kasm.sh"

# Set user
USER metauser

# Set container name
ENV CONTAINER_NAME='x11web'



