IMAGE motech_1.3.0-200313
FROM alpine3.11-tomcat7_7.0.99-200313

RUN EOF
    # Download Motech
    wget http://nexus.motechproject.org/service/local/repositories/releases/content/org/motechproject/motech-platform-server/1.3/motech-platform-server-1.3.war -O /tmp/motech.war
    mkdir /srv/tomcat/webapps/ROOT
    unzip /tmp/motech.war -d /srv/tomcat/webapps/ROOT

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

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

    # Cleanup
    rm -f /tmp/motech.war
EOF

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