# Copyright 2017 Red Hat
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# ------------------------------------------------------------------------
#
# This is a Dockerfile for the rhdm-7-tech-preview/rhdm73-optaweb-employee-rostering-openshift:1.1 image.

FROM rhel7:7-released

USER root


# Install required RPMs and ensure that the packages were installed
RUN yum install -y java-1.8.0-openjdk-devel rh-maven35 rh-mongodb32-mongo-java-driver postgresql-jdbc mysql-connector-java yum-utils unzip tar rsync python-requests python-enum34 PyYAML hostname \
    && yum clean all && rm -rf /var/cache/yum \
    && rpm -q java-1.8.0-openjdk-devel rh-maven35 rh-mongodb32-mongo-java-driver postgresql-jdbc mysql-connector-java yum-utils unzip tar rsync python-requests python-enum34 PyYAML hostname


# Add all artifacts to the /tmp/artifacts
# directory
COPY \
    jboss-eap-7.2.zip \
    artifacts/add_ons_distribution.zip \
    jolokia-jvm-1.5.0.redhat-1-agent.jar \
    txn-recovery-marker-jdbc-common-1.1.2.Final-redhat-00001.jar \
    txn-recovery-marker-jdbc-hibernate5-1.1.2.Final-redhat-00001.jar \
    openshift-ping-common-1.2.3.Final-redhat-1.jar \
    openshift-ping-dns-1.2.3.Final-redhat-1.jar \
    openshift-ping-kube-1.2.3.Final-redhat-1.jar \
    oauth-20100527.jar \
    activemq-rar-5.11.0.redhat-630371.rar \
    rh-sso-7.2.2-eap7-adapter.zip \
    rh-sso-7.2.2-saml-eap7-adapter.zip \
    hawkular-javaagent-1.0.1.Final-redhat-2-shaded.jar \
    jmx_prometheus_javaagent-0.3.1.redhat-00006.jar \
    /tmp/artifacts/


# Environment variables
ENV \
    AB_JOLOKIA_AUTH_OPENSHIFT="true" \
    AB_JOLOKIA_HTTPS="true" \
    AB_JOLOKIA_PASSWORD_RANDOM="true" \
    AB_PROMETHEUS_JMX_EXPORTER_CONFIG="/opt/jboss/container/prometheus/etc/jmx-exporter-config.yaml" \
    AB_PROMETHEUS_JMX_EXPORTER_PORT="9799" \
    ADD_ONS_DISTRIBUTION_ZIP="add_ons_distribution.zip" \
    DEFAULT_ADMIN_USERNAME="eapadmin" \
    EMPLOYEE_ROSTERING_DISTRIBUTION_WAR="employee-rostering-distribution-7.18.0.Final-redhat-00004/binaries/employee-rostering-webapp-7.18.0.Final-redhat-00004.war" \
    EMPLOYEE_ROSTERING_DISTRIBUTION_ZIP="rhdm-7.3-employee-rostering.zip" \
    HOME="/home/jboss" \
    HTTPS_ENABLE_HTTP2="true" \
    JAVA_HOME="/usr/lib/jvm/java-1.8.0" \
    JAVA_VENDOR="openjdk" \
    JAVA_VERSION="1.8.0" \
    JBOSS_CONTAINER_HAWKULAR_MODULE="/opt/jboss/container/hawkular" \
    JBOSS_CONTAINER_JAVA_JVM_MODULE="/opt/jboss/container/java/jvm" \
    JBOSS_CONTAINER_JAVA_PROXY_MODULE="/opt/jboss/container/java/proxy" \
    JBOSS_CONTAINER_JOLOKIA_MODULE="/opt/jboss/container/jolokia" \
    JBOSS_CONTAINER_MAVEN_35_MODULE="/opt/jboss/container/maven/35/" \
    JBOSS_CONTAINER_MAVEN_DEFAULT_MODULE="/opt/jboss/container/maven/default/" \
    JBOSS_CONTAINER_OPENJDK_JDK_MODULE="/opt/jboss/container/openjdk/jdk" \
    JBOSS_CONTAINER_PROMETHEUS_MODULE="/opt/jboss/container/prometheus" \
    JBOSS_CONTAINER_UTIL_LOGGING_MODULE="/opt/jboss/container/util/logging/" \
    JBOSS_EAP_VERSION="7.2.0.GA" \
    JBOSS_HOME="/opt/eap" \
    JBOSS_IMAGE_NAME="rhdm-7-tech-preview/rhdm73-optaweb-employee-rostering-openshift" \
    JBOSS_IMAGE_VERSION="1.1" \
    JBOSS_MODULES_SYSTEM_PKGS="org.jboss.logmanager,jdk.nashorn.api" \
    JBOSS_PRODUCT="rhdm-optaweb-employee-rostering" \
    JBOSS_RHDM_OPTAWEB_EMPLOYEE_ROSTERING_VERSION="7.3.1" \
    JOLOKIA_VERSION="1.5.0" \
    LAUNCH_JBOSS_IN_BACKGROUND="true" \
    MAVEN_VERSION="3.5" \
    MICROPROFILE_CONFIG_DIR_ORDINAL="500" \
    PRODUCT_VERSION="7.3.1" 

