from openjdk:7

ENV GHN_HOME=/SmartGears-Bundle/
ENV BUNDLE_HOME=$GHN_HOME
ENV CATALINA_HOME=$GHN_HOME/tomcat/
ENV CATALINA_OPTS="-Xmx2000m -Xms2000m -XX:MaxPermSize=512M" 
ENV CATALINA_PID=$CATALINA_HOME/pid.txt

#WORKDIR $GHN_HOME/

RUN  \
  wget http://maven.research-infrastructures.eu/nexus/service/local/repositories/{{ repo }}/content/org/gcube/distribution/smartgears-distribution-bundle/{{ smartgears_version }}/smartgears-distribution-bundle-{{ smartgears_version }}.tar.gz \
  && tar xzvf smartgears-distribution-bundle-{{ smartgears_version }}.tar.gz \ #--strip-components=1 \
  && rm smartgears-distribution-bundle-{{ smartgears_version }}.tar.gz \
  && cd smartgears-distribution-bundle-{{ smartgears_version }} \
  && echo 1 | /bin/bash ./setup.sh -n {{ hostname }} -f \
  && ln -s $GHN_HOME/SmartGears/container.xml $GHN_HOME/container.xml \
  && sed -ie 's/^$CATALINA_HOME\/bin\/startup.sh/$CATALINA_HOME\/bin\/catalina.sh\ run/' startContainer.sh \
  && sed -ie "s/<container mode='offline'>/<container mode='{{ container_mode }}'>/" container.xml \
  && sed -ie "s/<infrastructure>gcube<\/infrastructure>/<infrastructure>{{ infrastructure }}<\/infrastructure>/" container.xml \
  && sed -ie "/<\/infrastructure>/a \        <token>{{ token }}</token>" container.xml

EXPOSE 8080

CMD /SmartGears-Bundle/startContainer.sh