# 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 rhpam-7/rhpam73-smartrouter-openshift:1.1 image.

FROM rhel7:7-released

USER root


# Install required RPMs and ensure that the packages were installed
RUN yum install -y yum-utils unzip tar rsync java-1.8.0-openjdk-devel \
    && yum clean all && rm -rf /var/cache/yum \
    && rpm -q yum-utils unzip tar rsync java-1.8.0-openjdk-devel


# Add all artifacts to the /tmp/artifacts
# directory
COPY \
    artifacts/add_ons_distribution.zip \
    /tmp/artifacts/


# Environment variables
ENV \
    ADD_ONS_DISTRIBUTION_ZIP="add_ons_distribution.zip" \
    HOME="/home/jboss" \
    JAVA_HOME="/usr/lib/jvm/java-1.8.0" \
    JAVA_VENDOR="openjdk" \
    JAVA_VERSION="1.8.0" \
    JBOSS_CONTAINER_JAVA_JVM_MODULE="/opt/jboss/container/java/jvm" \
    JBOSS_CONTAINER_JAVA_PROXY_MODULE="/opt/jboss/container/java/proxy" \
    JBOSS_CONTAINER_OPENJDK_JDK_MODULE="/opt/jboss/container/openjdk/jdk" \
    JBOSS_CONTAINER_UTIL_LOGGING_MODULE="/opt/jboss/container/util/logging/" \
    JBOSS_IMAGE_NAME="rhpam-7/rhpam73-smartrouter-openshift" \
    JBOSS_IMAGE_VERSION="1.1" \
    JBOSS_PRODUCT="rhpam-smartrouter" \
    KIE_ROUTER_DISTRIBUTION_JAR="rhpam-7.3-smart-router.jar" \
    KIE_SERVER_ROUTER_PORT_TLS="9443" \
    LAUNCH_DIR="/opt/rhpam-smartrouter/launch" \
    PRODUCT_VERSION="7.3.1" \
    RHPAM_SMARTROUTER_VERSION="7.3.1" 

# Labels
LABEL \
      com.redhat.component="rhpam-7-rhpam73-smartrouter-openshift-container"  \
      description="Red Hat Process Automation Manager Smart Router 7.3 container image"  \
      io.cekit.version="2.2.7"  \
      io.k8s.description="Platform for running Red Hat Process Automation Manager Smart Router"  \
      io.k8s.display-name="Red Hat Process Automation Manager Smart Router 7.3"  \
      io.openshift.expose-services="9000:http"  \
      io.openshift.tags="javaee,rhpam,rhpam7"  \
      name="rhpam-7/rhpam73-smartrouter-openshift"  \
      org.concrt.version="2.2.7"  \
      org.jboss.product="rhpam-smartrouter"  \
      org.jboss.product.openjdk.version="1.8.0"  \
      org.jboss.product.rhpam-smartrouter.version="7.3.1"  \
      org.jboss.product.version="7.3.1"  \
      summary="Red Hat Process Automation Manager Smart Router 7.3 container image"  \
      version="1.1" 

# Exposed ports
EXPOSE 9000
# 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/rhpam-7-smartrouter/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.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-kie-smartrouter/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/rhpam-smartrouter/openshift-launch.sh"]