# Labels
LABEL \
      com.redhat.component="rhdm-7-rhdm73-optaweb-employee-rostering-openshift-container"  \
      com.redhat.deployments-dir="/opt/eap/standalone/deployments"  \
      com.redhat.dev-mode="DEBUG:true"  \
      com.redhat.dev-mode.port="DEBUG_PORT:8787"  \
      description="Red Hat Business Optimizer OptaWeb Employee Rostering 7.3 OpenShift container image"  \
      io.cekit.version="2.2.7"  \
      io.fabric8.s2i.version.jolokia="1.5.0-redhat-1"  \
      io.fabric8.s2i.version.maven="3.5"  \
      io.k8s.description="Platform for running Red Hat Business Optimizer OptaWeb Employee Rostering"  \
      io.k8s.display-name="Red Hat Business Optimizer OptaWeb Employee Rostering 7.3"  \
      io.openshift.expose-services="8080:http,8443:https"  \
      io.openshift.tags="builder,javaee,eap,eap7,rhdm,rhdm7"  \
      name="rhdm-7-tech-preview/rhdm73-optaweb-employee-rostering-openshift"  \
      org.concrt.version="2.2.7"  \
      org.jboss.product="rhdm-optaweb-employee-rostering"  \
      org.jboss.product.eap.version="7.2.0.GA"  \
      org.jboss.product.openjdk.version="1.8.0"  \
      org.jboss.product.rhdm-optaweb-employee-rostering.version="7.3.1"  \
      org.jboss.product.version="7.3.1"  \
      summary="Red Hat Business Optimizer OptaWeb Employee Rostering 7.3 OpenShift container image"  \
      version="1.1" 

# Exposed ports
EXPOSE 8080 8778 8443
# Add scripts used to configure the image
COPY modules /tmp/scripts

# Custom scripts
USER root
RUN [ "bash", "-x", "/tmp/scripts/jboss.container.user/configure.sh" ]

USER root
RUN [ "bash", "-x", "/tmp/scripts/jboss.container.openjdk.jdk/configure.sh" ]

USER root
RUN [ "bash", "-x", "/tmp/scripts/eap-7.2.0/install.sh" ]

USER root
RUN [ "bash", "-x", "/tmp/scripts/eap-install-cleanup/install.sh" ]

USER root
RUN [ "bash", "-x", "/tmp/scripts/rhdm-7-optaweb-employee-rostering/install" ]

USER root
RUN [ "bash", "-x", "/tmp/scripts/jboss.container.java.proxy.bash/configure.sh" ]

USER root
RUN [ "bash", "-x", "/tmp/scripts/jboss.container.java.proxy.bash/backward_compatibility.sh" ]

USER root
RUN [ "bash", "-x", "/tmp/scripts/jboss.container.java.jvm.bash/configure.sh" ]

USER root
RUN [ "bash", "-x", "/tmp/scripts/jboss.container.java.jvm.bash/backward_compatibility.sh" ]

USER root
RUN [ "bash", "-x", "/tmp/scripts/dynamic-resources/install.sh" ]

USER root
RUN [ "bash", "-x", "/tmp/scripts/java-alternatives/run.sh" ]

USER root
RUN [ "bash", "-x", "/tmp/scripts/jboss.container.jolokia.bash/configure.sh" ]

USER root
RUN [ "bash", "-x", "/tmp/scripts/jboss.container.jolokia.bash/backward_compatibility.sh" ]

USER 185
RUN [ "bash", "-x", "/tmp/scripts/jboss.eap.cd.jolokia/configure.sh" ]

USER root
RUN [ "bash", "-x", "/tmp/scripts/os-eap7-openshift/prepare.sh" ]

USER 185
RUN [ "bash", "-x", "/tmp/scripts/os-eap7-openshift/configure.sh" ]

USER 185
RUN [ "bash", "-x", "/tmp/scripts/jboss.eap72.openshift/configure.sh" ]

USER 185
RUN [ "bash", "-x", "/tmp/scripts/jboss.eap.cd.openshift.modules/configure.sh" ]

