diff --git a/ci-scripts/docker/Dockerfile.ci.ubuntu b/ci-scripts/docker/Dockerfile.ci.ubuntu index 668cebe6d13853005c39d99de79d38af90668c91..cc9ca0adc5604260f03e1a70e219ce68f995a05d 100644 --- a/ci-scripts/docker/Dockerfile.ci.ubuntu +++ b/ci-scripts/docker/Dockerfile.ci.ubuntu @@ -55,6 +55,8 @@ ENV TZ=Europe/Paris RUN apt-get update && \ DEBIAN_FRONTEND=noninteractive apt-get upgrade --yes && \ DEBIAN_FRONTEND=noninteractive apt-get install --yes \ + python3 \ + python3-jinja2 \ psmisc \ net-tools \ iputils-ping \ @@ -94,7 +96,7 @@ RUN apt-get update && \ WORKDIR /openair-udm/bin COPY --from=oai-udm-builder \ /openair-udm/build/udm/build/oai_udm \ - /openair-udm/scripts/entrypoint.sh \ + /openair-udm/scripts/entrypoint.py \ /openair-udm/scripts/healthcheck.sh \ ./ @@ -123,5 +125,5 @@ HEALTHCHECK --interval=10s \ --retries=6 \ CMD /openair-udm/bin/healthcheck.sh -ENTRYPOINT ["/bin/bash","/openair-udm/bin/entrypoint.sh"] +ENTRYPOINT ["python3","/openair-udm/bin/entrypoint.py"] CMD ["/openair-udm/bin/oai_udm", "-c" , "/openair-udm/etc/udm.conf", "-o"] diff --git a/ci-scripts/flatten_image.py b/ci-scripts/flatten_image.py index ce57ed0f3ddd4f4e1d9de13ae386b55a5027af6c..fbce59caed6a099e729c2c9de57b7d5748144cf8 100644 --- a/ci-scripts/flatten_image.py +++ b/ci-scripts/flatten_image.py @@ -78,7 +78,7 @@ def perform_flattening(tag): cmd += ' --change "EXPOSE 80/tcp" ' cmd += ' --change "HEALTHCHECK --interval=10s --timeout=15s --retries=6 CMD /openair-udm/bin/healthcheck.sh" ' cmd += ' --change "CMD [\\"/openair-udm/bin/oai_udm\\", \\"-c\\", \\"/openair-udm/etc/udm.conf\\", \\"-o\\"]" ' - cmd += ' --change "ENTRYPOINT [\\"/bin/bash\\", \\"/openair-udm/bin/entrypoint.sh\\"]" ' + cmd += ' --change "ENTRYPOINT [\\"python3\\", \\"/openair-udm/bin/entrypoint.py\\"]" ' cmd += ' - ' + image_prefix + tag print (cmd) subprocess.check_output(cmd, shell=True, universal_newlines=True) diff --git a/docker/Dockerfile.udm.rhel8 b/docker/Dockerfile.udm.rhel8 index 8ca6a3bbdfa53a6601e13c43f7d5344c47bf3b92..48a62279dc6510c0b4b40e7cd482ccab2d100baa 100644 --- a/docker/Dockerfile.udm.rhel8 +++ b/docker/Dockerfile.udm.rhel8 @@ -90,6 +90,8 @@ COPY ./rhsm-ca /etc/rhsm/ca RUN rm -f /etc/rhsm-host && \ microdnf update -y && \ microdnf install -y \ + python3 \ + python3-pip \ tzdata \ # libasan \ procps-ng \ @@ -100,6 +102,7 @@ RUN rm -f /etc/rhsm-host && \ libevent \ findutils \ libconfig && \ + pip3 install jinja2 && \ microdnf clean all -y && \ rm -rf /var/cache/yum /var/cache/dnf && \ # Remove entitlements and Subscription Manager configs @@ -110,7 +113,7 @@ RUN rm -f /etc/rhsm-host && \ WORKDIR /openair-udm/bin COPY --from=oai-udm-builder \ /openair-udm/build/udm/build/oai_udm \ - /openair-udm/scripts/entrypoint.sh \ + /openair-udm/scripts/entrypoint.py \ /openair-udm/scripts/healthcheck.sh \ ./ @@ -137,5 +140,5 @@ HEALTHCHECK --interval=10s \ --retries=6 \ CMD /openair-udm/bin/healthcheck.sh -ENTRYPOINT ["/bin/bash","/openair-udm/bin/entrypoint.sh"] +ENTRYPOINT ["python3","/openair-udm/bin/entrypoint.py"] CMD ["/openair-udm/bin/oai_udm", "-c" , "/openair-udm/etc/udm.conf", "-o"] diff --git a/docker/Dockerfile.udm.ubuntu b/docker/Dockerfile.udm.ubuntu index 32fefe8f876124a8b37c15b80bc1ad6e799863f7..e589a4b16076f97fb342d4693d201df3e04e4728 100644 --- a/docker/Dockerfile.udm.ubuntu +++ b/docker/Dockerfile.udm.ubuntu @@ -78,6 +78,8 @@ ENV TZ=Europe/Paris RUN apt-get update && \ DEBIAN_FRONTEND=noninteractive apt-get upgrade --yes && \ DEBIAN_FRONTEND=noninteractive apt-get install --yes \ + python3 \ + python3-jinja2 \ psmisc \ net-tools \ iputils-ping \ @@ -117,7 +119,7 @@ RUN apt-get update && \ WORKDIR /openair-udm/bin COPY --from=oai-udm-builder \ /openair-udm/build/udm/build/oai_udm \ - /openair-udm/scripts/entrypoint.sh \ + /openair-udm/scripts/entrypoint.py \ /openair-udm/scripts/healthcheck.sh \ ./ @@ -146,5 +148,5 @@ HEALTHCHECK --interval=10s \ --retries=6 \ CMD /openair-udm/bin/healthcheck.sh -ENTRYPOINT ["/bin/bash","/openair-udm/bin/entrypoint.sh"] +ENTRYPOINT ["python3","/openair-udm/bin/entrypoint.py"] CMD ["/openair-udm/bin/oai_udm", "-c" , "/openair-udm/etc/udm.conf", "-o"] diff --git a/etc/udm.conf b/etc/udm.conf index 265c5715632fe35225727996421024f094e9c1e9..bee8babbea9d627c90bfdf3788d29557b42e2ef5 100644 --- a/etc/udm.conf +++ b/etc/udm.conf @@ -1,43 +1,60 @@ ## UDM configuration file UDM = { - INSTANCE_ID = @INSTANCE@; - PID_DIRECTORY = "@PID_DIRECTORY@"; - - UDM_NAME = "@UDM_NAME@"; + INSTANCE_ID = {{ env["INSTANCE"] if "INSTANCE" in env.keys() else 0 }}; + PID_DIRECTORY = "{{ env["PID_DIRECTORY"] if "PID_DIRECTORY" in env.keys() else '/var/run' }}"; + UDM_NAME = "{{ env["UDM_NAME"] }}"; INTERFACES:{ # UDM binded interface for SBI interface (e.g., communication with UDR, AUSF) SBI:{ - INTERFACE_NAME = "@SBI_IF_NAME@"; # YOUR NETWORK CONFIG HERE + INTERFACE_NAME = "{{ env["SBI_IF_NAME"] }}"; IPV4_ADDRESS = "read"; - PORT = @SBI_PORT@; # YOUR NETWORK CONFIG HERE (default: 80) + # YOUR NETWORK CONFIG HERE (default: 80) + PORT = {{ env["SBI_PORT"] if "SBI_PORT" in env.keys() else '80' }}; PPID = 60; - API_VERSION = "@UDM_VERSION_NB@"; - HTTP2_PORT = @SBI_HTTP2_PORT@; # YOUR NETWORK CONFIG HERE + # YOUR NETWORK CONFIG HERE (default: v1) + API_VERSION = "{{ env["UDM_VERSION_NB"] if "UDM_VERSION_NB" in env.keys() else 'v1' }}"; + # YOUR NETWORK CONFIG HERE (default: 8080) + HTTP2_PORT = {{ env["SBI_HTTP2_PORT"] if "SBI_HTTP2_PORT" in env.keys() else '8080' }}; }; }; # SUPPORT FEATURES SUPPORT_FEATURES: { - # STRING, {"yes", "no"}, - USE_FQDN_DNS = "@USE_FQDN_DNS@"; # Set to yes if UDM will relying on a DNS to resolve UDR's FQDN - USE_HTTP2 = "@USE_HTTP2@"; # Set to yes to enable HTTP2 for AUSF server - REGISTER_NRF = "@REGISTER_NRF@"; # Set to 'yes' if UDM resgisters to an NRF - } - + # STRING, {"yes", "no"}, + # Set to yes if UDM will relying on a DNS to resolve UDR's FQDN + USE_FQDN_DNS = "{{ env["USE_FQDN_DNS"] if "USE_FQDN_DNS" in env.keys() else 'no' }}"; + # Set to yes to enable HTTP2 for AUSF server + USE_HTTP2 = "{{ env["USE_HTTP2"] if "USE_HTTP2" in env.keys() else 'no' }}"; + # Set to 'yes' if UDM resgisters to an NRF + REGISTER_NRF = "{{ env["REGISTER_NRF"] if "REGISTER_NRF" in env.keys() else 'no' }}"; + } + UDR:{ - IPV4_ADDRESS = "@UDR_IP_ADDRESS@"; # YOUR NETWORK CONFIG HERE - PORT = @UDR_PORT@; # YOUR NETWORK CONFIG HERE (default: 80) - API_VERSION = "@UDR_VERSION_NB@"; # YOUR API VERSION FOR UDR CONFIG HERE - FQDN = "@UDR_FQDN@" # YOUR UDR FQDN CONFIG HERE + {%- if env["UDR_HOSTNAME"] is defined %} + IPV4_ADDRESS = "{{ resolve(env["UDR_HOSTNAME"]) }}"; + {%- else %} + IPV4_ADDRESS = "{{ env["UDR_IP_ADDRESS"] if "UDR_IP_ADDRESS" in env.keys() else '0.0.0.0' }}"; + {%- endif %} + # YOUR NETWORK CONFIG HERE (default: 80) + PORT = {{ env["UDR_PORT"] if "UDR_PORT" in env.keys() else '80' }}; + # YOUR API VERSION FOR UDR CONFIG HERE (default: v1) + API_VERSION = "{{ env["UDR_VERSION_NB"] if "UDR_VERSION_NB" in env.keys() else 'v1' }}"; + FQDN = "{{ env["UDR_FQDN"] if "UDR_FQDN" in env.keys() else 'localhost' }}" }; - + NRF : { - IPV4_ADDRESS = "@NRF_IPV4_ADDRESS@"; # YOUR NRF CONFIG HERE - PORT = @NRF_PORT@; # YOUR NRF CONFIG HERE (default: 80) - API_VERSION = "@NRF_API_VERSION@"; # YOUR NRF API VERSION HERE - FQDN = "@NRF_FQDN@"; # YOUR NRF FQDN HERE + {%- if env["NRF_HOSTNAME"] is defined %} + IPV4_ADDRESS = "{{ resolve(env["NRF_HOSTNAME"]) }}"; + {%- else %} + IPV4_ADDRESS = "{{ env["NRF_IPV4_ADDRESS"] if "NRF_IPV4_ADDRESS" in env.keys() else '0.0.0.0' }}"; + {%- endif %} + # YOUR NRF CONFIG HERE (default: 80) + PORT = {{ env["NRF_PORT"] if "NRF_PORT" in env.keys() else '80' }}; + # YOUR NRF API VERSION HERE + API_VERSION = "{{ env["NRF_API_VERSION"] if "NRF_API_VERSION" in env.keys() else 'v1' }}"; + FQDN = "{{ env["NRF_FQDN"] if "NRF_FQDN" in env.keys() else 'localhost' }}"; }; -}; \ No newline at end of file +}; diff --git a/scripts/entrypoint.py b/scripts/entrypoint.py new file mode 100755 index 0000000000000000000000000000000000000000..6d6fbfaadc8394465c8b30e3a39bdf33c21e919c --- /dev/null +++ b/scripts/entrypoint.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python3 +################################################################################ +# 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 +################################################################################ + +from jinja2 import Environment, FileSystemLoader +import socket +import os +import sys + +CONFIG_FILE = str(os.getenv('CONFIG_FILE','/openair-udm/etc/udm.conf')) +MOUNT_CONFIG = str(os.getenv('MOUNT_CONFIG','no')).lower() + +def resolve(hostname): + try: + return socket.gethostbyname(hostname) + except socket.error: + print(f"Not able to resolve {hostname}") + +def render(filepath,funcs,values): + env = Environment(loader=FileSystemLoader(os.path.dirname(filepath))) + jinja_template = env.get_template(os.path.basename(filepath)) + jinja_template.globals.update(funcs) + template_string = jinja_template.render(env=values) + return template_string + +env_variables = dict() +#list of all the environment variables +for name, value in os.environ.items(): + env_variables.update({name:value}) + +if MOUNT_CONFIG != "yes": + output = render(CONFIG_FILE,{"resolve":resolve},env_variables) + with open(CONFIG_FILE, "w") as fh: + fh.write(output) + print(f"Configuration file {CONFIG_FILE} is ready") + if len(sys.argv) == 1: + sys.exit(0) + os.execvp(sys.argv[1], sys.argv[1:]) #important for running the network function it works like exec $@ +else: + print("Configuration file is mounted to the network function") diff --git a/scripts/entrypoint.sh b/scripts/entrypoint.sh deleted file mode 100755 index 72641acf1fc4f5837fb874a8cdb1157e7b85268f..0000000000000000000000000000000000000000 --- a/scripts/entrypoint.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash - -set -euo pipefail - -CONFIG_DIR="/openair-udm/etc" -SBI_PORT=${SBI_PORT:-80} -UDR_PORT=${UDR_PORT:-80} -SBI_HTTP2_PORT=${SBI_HTTP2_PORT:-8080} -USE_HTTP2=${USE_HTTP2:-no} -REGISTER_NRF=${REGISTER_NRF:-no} -NRF_PORT=${NRF_PORT:-80} -NRF_API_VERSION=${NRF_API_VERSION:-v1} -NRF_FQDN=${NRF_FQDN:-oai-nrf} - -if [[ ${USE_FQDN_DNS} == "yes" ]];then - UDR_IP_ADDRESS=${UDR_IP_ADDRESS:-0.0.0.0} - NRF_IPV4_ADDRESS=${NRF_IPV4_ADDRESS:-0.0.0.0} -fi - - -for c in ${CONFIG_DIR}/*.conf; do - # grep variable names (format: ${VAR}) from template to be rendered - if ! grep -oP '@[a-zA-Z0-9_]+@' ${c}; then - echo "Configuration is already set" - exec "$@" - fi - VARS=$(grep -oP '@[a-zA-Z0-9_]+@' ${c} | sort | uniq | xargs) - - # create sed expressions for substituting each occurrence of ${VAR} - # with the value of the environment variable "VAR" - EXPRESSIONS="" - for v in ${VARS}; do - NEW_VAR=`echo $v | sed -e "s#@##g"` - if [[ "${!NEW_VAR}x" == "x" ]]; then - echo "Error: Environment variable '${NEW_VAR}' is not set." \ - "Config file '$(basename $c)' requires all of $VARS." - exit 1 - fi - EXPRESSIONS="${EXPRESSIONS};s|${v}|${!NEW_VAR}|g" - done - EXPRESSIONS="${EXPRESSIONS#';'}" - - # render template and inline replace config file - sed -i "${EXPRESSIONS}" ${c} -done - -exec "$@"