IMAGE sigmah_2.0.2-200403
FROM alpine3.11-tomcat8.5_8.5.53-200403

RUN EOF
    # Download Sigmah
    wget https://github.com/sigmah-dev/sigmah/releases/download/v2.0.2/sigmah-2.0.2.war -O /tmp/sigmah.war
    mkdir /srv/tomcat/webapps/sigmah
    unzip /tmp/sigmah.war -d /srv/tomcat/webapps/sigmah

    # Update Postgres JDBC driver
    rm /srv/tomcat/webapps/sigmah/WEB-INF/lib/postgresql-9.1-901-1.jdbc4.jar
    wget https://jdbc.postgresql.org/download/postgresql-42.2.11.jar -O /srv/tomcat/webapps/sigmah/WEB-INF/lib/postgresql-42.2.11.jar

    # Remove logging config
    rm /srv/tomcat/webapps/sigmah/WEB-INF/classes/logback.xml

    # Change webapps ownership
    chown -R tomcat:tomcat /srv/tomcat/webapps

    # Download database files
    wget https://github.com/sigmah-dev/sigmah/releases/download/v2.0.2/sigmah-MinimumDataKit-2.0.postgresql.sql -O /srv/sigmah-MinimumDataKit.sql
    wget https://github.com/sigmah-dev/sigmah/releases/download/v2.0.2/sigmah-newOrganizationLaunchScript-2.0.postgresql.sql -O /srv/sigmah-newOrganizationLaunchScript.sql

    # Cleanup
    rm /tmp/sigmah.war
EOF

COPY image.d

USER tomcat
WORKDIR /srv/tomcat
CMD /usr/bin/catalina.sh run
