FROM debian:bullseye-slim
LABEL Description="vlkb tomcat9"

WORKDIR /root
ENV HOME /root


RUN apt -y update \
 && apt -y install sudo procps psmisc tree wget curl vim make build-essential checkinstall git \
                   libcfitsio-dev libpqxx-dev librabbitmq-dev libcsv-dev gfortran \
                   openjdk-17-jre-headless unzip \
                   rabbitmq-server openjdk-17-jre openjdk-17-jdk tomcat9 tomcat9-admin \
                   postgresql-client


RUN mkdir -p /webapps/vlkb-search
ARG VLKB_VERSION
COPY vlkb-search-${VLKB_VERSION}.war /webapps/vlkb-search/
RUN cd /webapps/vlkb-search && jar -xf vlkb-search-${VLKB_VERSION}.war \
 && mkdir /srv/surveys
COPY postgresql-*.jar  /var/lib/tomcat9/lib

# Lines with postgresql_*.jar: provide DB-driver so Tomcat loads it
# vlkb-search does not explicitely load DB-driver


# configure instance

COPY config-vlkb/auth.properties config-vlkb/neatoken.properties config-vlkb/iamtoken.properties config-vlkb/formatresponsefilter.properties /webapps/vlkb-search/WEB-INF/classes/

#COPY ssl/keystore.jks /root/
COPY ssl/server.xml ssl/server-connector-8080.xml ssl/server-connector-8443.xml /etc/tomcat9/

# configure during docker run-time

COPY entrypoint.sh /root

RUN echo "alias log-catalina='ls -t /var/log/tomcat9/catalina*.log | head -n 1 | xargs tail -200 '" >> /root/.bashrc 

# run

RUN pwd && chmod +x /root/entrypoint.sh
CMD ["sh", "-c", "/root/entrypoint.sh"]