USER 185
RUN [ "bash", "-x", "/tmp/scripts/os-eap7-ping/configure.sh" ]

USER 185
RUN [ "bash", "-x", "/tmp/scripts/os-eap-activemq-rar/configure.sh" ]

USER 185
RUN [ "bash", "-x", "/tmp/scripts/os-eap-launch/configure.sh" ]

USER 185
RUN [ "bash", "-x", "/tmp/scripts/os-eap-node-name/configure.sh" ]

USER root
RUN [ "bash", "-x", "/tmp/scripts/os-eap-txnrecovery/install_as_root.sh" ]

USER 185
RUN [ "bash", "-x", "/tmp/scripts/os-eap-migration/configure.sh" ]

USER 185
RUN [ "bash", "-x", "/tmp/scripts/os-eap7-launch/configure.sh" ]

USER 185
RUN [ "bash", "-x", "/tmp/scripts/jboss.eap.cd.openshift.launch/configure.sh" ]

USER 185
RUN [ "bash", "-x", "/tmp/scripts/jboss.eap.cd.logging/configure.sh" ]

USER 185
RUN [ "bash", "-x", "/tmp/scripts/jboss.eap.config.mp-config/configure.sh" ]

USER 185
RUN [ "bash", "-x", "/tmp/scripts/jboss.eap.config.jgroups/configure.sh" ]

USER 185
RUN [ "bash", "-x", "/tmp/scripts/jboss.eap.config.elytron/configure.sh" ]

USER 185
RUN [ "bash", "-x", "/tmp/scripts/jboss.eap.config.tracing/configure.sh" ]

USER 185
RUN [ "bash", "-x", "/tmp/scripts/os-eap-probes/configure.sh" ]

USER root
RUN [ "bash", "-x", "/tmp/scripts/jboss.container.maven.35.bash/configure.sh" ]

USER root
RUN [ "bash", "-x", "/tmp/scripts/jboss.container.util.logging.bash/configure.sh" ]

USER root
RUN [ "bash", "-x", "/tmp/scripts/jboss.container.util.logging.bash/backward_compatibility.sh" ]

USER root
RUN [ "bash", "-x", "/tmp/scripts/jboss.container.maven.default.bash/configure.sh" ]

USER root
RUN [ "bash", "-x", "/tmp/scripts/jboss.container.maven.default.bash/backward_compatibility.sh" ]

USER 185
RUN [ "bash", "-x", "/tmp/scripts/os-eap-db-drivers/configure.sh" ]

USER 185
RUN [ "bash", "-x", "/tmp/scripts/os-eap-sso/configure.sh" ]

USER 185
RUN [ "bash", "-x", "/tmp/scripts/os-eap70-sso/configure.sh" ]

USER root
RUN [ "bash", "-x", "/tmp/scripts/jboss.container.hawkular.bash/configure.sh" ]

USER root
RUN [ "bash", "-x", "/tmp/scripts/jboss.container.hawkular.bash/backward_compatibility.sh" ]

USER root
RUN [ "bash", "-x", "/tmp/scripts/os-eap70-hawkular/install_as_root" ]

USER 185
RUN [ "bash", "-x", "/tmp/scripts/os-eap-hawkular/configure.sh" ]

USER 185
RUN [ "bash", "-x", "/tmp/scripts/os-eap-deployment-scanner/configure.sh" ]

USER 185
RUN [ "bash", "-x", "/tmp/scripts/os-eap-extensions/configure.sh" ]

USER 185
RUN [ "bash", "-x", "/tmp/scripts/openshift-layer/configure_layers.sh" ]

USER root
RUN [ "bash", "-x", "/tmp/scripts/jboss.container.prometheus.bash/configure.sh" ]

USER 185
RUN [ "bash", "-x", "/tmp/scripts/jboss.container.eap.prometheus.agent/configure.sh" ]

USER root
RUN [ "bash", "-x", "/tmp/scripts/jboss.container.eap.prometheus.config/configure.sh" ]

USER root
RUN [ "bash", "-x", "/tmp/scripts/jboss-kie-wildfly-common/configure.sh" ]

USER root
RUN [ "bash", "-x", "/tmp/scripts/jboss-kie-optaweb-common/configure.sh" ]

USER root
RUN [ "bash", "-x", "/tmp/scripts/jboss-kie-optaweb-employeerostering/configure.sh" ]

USER root
RUN rm -rf /tmp/scripts
USER root
RUN rm -rf /tmp/artifacts

USER 185

# Specify the working directory
WORKDIR /home/jboss


CMD ["/opt/eap/bin/openshift-launch.sh"]

