#/*
# * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
# * contributor license agreements.  See the NOTICE file distributed with
# * this work for additional information regarding copyright ownership.
# * The OpenAirInterface Software Alliance licenses this file to You under
# * the OAI Public License, Version 1.1  (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.openairinterface.org/?page_id=698
# *
# * 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.
# *-------------------------------------------------------------------------------
# * For more information about the OpenAirInterface (OAI) Software Alliance:
# *      contact@openairinterface.org
# */
#---------------------------------------------------------------------
#
# Dockerfile for the Open-Air-Interface BUILD service
#   Valid for Ubuntu24.04
#
#---------------------------------------------------------------------

FROM ran-base:latest AS gnb-base

FROM ran-build:latest AS gnb-build


FROM ubuntu:noble AS oai-nr-cuup
ARG BUILD_OPTION
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=Europe

RUN apt-get update && \
    apt-get upgrade --yes && \
    apt-get install --yes \
        libsctp1 \
        libconfig9 \
        iproute2 \
        net-tools \
        openssl && \
# if the --sanitize option was used to build, additional packages are required
    /bin/bash -c 'if [[ "$BUILD_OPTION" = "--sanitize" ]]; then DEBIAN_FRONTEND=noninteractive apt-get install --yes \
        libasan8 \ 
        libubsan1 \
        liblapacke; fi' && \
    rm -rf /var/lib/apt/lists/*

## Copy E2 SM models
COPY --from=gnb-build /usr/local/lib/flexric /usr/local/lib/flexric

WORKDIR /opt/oai-gnb/bin
COPY --from=gnb-build \
    /oai-ran/cmake_targets/ran_build/build/nr-cuup \
    ./
COPY ./docker/scripts/gnb_entrypoint.sh ./entrypoint.sh
COPY --from=gnb-build \
    /oai-ran/cmake_targets/ran_build/build/libparams_libconfig.so \
    /oai-ran/cmake_targets/ran_build/build/libtelnetsrv.so \
    /usr/local/lib/

RUN ldconfig && ldd /opt/oai-gnb/bin/nr-cuup

# Create directory for configuration files
WORKDIR /opt/oai-gnb/etc

WORKDIR /opt/oai-gnb
COPY --from=gnb-base /tini /tini
ENTRYPOINT ["/tini", "-v", "--", "/opt/oai-gnb/bin/entrypoint.sh"]
CMD ["/opt/oai-gnb/bin/nr-cuup", "-O", "/opt/oai-gnb/etc/gnb.conf"]
