FROM ubuntu:latest

MAINTAINER S. Koulouzis "S.Koulouzis@uva.nl"


ARG RABBITMQ_HOST=127.0.0.1
ARG MONOG_HOST=127.0.0.1
ARG RELESE_VERSION=0.1
ARG CERTS=/etc/grid-security/certificates


##install java
ENV DEBIAN_FRONTEND=noninteractive 
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends 
RUN apt-get upgrade -y
RUN apt-get install -y wget git software-properties-common build-essential libssl-dev libffi-dev myproxy 
RUN apt-get install -y python-software-properties debconf-utils apt-utils
RUN add-apt-repository -y ppa:webupd8team/java
RUN apt-get update
RUN "oracle-java8-installer shared/accepted-oracle-license-v1-1 select true" | debconf-set-selections
RUN echo debconf shared/accepted-oracle-license-v1-1 select true | debconf-set-selections
RUN echo debconf shared/accepted-oracle-license-v1-1 seen true | debconf-set-selections
RUN apt-get install -y oracle-java8-installer


##install drip-manager
WORKDIR /root
# RUN wget http://www-eu.apache.org/dist/tomcat/tomcat-7/v7.0.75/bin/apache-tomcat-7.0.75.tar.gz
RUN wget https://github.com/QCAPI-DRIP/DRIP-integradation/releases/download/0.1/apache-tomcat-7.0.75.tar.gz
RUN tar -xzf apache-tomcat-7.0.75.tar.gz
WORKDIR apache-tomcat-7.0.75
RUN wget https://github.com/QCAPI-DRIP/DRIP-integradation/releases/download/$RELESE_VERSION/drip-api-1.0-SNAPSHOT.tar.gz 
RUN tar -xzvf drip-api-1.0-SNAPSHOT.tar.gz
RUN sed -ie "s/^message.broker.host=.*/message.broker.host=$RABBITMQ_HOST/" drip-api-1.0-SNAPSHOT/WEB-INF/classes/drip.properties
RUN sed -ie "s/^db.host=.*/db.host=$MONOG_HOST/" drip-api-1.0-SNAPSHOT/WEB-INF/classes/drip.properties
RUN cat drip-api-1.0-SNAPSHOT/WEB-INF/classes/drip.properties
RUN mv drip-api-1.0-SNAPSHOT webapps/drip-api

WORKDIR /root
RUN echo "/root/apache-tomcat-7.0.75/bin/startup.sh" >> startAll.sh
RUN echo "tail -f ./apache-tomcat-7.0.75/logs/catalina.out" >> startAll.sh
RUN echo "while true" >> startAll.sh
RUN echo "do" >> startAll.sh
RUN echo "sleep 10s" >> startAll.sh
RUN echo "done" >> startAll.sh


EXPOSE 8080
RUN chmod +x startAll.sh
ENTRYPOINT ./startAll.sh

# To build: docker build -t drip-manager .
# To run: docker run --name drip-manager-inst -p 127.0.0.1:8080:8080 -d drip-manager