# DO NOT EDIT THIS FILE DIRECTLY
# This file was auto generated from the template file Dockerfile.j2 using the generate.py script

FROM registry.access.redhat.com/ubi9/ubi-minimal:9.4 AS builder

ARG MONGOCXX_VERSION=3.10.1
ARG MONGOC_VERSION=1.27.1
ARG MONGOCRYPT_VERSION=1.10.0

WORKDIR /build

RUN microdnf upgrade -y && microdnf install -y ninja-build gcc g++ git gzip tar wget cmake openssl-devel python3

RUN mkdir -p /opt/mongocxx

RUN wget https://github.com/mongodb/libmongocrypt/archive/refs/tags/${MONGOCRYPT_VERSION}/libmongocrypt-${MONGOCRYPT_VERSION}.tar.gz \
        -O libmongocrypt-${MONGOCRYPT_VERSION}.tar.gz && \
    tar xf libmongocrypt-${MONGOCRYPT_VERSION}.tar.gz && \
    cmake \
        -S libmongocrypt-${MONGOCRYPT_VERSION} \
        -B mongocrypt-build \
        -G "Ninja Multi-Config" \
        -DBUILD_VERSION=${MONGOCRYPT_VERSION} \
        -DCMAKE_BUILD_TYPE=RelWithDebInfo \
        -DCMAKE_INSTALL_PREFIX=/opt/mongocxx \
        && \
    cmake --build mongocrypt-build --config RelWithDebInfo && \
    cmake --install mongocrypt-build --config RelWithDebInfo --prefix /opt/mongocxx

RUN wget https://github.com/mongodb/mongo-c-driver/archive/refs/tags/${MONGOC_VERSION}/mongo-c-driver-${MONGOC_VERSION}.tar.gz \
        -O mongo-c-driver-${MONGOC_VERSION}.tar.gz && \
    tar xf mongo-c-driver-${MONGOC_VERSION}.tar.gz && \
    cmake \
        -S mongo-c-driver-${MONGOC_VERSION} \
        -B mongoc-build \
        -G "Ninja Multi-Config" \
        -DBUILD_VERSION=${MONGOC_VERSION} \
        -DCMAKE_BUILD_TYPE=RelWithDebInfo \
        -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF \
        -DMONGOC_ENABLE_CLIENT_SIDE_ENCRYPTION=ON \
        -DCMAKE_INSTALL_PREFIX=/opt/mongocxx \
        -DCMAKE_PREFIX_PATH=/opt/mongocxx \
        && \
    cmake --build mongoc-build --config RelWithDebInfo && \
    cmake --install mongoc-build --config RelWithDebInfo --prefix /opt/mongocxx

RUN wget https://github.com/mongodb/mongo-cxx-driver/archive/refs/tags/r${MONGOCXX_VERSION}/mongo-cxx-driver-${MONGOCXX_VERSION}.tar.gz \
        -O mongo-cxx-driver-${MONGOCXX_VERSION}.tar.gz && \
    tar xf mongo-cxx-driver-${MONGOCXX_VERSION}.tar.gz && \
    cmake \
        -S mongo-cxx-driver-r${MONGOCXX_VERSION} \
        -B mongocxx-build \
        -G "Ninja Multi-Config" \
        -DBUILD_VERSION=${MONGOCXX_VERSION} \
        -DCMAKE_BUILD_TYPE=RelWithDebInfo \
        -DCMAKE_CXX_STANDARD=17 \
        -DCMAKE_INSTALL_PREFIX=/opt/mongocxx \
        -DCMAKE_PREFIX_PATH=/opt/mongocxx \
        && \
    cmake --build mongocxx-build --config RelWithDebInfo && \
    cmake --install mongocxx-build --config RelWithDebInfo --prefix /opt/mongocxx

FROM registry.access.redhat.com/ubi9/ubi-minimal:9.4

RUN microdnf upgrade -y && microdnf install -y openssl

COPY --from=builder /opt/mongocxx /usr/local

RUN ldconfig

ENV LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/local/lib64/"
