diff --git a/.github/workflows/docker-image-nrf.yml b/.github/workflows/docker-image-nrf.yml new file mode 100644 index 0000000..530d0cc --- /dev/null +++ b/.github/workflows/docker-image-nrf.yml @@ -0,0 +1,59 @@ +name: Docker Image CI - NRF + +on: + schedule: + - cron: '00 04 * * Sun' + push: + paths: + - 'nrf/**' + branches: [ master ] + workflow_dispatch: + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v3 + - + name: Get current date + id: date + run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT + - + name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: | + ${{ vars.DOCKERHUB_USERNAME }}/${{ vars.DOCKERHUB_REPO_NRF }} + tags: | + type=raw,enable=true,priority=100,prefix=bookworm-,suffix=-slim,value={{date 'YYYY-MM-DD'}}-{{sha}} + flavor: | + latest=true + prefix= + suffix= + - + name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - + name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ vars.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - + name: Build and push + uses: docker/build-push-action@v3 + with: + context: "{{defaultContext}}:nrf" + push: true + tags: ${{ steps.meta.outputs.tags }} + build-args: BUILD_DATE=${{ steps.date.outputs.date }} + labels: ${{ steps.meta.outputs.labels }} + platforms: linux/amd64 + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/README.md b/README.md index 004f77d..0c2ba26 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ environment: N2: "192.0.2.1" SBI_REGISTER_IP: "amf.sbi" # you can use a domain or an IP address SBI_BINDING_IP: "192.51.100.1" # use only an IP address in this field + SBI_BINDING_PORT: "8000" # default: "8000" MCC: "001" MNC: "01" AMF_ID: "000001" # 6 digits @@ -49,3 +50,32 @@ environment: TAC: "000001" # 6 digits LOCALITY: "area1" ``` + +### NRF +- On Dockerhub: [`louisroyer/dev-free5gc-nrf`](https://hub.docker.com/r/louisroyer/dev-free5gc-nrf). + +Please note that even if this software is not yet properly packaged using `.deb`, the generated binary file `/usr/local/bin/nrf` is provided to you under Apache Version 2.0 License. A copy of this license can be found in `/usr/share/common-licenses/Apache-2.0`. +A copy of the source code is available at in the repository [`free5gc/nrf`](https://github.com/free5gc/nrf). + +Environment variable used to select templating system: +```yaml +environment: + ROUTING_SCRIPT: "docker-setup" + TEMPLATE_SCRIPT: "template-script.sh" + TEMPLATE_SCRIPT_ARGS: "" + CONFIG_FILE: "/etc/free5gc/nrf.yaml" + CONFIG_TEMPLATE: "/etc/free5gc/template-nrf.yaml" +``` + +Environment variables for templating: +```yaml +environment: + MONGO_HOST: "mongodb.db" + MONGO_PORT: "27017" + MONGO_NAME: "free5gc" + SBI_REGISTER_IP: "nrf.sbi" # you can use a domain or an IP address + SBI_BINDING_IP: "192.51.100.2" # use only an IP address in this field + SBI_BINDING_PORT: "8000" # default: "8000" + MCC: "001" + MNC: "01" +``` diff --git a/amf/template-amf.yaml b/amf/template-amf.yaml index 7141056..4684255 100644 --- a/amf/template-amf.yaml +++ b/amf/template-amf.yaml @@ -11,7 +11,7 @@ configuration: scheme: http # the protocol for sbi (http or https) registerIPv4: %SBI_REGISTER_IP # IP used to register to NRF bindingIPv4: %SBI_BINDING_IP # IP used to bind the service - port: 8000 # port used to bind the service + port: %SBI_BINDING_PORT # port used to bind the service tls: # the local path of TLS key pem: cert/amf.pem # AMF TLS Certificate key: cert/amf.key # AMF TLS Private key diff --git a/amf/template-script.sh b/amf/template-script.sh index e47086c..d60252a 100755 --- a/amf/template-script.sh +++ b/amf/template-script.sh @@ -49,6 +49,7 @@ awk \ -v N2="${N2}" \ -v SBI_REGISTER_IP="${SBI_REGISTER_IP}" \ -v SBI_BINDING_IP="${SBI_BINDING_IP}" \ + -v SBI_BINDING_PORT="${SBI_BINDING_PORT:-8000}" \ -v MCC="${MCC:-001}" \ -v MNC="${MNC:-01}" \ -v AMF_ID="${AMF_ID:-0000001}" \ @@ -62,6 +63,7 @@ awk \ sub(/%N2/, N2); sub(/%SBI_REGISTER_IP/, SBI_REGISTER_IP); sub(/%SBI_BINDING_IP/, SBI_BINDING_IP); + sub(/%SBI_BINDING_PORT/, SBI_BINDING_PORT); sub(/%MCC/, MCC); sub(/%MNC/, MNC); sub(/%AMF_ID/, AMF_ID); diff --git a/nrf/Dockerfile b/nrf/Dockerfile new file mode 100644 index 0000000..cabdaca --- /dev/null +++ b/nrf/Dockerfile @@ -0,0 +1,40 @@ +# Copyright 2024 Louis Royer. All rights reserved. +# Use of this source code is governed by a MIT-style license that can be +# found in the LICENSE file. +# SPDX-License-Identifier: MIT + +FROM golang:1.21 AS builder +ARG COMMIT=26fb5a1a5a60ce87127862a14c3727dcca161fde +RUN : ${COMMIT:? Missing build-arg COMMIT.} && go install github.com/free5gc/nrf/cmd@${COMMIT} + + +FROM louisroyer/base-irit:latest + +LABEL maintainer="Louis Royer " \ + org.opencontainers.image.authors="Louis Royer " \ + org.opencontainers.image.source="https://github.com/louisroyer-docker/free5gc" + +# Used to disable caching of next steps, if not build since 1 day, +# allowing to search and apply security upgrades +ARG BUILD_DATE="" + +RUN apt-get update -q && DEBIAN_FRONTEND=non-interactive apt-get install -qy --no-install-recommends --no-install-suggests \ + docker-setup \ + && apt-get upgrade -qy \ + && rm -rf /var/lib/apt/lists/* + +COPY --from=builder /go/bin/cmd /usr/local/bin/nrf + +COPY ./entrypoint.sh /usr/local/bin/entrypoint.sh +ENV ROUTING_SCRIPT="docker-setup" + +COPY ./template-script.sh /usr/local/bin/template-script.sh +ENV TEMPLATE_SCRIPT="template-script.sh" +ENV TEMPLATE_SCRIPT_ARGS="" + +COPY ./template-nrf.yaml /etc/free5gc/template-nrf.yaml +ENV CONFIG_FILE="/etc/free5gc/nrf.yaml" +ENV CONFIG_TEMPLATE="/etc/free5gc/template-nrf.yaml" + +ENTRYPOINT ["entrypoint.sh"] +CMD ["--help"] diff --git a/nrf/entrypoint.sh b/nrf/entrypoint.sh new file mode 100755 index 0000000..a14fc9a --- /dev/null +++ b/nrf/entrypoint.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +# Copyright 2024 Louis Royer. All rights reserved. +# Use of this source code is governed by a MIT-style license that can be +# found in the LICENSE file. +# SPDX-License-Identifier: MIT + +set -e +savedargs=( "$@" ) +config_opt=1 +while [ $# -gt 0 ]; do + if [[ $1 == "--config" || $1 == "-c" ]]; then + config_opt=0 + fi + shift +done +set -- "${savedargs[@]}" + +if [[ -n "${CONFIG_TEMPLATE}" && -n "${CONFIG_FILE}" ]]; then + if [ -n "${TEMPLATE_SCRIPT}" ]; then + echo "[$(date --iso-8601=s)] Running ${TEMPLATE_SCRIPT}${TEMPLATE_SCRIPT_ARGS:+ }${TEMPLATE_SCRIPT_ARGS} for building ${CONFIG_FILE} from ${CONFIG_TEMPLATE}." > /dev/stderr + "$TEMPLATE_SCRIPT" "$TEMPLATE_SCRIPT_ARGS" + fi +else + config_opt=0 +fi + +if [ -n "${ROUTING_SCRIPT}" ]; then + "${ROUTING_SCRIPT}" & +fi + +if [[ $config_opt -eq 1 ]]; then + exec nrf --config "$CONFIG_FILE" "$@" +else + exec nrf "$@" +fi diff --git a/nrf/template-nrf.yaml b/nrf/template-nrf.yaml new file mode 100644 index 0000000..a74a655 --- /dev/null +++ b/nrf/template-nrf.yaml @@ -0,0 +1,29 @@ +info: + version: 1.0.1 + description: NRF initial local configuration + +configuration: + MongoDBName: %MONGO_NAME # database name in MongoDB + MongoDBUrl: mongodb://%MONGO_HOST:%MONGO_PORT # a valid URL of the mongodb + sbi: # Service-based interface information + scheme: http # the protocol for sbi (http or https) + registerIPv4: %SBI_REGISTER_IP # IP used to serve NFs or register to another NRF + bindingIPv4: %SBI_BINDING_IP # IP used to bind the service + port: %SBI_BINDING_PORT # port used to bind the service + tls: + pem: config/TLS/nrf.pem + key: config/TLS/nrf.key + DefaultPlmnId: + mcc: %MCC # Mobile Country Code (3 digits string, digit: 0~9) + mnc: %MNC # Mobile Network Code (2 or 3 digits string, digit: 0~9) + serviceNameList: # the SBI services provided by this NRF, refer to TS 29.510 + - nnrf-nfm # Nnrf_NFManagement service + - nnrf-disc # Nnrf_NFDiscovery service + +# the kind of log output + # debugLevel: how detailed to output, value: trace, debug, info, warn, error, fatal, panic + # ReportCaller: enable the caller report or not, value: true or false +logger: + NRF: + debugLevel: info + ReportCaller: false diff --git a/nrf/template-script.sh b/nrf/template-script.sh new file mode 100755 index 0000000..2230071 --- /dev/null +++ b/nrf/template-script.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash +# Copyright 2024 Louis Royer. All rights reserved. +# Use of this source code is governed by a MIT-style license that can be +# found in the LICENSE file. +# SPDX-License-Identifier: MIT + +set -e +if [ -z "$MONGO_HOST" ]; then + echo "Missing mandatory environment variable (MONGO_HOST)." > /dev/stderr + exit 1 +fi +if [ -z "$SBI_REGISTER_IP" ]; then + echo "Missing mandatory environment variable (SBI_REGISTER_IP)." > /dev/stderr + exit 1 +fi +if [ -z "$SBI_BINDING_IP" ]; then + echo "Missing mandatory environment variable (SBI_BINDING_IP)." > /dev/stderr + exit 1 +fi + +awk \ + -v MONGO_HOST="${MONGO_HOST}" \ + -v MONGO_PORT="${MONGO_PORT:-27017}" \ + -v MONGO_NAME="${MONGO_NAME:-free5gc}" \ + -v SBI_REGISTER_IP="${SBI_REGISTER_IP}" \ + -v SBI_BINDING_IP="${SBI_BINDING_IP}" \ + -v SBI_BINDING_PORT="${SBI_BINDING_PORT:-8000}" \ + -v MCC="${MCC:-001}" \ + -v MNC="${MNC:-01}" \ + '{ + sub(/%MONGO_HOST/, MONGO_HOST); + sub(/%MONGO_PORT/, MONGO_PORT); + sub(/%MONGO_NAME/, MONGO_NAME); + sub(/%SBI_REGISTER_IP/, SBI_REGISTER_IP); + sub(/%SBI_BINDING_IP/, SBI_BINDING_IP); + sub(/%SBI_BINDING_PORT/, SBI_BINDING_PORT); + sub(/%MCC/, MCC); + sub(/%MNC/, MNC); + print; + }' \ + "${CONFIG_TEMPLATE}" > "${CONFIG_FILE}"