# 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-decisioncentral-indexing-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 hostname \
    && yum clean all && rm -rf /var/cache/yum \
    && rpm -q yum-utils unzip tar rsync java-1.8.0-openjdk-devel hostname


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


# Environment variables
ENV \
    ELASTICSEARCH_DISTRIBUTION_ZIP="elasticsearch_distribution.zip" \
    ELASTICSEARCH_HOME="/opt/elasticsearch" \
    ELASTICSEARCH_VERSION="5.6.5" \
    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_IMAGE_NAME="rhdm-7-tech-preview/rhdm73-decisioncentral-indexing-openshift" \
    JBOSS_IMAGE_VERSION="1.1" \
    JBOSS_PRODUCT="rhdm-decisioncentral-indexing" \
    PRODUCT_VERSION="7.3.1" \
    RHDM_BUSINESS_CENTRAL_INDEXING_VERSION="7.3.1" 

# Labels
LABEL \
      com.redhat.component="rhdm-7-rhdm73-decisioncentral-indexing-openshift-container"  \
      description="Red Hat Decision Central Indexing 7.3 OpenShift container image"  \
      elasticsearch.version="5.6.5"  \
      io.cekit.version="2.2.7"  \
      io.k8s.description="Platform for running Red Hat Decision Central Indexing"  \
      io.k8s.display-name="Red Hat Decision Central Indexing 7.3"  \
      io.openshift.expose-services="9200:http,9300:tcp"  \
      io.openshift.tags="javaee,rhdm,rhdm7"  \
      name="rhdm-7-tech-preview/rhdm73-decisioncentral-indexing-openshift"  \
      org.concrt.version="2.2.7"  \
      org.jboss.product="rhdm-decisioncentral-indexing"  \
      org.jboss.product.openjdk.version="1.8.0"  \
      org.jboss.product.rhdm-decisioncentral-indexing.version="7.3.1"  \
      org.jboss.product.version="7.3.1"  \
      summary="Red Hat Decision Central Indexing 7.3 OpenShift container image"  \
      version="1.1" 

# Exposed ports
EXPOSE 9200 9300
# 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/rhdm-7-decisioncentral-indexing/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-kie-workbench-indexing/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/elasticsearch/bin/openshift-launch.sh"]

