FROM jboss/wildfly:14.0.1.Final

# User root user to install software
USER root
RUN yum -y install expect
RUN yum -y install postgresql
RUN yum -y install ant

# Compile and copy .ear to deployments
ADD ./1.sources/  /opt/jboss/
RUN cd /opt/jboss/MyHealth && ant
RUN mv /opt/jboss/MyHealth/dist/MyHealth.ear /opt/jboss/wildfly/standalone/deployments

# Switch back to jboss user
USER jboss

ADD ./4.config/createApplicationUser.sh /opt/jboss/wildfly/bin/
ADD ./4.config/createManagementUser.sh /opt/jboss/wildfly/bin/

RUN cd /opt/jboss/wildfly/bin && ./createApplicationUser.sh 
RUN cd /opt/jboss/wildfly/bin && ./createManagementUser.sh

RUN mkdir /opt/jboss/wildfly/modules/system/layers/base/org/postgresql/
RUN mkdir /opt/jboss/wildfly/modules/system/layers/base/org/postgresql/main
ADD ./4.config/postgresql-9.4.1209.jar /opt/jboss/wildfly/modules/system/layers/base/org/postgresql/main
ADD ./4.config/module.xml /opt/jboss/wildfly/modules/system/layers/base/org/postgresql/main
ADD ./4.config/standalone.xml /opt/jboss/wildfly/standalone/configuration/standalone.xml

CMD ["/opt/jboss/wildfly/bin/standalone.sh", "-b", "0.0.0.0", "-bmanagement", "0.0.0.0"]