# Copyright 2019 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 amq-broker-7/amq-broker-78:7.8 image.


## START target image amq-broker-7/amq-broker-78:7.8
## \
    FROM ubi8:8.4-211

    USER root

###### START module 'jboss.container.user:1.0'
###### \
        # Copy 'jboss.container.user' module content
        COPY modules/jboss.container.user /tmp/scripts/jboss.container.user
        # Switch to 'root' user to install 'jboss.container.user' module defined packages
        USER root
        # Install packages defined in the 'jboss.container.user' module
        RUN yum --setopt=tsflags=nodocs install -y unzip tar rsync shadow-utils \
            && rpm -q unzip tar rsync shadow-utils
        # Set 'jboss.container.user' module defined environment variables
        ENV \
            HOME="/home/jboss" 
        # Custom scripts from 'jboss.container.user' module
        USER root
        RUN [ "bash", "-x", "/tmp/scripts/jboss.container.user/configure.sh" ]
###### /
###### END module 'jboss.container.user:1.0'

###### START module 'jboss.container.openjdk.jdk:8'
###### \
        # Copy 'jboss.container.openjdk.jdk' module content
        COPY modules/jboss.container.openjdk.jdk /tmp/scripts/jboss.container.openjdk.jdk
        # Switch to 'root' user to install 'jboss.container.openjdk.jdk' module defined packages
        USER root
        # Install packages defined in the 'jboss.container.openjdk.jdk' module
        RUN yum --setopt=tsflags=nodocs install -y java-1.8.0-openjdk-devel \
            && rpm -q java-1.8.0-openjdk-devel
        # Set 'jboss.container.openjdk.jdk' module defined environment variables
        ENV \
            JAVA_HOME="/usr/lib/jvm/java-1.8.0" \
            JAVA_VENDOR="openjdk" \
            JAVA_VERSION="1.8.0" \
            JBOSS_CONTAINER_OPENJDK_JDK_MODULE="/opt/jboss/container/openjdk/jdk" 
        # Set 'jboss.container.openjdk.jdk' module defined labels
        LABEL \
            org.jboss.product="openjdk"  \
            org.jboss.product.openjdk.version="1.8.0"  \
            org.jboss.product.version="1.8.0" 
        # Custom scripts from 'jboss.container.openjdk.jdk' module
        USER root
        RUN [ "bash", "-x", "/tmp/scripts/jboss.container.openjdk.jdk/configure.sh" ]
###### /
###### END module 'jboss.container.openjdk.jdk:8'

###### START module 'amq.broker78.install:1.3'
###### \
        # Copy 'amq.broker78.install' module general artifacts
        COPY \
            artifacts/amq-broker-7.8.3-bin.zip \
            /tmp/artifacts/
        # Copy 'amq.broker78.install' module content
        COPY modules/amq.broker78.install /tmp/scripts/amq.broker78.install
        # Custom scripts from 'amq.broker78.install' module
        USER root
        RUN [ "bash", "-x", "/tmp/scripts/amq.broker78.install/install.sh" ]
###### /
###### END module 'amq.broker78.install:1.3'

###### START module 'amq.broker78.chown:1'
###### \
        # Copy 'amq.broker78.chown' module content
        COPY modules/amq.broker78.chown /tmp/scripts/amq.broker78.chown
        # Custom scripts from 'amq.broker78.chown' module
        USER root
        RUN [ "bash", "-x", "/tmp/scripts/amq.broker78.chown/install.sh" ]
###### /
###### END module 'amq.broker78.chown:1'

###### START image 'amq-broker-7/amq-broker-78:7.8'
###### \
        # Switch to 'root' user to install 'amq-broker-7/amq-broker-78' image defined packages
        USER root
        # Install packages defined in the 'amq-broker-7/amq-broker-78' image
        RUN yum --setopt=tsflags=nodocs install -y hostname libaio python2 \
            && rpm -q hostname libaio python2
        # Set 'amq-broker-7/amq-broker-78' image defined environment variables
        ENV \
            AMQ_CLUSTER_PASSWORD="cluster_password" \
            AMQ_CLUSTER_USER="cluster_user" \
            AMQ_CLUSTERED="false" \
            AMQ_HOME="/opt/amq" \
            AMQ_NAME="broker" \
            AMQ_RESET_CONFIG="false" \
            AMQ_ROLE="admin" \
            JBOSS_AMQ_VERSION="7.8.3" \
            JBOSS_IMAGE_NAME="amq-broker-7/amq-broker-78-rhel8" \
            JBOSS_IMAGE_VERSION="7.8" \
            JBOSS_PRODUCT="AMQ" \
            PRODUCT_VERSION="7.8.3" 
        # Set 'amq-broker-7/amq-broker-78' image defined labels
        LABEL \
            com.redhat.component="amq-broker-rhel8-container"  \
            description="Red Hat AMQ 7.8.3 container image"  \
            io.cekit.version="3.5.0"  \
            io.k8s.display-name="Red Hat AMQ Broker 7.8.3"  \
            maintainer="rkieley@redhat.com"  \
            name="amq-broker-7/amq-broker-78-rhel8"  \
            org.jboss.product="amq"  \
            org.jboss.product.amq.version="7.8.3"  \
            org.jboss.product.version="7.8.3"  \
            summary="Red Hat AMQ 7.8.3 container image"  \
            version="7.8" 
###### /
###### END image 'amq-broker-7/amq-broker-78:7.8'


    # Switch to 'root' user and remove artifacts and modules
    USER root
    RUN [ ! -d /tmp/scripts ] || rm -rf /tmp/scripts
    RUN [ ! -d /tmp/artifacts ] || rm -rf /tmp/artifacts

    # Clear package manager metadata
    RUN yum clean all && [ ! -d /var/cache/yum ] || rm -rf /var/cache/yum

    # Define the user
    USER 185
    # Define the working directory
    WORKDIR /home/jboss
    # Define run cmd
    CMD ["/opt/amq/bin/launch.sh"]
## /
## END target image
