FROM tomcat:9-jre17-temurin-jammy
LABEL Description="VLKB Ingestion / Ubuntu 22 (Jammy Jellyfish)"

COPY deps/ast_9.2.9-1_amd64.deb /tmp/

RUN apt -y update \
 && apt -y install sudo procps psmisc \
				curl wget vim make build-essential checkinstall tree htop unzip \
            libcfitsio-dev libpqxx-dev libcsv-dev \
 && dpkg -i /tmp/ast_9.2.9-1_amd64.deb \
 && echo "/usr/local/lib" > /etc/ld.so.conf.d/ast.conf && ldconfig \
 && apt -y install openssh-server postgresql-client

USER root
RUN useradd -ms /bin/bash devel \
 && usermod -aG sudo devel \
 && echo 'devel:ia2vlkb' | chpasswd 

USER devel
ENV USER=devel
WORKDIR /home/devel
ENV HOME=/home/devel

RUN echo "alias vlkb-dbinit='vlkb-obscore /usr/local/etc/vlkb-obscore/datasets.conf dbinit '" >> .bash_aliases
RUN echo "alias vlkb-dbcheck='vlkb-obscore /usr/local/etc/vlkb-obscore/datasets.conf dbcheck '" >> .bash_aliases
RUN echo "alias vlkb-dbadd='vlkb-obscore /usr/local/etc/vlkb-obscore/datasets.conf dbadd '" >> .bash_aliases
RUN echo "alias vlkb-dbremove='vlkb-obscore /usr/local/etc/vlkb-obscore/datasets.conf dbremove '" >> .bash_aliases
RUN echo "alias vlkb-dbmodgroups='vlkb-obscore /usr/local/etc/vlkb-obscore/datasets.conf dbmodgroups '" >> .bash_aliases

# allow sudo without pwd and sudo no checks on hosts
USER root
RUN echo 'devel ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/develallowallcmds \
 && echo 'Defaults !fqdn' > /etc/sudoers.d/nodns

RUN mkdir /var/run/sshd \
 && echo 'root:deb11develenv' | chpasswd \
 && sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config \
 && sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd

EXPOSE 22

# vlkb-obscore*.deb installs to /usr/local
ENV INST_DIR=/usr/local
ARG VLKB_VERSION
COPY vlkb-obscore-${VLKB_VERSION}.deb ./
RUN dpkg -i vlkb-obscore-${VLKB_VERSION}.deb

COPY start-ingestion.sh /root
RUN chmod +x /root/start-ingestion.sh
CMD ["/root/start-ingestion.sh"]


