# ESGF Identity Provider node
# Implemented as Java web servlet application running inside Tomcat container.

ARG ESGF_IMAGES_HUB=esgfhub
ARG ESGF_VERSION=devel

FROM $ESGF_IMAGES_HUB/esgf-tomcat:$ESGF_VERSION

MAINTAINER Earth System Grid Federation <esgf-devel@lists.llnl.gov>

# default ESGF repository
ARG ESGF_REPO=http://distrib-coffee.ipsl.jussieu.fr/pub/esgf

ADD $ESGF_REPO/dist/esgf-idp/esgf-idp.war /usr/local/tomcat/webapps/esgf-idp/
#ADD esgf-idp.war /usr/local/tomcat/webapps/esgf-idp/
RUN cd /usr/local/tomcat/webapps/esgf-idp/ && \
    jar xvf esgf-idp.war && \
    rm esgf-idp.war && \
    chown -R tomcat:tomcat /usr/local/tomcat/webapps/esgf-idp

# Override Tomcat startup to wait for Postgres connection to be ready
COPY scripts/wait_for_postgres.sh /usr/local/bin/wait_for_postgres.sh
COPY scripts/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
COPY scripts/process_esgf_config_archive.sh /usr/local/bin/process_esgf_config_archive.sh
COPY conf/supervisord.tomcat.conf /etc/supervisor/conf.d/supervisord.tomcat.conf

# FIXME: override Yadis configuration file to serve SLCS endpoints
# remove this override when change is entered into ESGF official war file
COPY conf/yadis-config.xml /usr/local/tomcat/webapps/esgf-idp/WEB-INF/classes/esg/idp/config/yadis-config.xml

ENTRYPOINT /usr/local/bin/docker-entrypoint.sh
