FROM quay.io/almalinuxorg/almalinux:8 as builder

ENV DEPS_HOME ${HOME}/deps
ENV MONGOC_HOME /usr

RUN mkdir -p ${DEPS_HOME}

RUN dnf -y update && \
    #Cunit comes from the powertools repo (need to install plugins-core for the config manager)
    dnf -y install dnf-plugins-core && yum config-manager --set-enabled powertools && \
    #Ant, junit etc come from the javapackages-tools module
    dnf -y module enable javapackages-tools && \
    # Install system tools and build dependencies required to build all releases of MessageGateway/MSProxy
    dnf -y install --nobest gcc gcc-c++ make cmake3 CUnit CUnit-devel junit ant ant-apache-xalan2 ant-junit ant-contrib libxslt && \
    # Install library dependencies (1/2)
    dnf -y install openssl-devel curl-devel openldap-devel net-snmp-devel libicu-devel icu boost-devel && \
    # Install library dependencies (1/2)
    dnf -y install jansson jansson-devel pam-devel curl-devel && \
    # Install some tools which developers find useful during basic testing
    dnf -y install less wget vim-enhanced dos2unix bc gdb net-tools openssh-clients bzip2 unzip zip && \
    dnf -y install man file which lsof strace python3-devel python3-pip nodejs npm valgrind nc nmap logrotate && \
    # Needed to build rpms in container
    dnf -y install rpm-build && \
    # Needed to build the proxy
    dnf -y install epel-release && \
    dnf -y install mongo-c-driver-devel && \
    # Needed for verifying python stuff
    pip3 install pylint requests

#Get the dependencies we need that aren't packaged (JMS and java treated separately)
RUN wget https://github.com/d3/d3/releases/download/v3.5.6/d3.zip -O ${DEPS_HOME}/d3-3.5.6.zip && \
    wget https://public.dhe.ibm.com/ibmdl/export/pub/software/openliberty/runtime/release/23.0.0.12/openliberty-23.0.0.12.zip -P ${DEPS_HOME} && \
    wget https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-annotations/2.16.0/jackson-annotations-2.16.0.jar -P ${DEPS_HOME} && \
    wget https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-core/2.16.0/jackson-core-2.16.0.jar -P ${DEPS_HOME} && \
    wget https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-databind/2.16.0/jackson-databind-2.16.0.jar -P ${DEPS_HOME} && \
    wget https://repo1.maven.org/maven2/com/fasterxml/jackson/jaxrs/jackson-jaxrs-base/2.16.0/jackson-jaxrs-base-2.16.0.jar -P ${DEPS_HOME} && \
    wget https://repo1.maven.org/maven2/com/fasterxml/jackson/jaxrs/jackson-jaxrs-json-provider/2.16.0/jackson-jaxrs-json-provider-2.16.0.jar -P ${DEPS_HOME} && \
    wget https://repo1.maven.org/maven2/com/fasterxml/jackson/module/jackson-module-jaxb-annotations/2.16.0/jackson-module-jaxb-annotations-2.16.0.jar -P ${DEPS_HOME} && \
    wget https://download.dojotoolkit.org/release-1.17.3/dojo-release-1.17.3-src.zip -O ${DEPS_HOME}/dojo-release-1.17.3-src.zip && \
    wget https://github.com/oria/gridx/archive/refs/tags/v1.3.9.zip -O ${DEPS_HOME}/gridx-1.3.9.zip && \
    wget https://github.com/unicode-org/icu/releases/download/release-74-1/icu4j-74.1.jar -P ${DEPS_HOME}
    
#Get the JMS jars (separate as need to consider whether these are right locations/jars to grab - consider fscontext.jar/providerutil.jar)
RUN wget https://repo1.maven.org/maven2/org/apache/geronimo/specs/geronimo-jms_1.1_spec/1.1.1/geronimo-jms_1.1_spec-1.1.1.jar  -O ${DEPS_HOME}/jms.jar 

#Get the operator-sdk that is required for building the operator images
RUN export ARCH=$(case $(uname -m) in x86_64) echo -n amd64 ;; aarch64) echo -n arm64 ;; *) echo -n $(uname -m) ;; esac) && \
    export OS=$(uname | awk '{print tolower($0)}') && \
    export OPERATOR_SDK_DL_URL=https://github.com/operator-framework/operator-sdk/releases/download/v1.22.0 && \
    curl -LO ${OPERATOR_SDK_DL_URL}/operator-sdk_${OS}_${ARCH} && \
    chmod +x operator-sdk_${OS}_${ARCH} && mv operator-sdk_${OS}_${ARCH} /usr/local/bin/operator-sdk

#Get dita which is required for building the documentation
RUN cd /usr/lib/ && \
    wget https://github.com/dita-ot/dita-ot/releases/download/3.7.2/dita-ot-3.7.2.zip && \
    unzip dita-ot-3.7.2.zip && \
    rm dita-ot-3.7.2.zip && \
    ln -s /usr/lib/dita-ot-3.7.2/bin/dita /usr/bin/dita

#Statsd is a little awkward to install, needed for building the proxy
RUN cd /deps && \
    mkdir statsd && \
    wget https://github.com/romanbsd/statsd-c-client/archive/refs/heads/master.zip && \
    unzip master.zip && \
    cd statsd-c-client-master && \
    make && \
    cp libstatsdclient.so /usr/lib64 && \
    cp statsd-client.h /usr/include

