#
#	Setup a blank tooltwist server, based on tooltwist/ttdemo.
#
FROM tooltwist/docker-base-tooltwist:latest
WORKDIR /home/tooltwist

# Install the application
COPY resources/ttsvr-1/ /home/tooltwist/server/tomcat/webapps/ttsvr/
COPY resources/ttsvr-2/ /home/tooltwist/server/tomcat/webapps/ttsvr/
COPY resources/ttsvr-3/ /home/tooltwist/server/tomcat/webapps/ttsvr/

# Install site-conf
RUN mv /home/tooltwist/site-conf /home/tooltwist/site-conf.original
COPY resources/site-conf /home/tooltwist/site-conf

# Add/overwrite any Tomcat config files
COPY resources/tomcat /home/tooltwist/server/tomcat

# Create any extra directories
RUN mkdir -p /home/tooltwist/site-conf/logs /home/tooltwist/site-conf/bin

# Set ownership and permissions
# NOTE: This is no longer done here, as it adds a huge layer to the Docker
#       image. Instead it is now done in site-conf/bin/setenv.sh.
#RUN chown -R tooltwist site-conf server

# Start tomcat and tail the log file
USER root
CMD [ "/bin/bash", "-c", "cd /home/tooltwist/site-conf/bin; . ./setenv.sh; cd /home/tooltwist/server/tomcat/bin; ./startup.sh; echo v2; sleep 5; exec tail -f /home/tooltwist/server/tomcat/logs/catalina.out" ]
