#/*
# * 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 AMF service
#   Valid for Ubuntu-18.04 (bionic)
#
#---------------------------------------------------------------------

#---------------------------------------------------------------------
# BUILDER IMAGE
#---------------------------------------------------------------------
FROM oai-amf-base:latest as oai-amf-builder

# Copying source code
WORKDIR /openair-amf/
COPY . /openair-amf
RUN cp -Rf /openair-amf-ext-ref /openair-amf/build/ext

# Building AMF
WORKDIR /openair-amf/build/scripts
RUN ldconfig && \
    ./build_amf --clean --Verbose --build-type Release --jobs && \
    ldd /openair-amf/build/amf/build/amf && \
    mv /openair-amf/build/amf/build/amf /openair-amf/build/amf/build/oai_amf

#---------------------------------------------------------------------
# TARGET IMAGE
#---------------------------------------------------------------------
FROM ubuntu:bionic as oai-amf
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=Europe/Paris
# We install some debug tools for the moment in addition of mandatory libraries
RUN apt-get update && \
    DEBIAN_FRONTEND=noninteractive apt-get upgrade --yes && \
    DEBIAN_FRONTEND=noninteractive apt-get install --yes \
      tzdata \
      psmisc \
      net-tools \
      bc \
      openssl \
      perl \
      libasan4 \
      libgssapi-krb5-2 \
      libldap-2.4-2 \
      libconfig++9v5 \
      libsctp1 \
  && rm -rf /var/lib/apt/lists/*

# Copying executable and generated libraries
WORKDIR /openair-amf/bin
COPY --from=oai-amf-builder \
    /openair-amf/build/amf/build/oai_amf \
    /openair-amf/scripts/entrypoint.sh \
    ./

WORKDIR /usr/lib/x86_64-linux-gnu
COPY --from=oai-amf-builder \
    /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20 \
    /usr/lib/x86_64-linux-gnu/libsqlite3.so.0 \
    /usr/lib/x86_64-linux-gnu/libcurl-gnutls.so.4 \
    /usr/lib/x86_64-linux-gnu/librtmp.so.1 \
    /usr/lib/x86_64-linux-gnu/libpsl.so.5 \
    ./

WORKDIR /usr/local/lib
COPY --from=oai-amf-builder \
    /usr/local/lib/libnghttp2.so.14 \
    /usr/local/lib/libnghttp2_asio.so.1 \
    /usr/lib/libboost_system.so.1.67.0 \
    /usr/lib/libboost_thread.so.1.67.0 \
    /usr/lib/libboost_chrono.so.1.67.0 \
    /usr/local/lib/libpistache.so \
    ./

RUN ldconfig && \
    ldd /openair-amf/bin/oai_amf

# Copying template configuration files
WORKDIR /openair-amf/etc
COPY --from=oai-amf-builder /openair-amf/etc/amf.conf .

WORKDIR /openair-amf

# expose ports
EXPOSE 80/tcp 9090/tcp 38412/sctp

ENTRYPOINT ["/bin/bash","/openair-amf/bin/entrypoint.sh"]
CMD ["/openair-amf/bin/oai_amf", "-c", "/openair-amf/etc/amf.conf", "-o"]
