FROM tomcat:9-jre17-temurin-jammy

ENV CATALINA_BASE=/usr/local/tomcat
ENV CATALINA_HOME=/usr/local/tomcat

WORKDIR /root
ENV HOME /root


RUN apt-get -y update \
 && apt-get -y install apt-utils \
 && apt-get -y install libcfitsio-bin unzip


ENV WEBAPP_DIR=/webapps/vlkb-soda


COPY deps/ast_9.2.9-1_amd64.deb ./
RUN dpkg -i /root/ast_9.2.9-1_amd64.deb && ldconfig \
 && mkdir -p ${WEBAPP_DIR} \
 && mkdir -p /srv/surveys && mkdir -p /srv/cutouts \
 && mkdir -p /etc/pki/tls

ARG VLKB_VERSION
COPY vlkb-${VLKB_VERSION}.deb ./
COPY vlkb-soda-${VLKB_VERSION}.war ${WEBAPP_DIR}/
RUN dpkg -i vlkb-${VLKB_VERSION}.deb \
 && cd ${WEBAPP_DIR} && unzip vlkb-soda-${VLKB_VERSION}.war



# configure instance

ENV INST_DIR=/usr/local

RUN echo "${INST_DIR}/lib" > /etc/ld.so.conf.d/ast.conf && ldconfig \
 && echo "fits_path_surveys=/srv/surveys" > $WEBAPP_DIR/WEB-INF/classes/cutout.properties

# pre-configure port 8080 (no TSL)
COPY deps/server.xml deps/server-connector.xml ${CATALINA_BASE}/conf/

# modif permissions to allow run as non-root: need to config TSL and ROOT-CONTEXT
WORKDIR ${CATALINA_BASE}
RUN chmod -R a+rwX conf

# configure during start-up
COPY start-soda.sh.soda /root/start-soda.sh

RUN chmod +rx /root && chmod +rx /root/start-soda.sh
CMD ["sh", "-c", "/root/start-soda.sh"]

