Skip to content

Commit

Permalink
NRF
Browse files Browse the repository at this point in the history
  • Loading branch information
louisroyer committed Jan 17, 2024
1 parent bdd76ab commit 00e0f03
Show file tree
Hide file tree
Showing 8 changed files with 237 additions and 1 deletion.
59 changes: 59 additions & 0 deletions .github/workflows/docker-image-nrf.yml
Original file line number Diff line number Diff line change
@@ -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
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
```
2 changes: 1 addition & 1 deletion amf/template-amf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions amf/template-script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}" \
Expand All @@ -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);
Expand Down
40 changes: 40 additions & 0 deletions nrf/Dockerfile
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>" \
org.opencontainers.image.authors="Louis Royer <[email protected]>" \
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"]
35 changes: 35 additions & 0 deletions nrf/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions nrf/template-nrf.yaml
Original file line number Diff line number Diff line change
@@ -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
41 changes: 41 additions & 0 deletions nrf/template-script.sh
Original file line number Diff line number Diff line change
@@ -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}"

0 comments on commit 00e0f03

Please sign in to comment.