From 433f2128305d5ced36f188278c8ef342bcdaf113 Mon Sep 17 00:00:00 2001 From: Louis Royer Date: Fri, 29 Nov 2024 20:29:23 +0100 Subject: [PATCH] Add NextMN-Lite & update srv6/srv6-ctrl --- .github/workflows/docker-image-cp-lite.yml | 59 +++++++++ .github/workflows/docker-image-gnb-lite.yml | 59 +++++++++ .github/workflows/docker-image-ue-lite.yml | 59 +++++++++ Makefile | 2 +- README.md | 132 ++++++++++++++++++++ cp-lite/Dockerfile | 40 ++++++ cp-lite/entrypoint.sh | 35 ++++++ cp-lite/template-cp-lite.yaml | 10 ++ cp-lite/template-script.sh | 47 +++++++ gnb-lite/Dockerfile | 40 ++++++ gnb-lite/entrypoint.sh | 35 ++++++ gnb-lite/template-gnb-lite.yaml | 10 ++ gnb-lite/template-script.sh | 52 ++++++++ srv6-ctrl/Dockerfile | 4 +- srv6/Dockerfile | 4 +- ue-lite/Dockerfile | 40 ++++++ ue-lite/entrypoint.sh | 35 ++++++ ue-lite/template-script.sh | 40 ++++++ ue-lite/template-ue-lite.yaml | 7 ++ 19 files changed, 705 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/docker-image-cp-lite.yml create mode 100644 .github/workflows/docker-image-gnb-lite.yml create mode 100644 .github/workflows/docker-image-ue-lite.yml create mode 100644 cp-lite/Dockerfile create mode 100755 cp-lite/entrypoint.sh create mode 100644 cp-lite/template-cp-lite.yaml create mode 100755 cp-lite/template-script.sh create mode 100644 gnb-lite/Dockerfile create mode 100755 gnb-lite/entrypoint.sh create mode 100644 gnb-lite/template-gnb-lite.yaml create mode 100755 gnb-lite/template-script.sh create mode 100644 ue-lite/Dockerfile create mode 100755 ue-lite/entrypoint.sh create mode 100755 ue-lite/template-script.sh create mode 100644 ue-lite/template-ue-lite.yaml diff --git a/.github/workflows/docker-image-cp-lite.yml b/.github/workflows/docker-image-cp-lite.yml new file mode 100644 index 0000000..1eaf851 --- /dev/null +++ b/.github/workflows/docker-image-cp-lite.yml @@ -0,0 +1,59 @@ +name: Docker Image CI - CP-Lite + +on: + push: + paths: + - 'cp-lite/**' + branches: [ master ] + workflow_dispatch: + repository_dispatch: + types: [docker-build] + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v4 + - + name: Get current date + id: date + run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT + - + name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: | + ${{ vars.DOCKERHUB_USERNAME }}/${{ vars.DOCKERHUB_REPO_CP_LITE }} + 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@v3 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - + name: Login to DockerHub + uses: docker/login-action@v3 + with: + username: ${{ vars.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - + name: Build and push + uses: docker/build-push-action@v6 + with: + context: "{{defaultContext}}:cp-lite" + 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/.github/workflows/docker-image-gnb-lite.yml b/.github/workflows/docker-image-gnb-lite.yml new file mode 100644 index 0000000..b857304 --- /dev/null +++ b/.github/workflows/docker-image-gnb-lite.yml @@ -0,0 +1,59 @@ +name: Docker Image CI - gNB-Lite + +on: + push: + paths: + - 'gnb-lite/**' + branches: [ master ] + workflow_dispatch: + repository_dispatch: + types: [docker-build] + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v4 + - + name: Get current date + id: date + run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT + - + name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: | + ${{ vars.DOCKERHUB_USERNAME }}/${{ vars.DOCKERHUB_REPO_GNB_LITE }} + 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@v3 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - + name: Login to DockerHub + uses: docker/login-action@v3 + with: + username: ${{ vars.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - + name: Build and push + uses: docker/build-push-action@v6 + with: + context: "{{defaultContext}}:gnb-lite" + 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/.github/workflows/docker-image-ue-lite.yml b/.github/workflows/docker-image-ue-lite.yml new file mode 100644 index 0000000..0b19f19 --- /dev/null +++ b/.github/workflows/docker-image-ue-lite.yml @@ -0,0 +1,59 @@ +name: Docker Image CI - UE-Lite + +on: + push: + paths: + - 'ue-lite/**' + branches: [ master ] + workflow_dispatch: + repository_dispatch: + types: [docker-build] + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v4 + - + name: Get current date + id: date + run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT + - + name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: | + ${{ vars.DOCKERHUB_USERNAME }}/${{ vars.DOCKERHUB_REPO_UE_LITE }} + 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@v3 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - + name: Login to DockerHub + uses: docker/login-action@v3 + with: + username: ${{ vars.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - + name: Build and push + uses: docker/build-push-action@v6 + with: + context: "{{defaultContext}}:ue-lite" + 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/Makefile b/Makefile index 632eb60..0a6daa6 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ .PHONY: docker -all: docker/upf docker/srv6 docker/srv6-ctrl +all: docker/upf docker/srv6 docker/srv6-ctrl docker/ue-lite docker/gnb-lite docker/cp-lite docker/%: docker buildx build -t louisroyer/dev-nextmn-$(@F) ./$(@F) diff --git a/README.md b/README.md index 75db8d4..0ace395 100644 --- a/README.md +++ b/README.md @@ -178,3 +178,135 @@ sysctls: - net.ipv6.conf.all.seg6_enabled=1 - net.ipv6.conf.default.seg6_enabled=1 ``` + +### NextMN UE-Lite +- On Dockerhub: [`louisroyer/dev-nextmn-ue-lite`](https://hub.docker.com/r/louisroyer/dev-nextmn-ue-lite). + +> [!NOTE] +> Please note that even if this software is not yet properly packaged using `.deb`, the generated binary file `/usr/local/bin/ue-lite` is provided to you under MIT License. +> A copy of the source code is available at in the repository [`nextmn/ue-lite`](https://github.com/nextmn/ue-lite). + +Environment variable used to select templating system: +```yaml +environment: + ROUTING_SCRIPT: "docker-setup" + TEMPLATE_SCRIPT: "template-script.sh" + TEMPLATE_SCRIPT_ARGS: "" + CONFIG_FILE: "/etc/nextmn/ue-lite.yaml" + CONFIG_TEMPLATE: "/usr/local/share/nextmn/template-ue-lite.yaml" +``` + +Environment variables for templating: +```yaml +environment: + HTTP_ADDRESS: "192.0.2.3" + HTTP_PORT: "8080" + RAN: |- + bind-addr: "10.1.0.2:1234" + gnbs: + - "http://192.0.2.4:8080" + pdu-sessions: + - gnb: "http://192.0.2.4:8080" + dnn: "nextmn-lite" + LOG_LEVEL: "info" +``` + + +#### Routing +> [!TIP] +> If you choose to configure the container using `docker-setup` (default), please refer to [`docker-setup`'s documentation](https://github.com/louisroyer/docker-setup). The environment variable ONESHOT is set to "true". + +#### Container deployment +> [!IMPORTANT] +> - The container requires the `NET_ADMIN` capability; +> - The tun interface (`/dev/net/tun`) must be available in the container. + +This can be done in `docker-compose.yaml` by defining the following for the service: + +```yaml +cap_add: + - NET_ADMIN +devices: + - "/dev/net/tun" +``` +### NextMN gNB-Lite +- On Dockerhub: [`louisroyer/dev-nextmn-gnb-lite`](https://hub.docker.com/r/louisroyer/dev-nextmn-gnb-lite). + +> [!NOTE] +> Please note that even if this software is not yet properly packaged using `.deb`, the generated binary file `/usr/local/bin/gnb-lite` is provided to you under MIT License. +> A copy of the source code is available at in the repository [`nextmn/gnb-lite`](https://github.com/nextmn/gnb-lite). + +Environment variable used to select templating system: +```yaml +environment: + ROUTING_SCRIPT: "docker-setup" + TEMPLATE_SCRIPT: "template-script.sh" + TEMPLATE_SCRIPT_ARGS: "" + CONFIG_FILE: "/etc/nextmn/gnb-lite.yaml" + CONFIG_TEMPLATE: "/usr/local/share/nextmn/template-gnb-lite.yaml" +``` + +Environment variables for templating: +```yaml +environment: + HTTP_ADDRESS: "192.0.2.4" + HTTP_PORT: "8080" + CP: "http://192.0.2.5:8080" + N3: "10.0.200.4" + RAN: |- + bind-addr: "10.1.0.1:1234" + LOG_LEVEL: "info" +``` + +#### Routing +> [!TIP] +> If you choose to configure the container using `docker-setup` (default), please refer to [`docker-setup`'s documentation](https://github.com/louisroyer/docker-setup). The environment variable ONESHOT is set to "true". + +#### Container deployment +> [!IMPORTANT] +> - The container requires the `NET_ADMIN` capability (if you want to configure the container using `docker-setup`). + +This can be done in `docker-compose.yaml` by defining the following for the service: + +```yaml +cap_add: + - NET_ADMIN +``` + +### NextMN CP-Lite +- On Dockerhub: [`louisroyer/dev-nextmn-cp-lite`](https://hub.docker.com/r/louisroyer/dev-nextmn-cp-lite). + +> [!NOTE] +> Please note that even if this software is not yet properly packaged using `.deb`, the generated binary file `/usr/local/bin/cp-lite` is provided to you under MIT License. +> A copy of the source code is available at in the repository [`nextmn/cp-lite`](https://github.com/nextmn/cp-lite). + +Environment variable used to select templating system: +```yaml +environment: + ROUTING_SCRIPT: "docker-setup" + TEMPLATE_SCRIPT: "template-script.sh" + TEMPLATE_SCRIPT_ARGS: "" + CONFIG_FILE: "/etc/nextmn/cp-lite.yaml" + CONFIG_TEMPLATE: "/usr/local/share/nextmn/template-cp-lite.yaml" +``` + +Environment variables for templating: +```yaml +environment: + N4: "203.0.113.3" + HTTP_ADDRESS: "192.0.2.5" + HTTP_PORT: "8080" + SLICES: |- + nextmn-lite: + pool: "10.0.111.0/24" + upfs: + - node-id: "203.0.113.2" + interfaces: + - type: "N3" + addr: "10.0.200.3" + LOG_LEVEL: "info" +``` + +#### Routing +> [!TIP] +> If you choose to configure the container using `docker-setup` (default), please refer to [`docker-setup`'s documentation](https://github.com/louisroyer/docker-setup). The environment variable ONESHOT is set to "true". diff --git a/cp-lite/Dockerfile b/cp-lite/Dockerfile new file mode 100644 index 0000000..6af1a2e --- /dev/null +++ b/cp-lite/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.22 AS builder +ARG COMMIT=v0.0.1 +RUN : ${COMMIT:? Missing build-arg COMMIT.} && go install github.com/nextmn/cp-lite@${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/nextmn" + +# 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/cp-lite /usr/local/bin/cp-lite +COPY ./*.sh /usr/local/bin/ +COPY ./template-cp-lite.yaml /usr/local/share/nextmn/ +ENV ROUTING_SCRIPT="docker-setup" \ + ONESHOT="true" \ + TEMPLATE_SCRIPT="template-script.sh" \ + TEMPLATE_SCRIPT_ARGS="" \ + CONFIG_FILE="/etc/nextmn/cp-lite.yaml" \ + CONFIG_TEMPLATE="/usr/local/share/nextmn/template-cp-lite.yaml" + +ENTRYPOINT ["entrypoint.sh"] +CMD ["--help"] + +HEALTHCHECK --interval=1m --timeout=1s --retries=3 --start-period=5s --start-interval=100ms \ +CMD ["entrypoint.sh", "healthcheck"] diff --git a/cp-lite/entrypoint.sh b/cp-lite/entrypoint.sh new file mode 100755 index 0000000..b1cd6b4 --- /dev/null +++ b/cp-lite/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 cp-lite --config "$CONFIG_FILE" "$@" +else + exec cp-lite "$@" +fi diff --git a/cp-lite/template-cp-lite.yaml b/cp-lite/template-cp-lite.yaml new file mode 100644 index 0000000..8d949f7 --- /dev/null +++ b/cp-lite/template-cp-lite.yaml @@ -0,0 +1,10 @@ +control: + uri: "http://[%HTTP_ADDRESS]:%HTTP_PORT" + bind-addr: "[%HTTP_ADDRESS]:%HTTP_PORT" + +pfcp: "%N4" + +slices: %SLICES + +logger: + level: "%LOG_LEVEL" diff --git a/cp-lite/template-script.sh b/cp-lite/template-script.sh new file mode 100755 index 0000000..440aae3 --- /dev/null +++ b/cp-lite/template-script.sh @@ -0,0 +1,47 @@ +#!/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 +mkdir -p "$(dirname "${CONFIG_FILE}")" + +if [ -z "$N4" ]; then + echo "Missing mandatory environment variable (N4)." > /dev/stderr + exit 1 +fi +if [ -z "$SLICES" ]; then + echo "Missing mandatory environment variable (SLICES)." > /dev/stderr + exit 1 +fi +if [ -z "$HTTP_ADDRESS" ]; then + echo "Missing mandatory environment variable (HTTP_ADDRESS)." > /dev/stderr + exit 1 +fi + +IFS=$'\n' + +SLICES_SUB="" +for S in ${SLICES}; do + if [ -n "${S}" ]; then + SLICES_SUB="${SLICES_SUB}\n ${S}" + fi +done + +awk \ + -v LOG_LEVEL="${LOG_LEVEL:-info}" \ + -v HTTP_PORT="${HTTP_PORT:-80}" \ + -v HTTP_ADDRESS="${HTTP_ADDRESS}" \ + -v SLICES="${SLICES_SUB}" \ + -v N4="${N4}" \ + -v SLICES="${SLICES_SUB}" \ + '{ + sub(/%LOG_LEVEL/, LOG_LEVEL); + sub(/%HTTP_PORT/, HTTP_PORT); + sub(/%HTTP_ADDRESS/, HTTP_ADDRESS); + sub(/%N4/, N4); + sub(/%SLICES/, SLICES); + print; + }' \ + "${CONFIG_TEMPLATE}" > "${CONFIG_FILE}" diff --git a/gnb-lite/Dockerfile b/gnb-lite/Dockerfile new file mode 100644 index 0000000..8e397a2 --- /dev/null +++ b/gnb-lite/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.22 AS builder +ARG COMMIT=v0.0.1 +RUN : ${COMMIT:? Missing build-arg COMMIT.} && go install github.com/nextmn/gnb-lite@${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/nextmn" + +# 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/gnb-lite /usr/local/bin/gnb-lite +COPY ./*.sh /usr/local/bin/ +COPY ./template-gnb-lite.yaml /usr/local/share/nextmn/ +ENV ROUTING_SCRIPT="docker-setup" \ + ONESHOT="true" \ + TEMPLATE_SCRIPT="template-script.sh" \ + TEMPLATE_SCRIPT_ARGS="" \ + CONFIG_FILE="/etc/nextmn/gnb-lite.yaml" \ + CONFIG_TEMPLATE="/usr/local/share/nextmn/template-gnb-lite.yaml" + +ENTRYPOINT ["entrypoint.sh"] +CMD ["--help"] + +HEALTHCHECK --interval=1m --timeout=1s --retries=3 --start-period=5s --start-interval=100ms \ +CMD ["entrypoint.sh", "healthcheck"] diff --git a/gnb-lite/entrypoint.sh b/gnb-lite/entrypoint.sh new file mode 100755 index 0000000..ae721e0 --- /dev/null +++ b/gnb-lite/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 gnb-lite --config "$CONFIG_FILE" "$@" +else + exec gnb-lite "$@" +fi diff --git a/gnb-lite/template-gnb-lite.yaml b/gnb-lite/template-gnb-lite.yaml new file mode 100644 index 0000000..abe5292 --- /dev/null +++ b/gnb-lite/template-gnb-lite.yaml @@ -0,0 +1,10 @@ +control: + uri: "http://[%HTTP_ADDRESS]:%HTTP_PORT" + bind-addr: "[%HTTP_ADDRESS]:%HTTP_PORT" +ran: %RAN +cp: + uri: "%CP" +gtp: "%N3" + +logger: + level: "%LOG_LEVEL" diff --git a/gnb-lite/template-script.sh b/gnb-lite/template-script.sh new file mode 100755 index 0000000..776d1b2 --- /dev/null +++ b/gnb-lite/template-script.sh @@ -0,0 +1,52 @@ +#!/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 +mkdir -p "$(dirname "${CONFIG_FILE}")" + +if [ -z "$N3" ]; then + echo "Missing mandatory environment variable (N3)." > /dev/stderr + exit 1 +fi +if [ -z "$HTTP_ADDRESS" ]; then + echo "Missing mandatory environment variable (HTTP_ADDRESS)." > /dev/stderr + exit 1 +fi +if [ -z "$CP" ]; then + echo "Missing mandatory environment variable (CP)." > /dev/stderr + exit 1 +fi +if [ -z "$RAN" ]; then + echo "Missing mandatory environment variable (RAN)." > /dev/stderr + exit 1 +fi + +IFS=$'\n' + +RAN_SUB="" +for R in ${RAN}; do + if [ -n "${R}" ]; then + RAN_SUB="${RAN_SUB}\n ${R}" + fi +done + +awk \ + -v LOG_LEVEL="${LOG_LEVEL:-info}" \ + -v RAN="${RAN_SUB}" \ + -v HTTP_PORT="${HTTP_PORT:-80}" \ + -v HTTP_ADDRESS="${HTTP_ADDRESS}" \ + -v N3="${N3}" \ + -v CP="${CP}" \ + '{ + sub(/%LOG_LEVEL/, LOG_LEVEL); + sub(/%RAN/, RAN); + sub(/%HTTP_PORT/, HTTP_PORT); + sub(/%HTTP_ADDRESS/, HTTP_ADDRESS); + sub(/%N3/, N3); + sub(/%CP/, CP); + print; + }' \ + "${CONFIG_TEMPLATE}" > "${CONFIG_FILE}" diff --git a/srv6-ctrl/Dockerfile b/srv6-ctrl/Dockerfile index 65693e6..5e05ef6 100644 --- a/srv6-ctrl/Dockerfile +++ b/srv6-ctrl/Dockerfile @@ -4,7 +4,7 @@ # SPDX-License-Identifier: MIT FROM golang:1.22 AS builder -ARG COMMIT=v0.0.18 +ARG COMMIT=v0.0.19 RUN : ${COMMIT:? Missing build-arg COMMIT.} && go install github.com/nextmn/srv6-ctrl@${COMMIT} @@ -36,5 +36,5 @@ ENV ROUTING_SCRIPT="docker-setup" \ ENTRYPOINT ["entrypoint.sh"] CMD ["--help"] -HEALTHCHECK --interval=1m --timeout=1s --retries=3 --start-period=5s --start-interval=1s \ +HEALTHCHECK --interval=1m --timeout=1s --retries=3 --start-period=5s --start-interval=100ms \ CMD ["entrypoint.sh", "healthcheck"] diff --git a/srv6/Dockerfile b/srv6/Dockerfile index 76ee5f9..68ea3a9 100644 --- a/srv6/Dockerfile +++ b/srv6/Dockerfile @@ -4,7 +4,7 @@ # SPDX-License-Identifier: MIT FROM golang:1.22 AS builder -ARG COMMIT=v0.0.22 +ARG COMMIT=v0.0.23 RUN : ${COMMIT:? Missing build-arg COMMIT.} && go install github.com/nextmn/srv6@${COMMIT} \ && find /go/pkg/mod/github.com/nextmn -iname 'srv6@*' -type d -exec ln -s {} /configuration \; @@ -37,5 +37,5 @@ ENV TEMPLATE_SCRIPT="template-script.sh" \ ENTRYPOINT ["entrypoint.sh"] CMD ["--help"] -HEALTHCHECK --interval=1m --timeout=1s --retries=3 --start-period=5s --start-interval=1s \ +HEALTHCHECK --interval=1m --timeout=1s --retries=3 --start-period=5s --start-interval=100ms \ CMD ["entrypoint.sh", "healthcheck"] diff --git a/ue-lite/Dockerfile b/ue-lite/Dockerfile new file mode 100644 index 0000000..77ef12f --- /dev/null +++ b/ue-lite/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.22 AS builder +ARG COMMIT=v0.0.1 +RUN : ${COMMIT:? Missing build-arg COMMIT.} && go install github.com/nextmn/ue-lite@${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/nextmn" + +# 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 iproute2 iptables \ + && apt-get upgrade -qy \ + && rm -rf /var/lib/apt/lists/* + +COPY --from=builder /go/bin/ue-lite /usr/local/bin/ue-lite +COPY ./*.sh /usr/local/bin/ +COPY ./template-ue-lite.yaml /usr/local/share/nextmn/ +ENV ROUTING_SCRIPT="docker-setup" \ + ONESHOT="true" \ + TEMPLATE_SCRIPT="template-script.sh" \ + TEMPLATE_SCRIPT_ARGS="" \ + CONFIG_FILE="/etc/nextmn/ue-lite.yaml" \ + CONFIG_TEMPLATE="/usr/local/share/nextmn/template-ue-lite.yaml" + +ENTRYPOINT ["entrypoint.sh"] +CMD ["--help"] + +HEALTHCHECK --interval=1m --timeout=1s --retries=3 --start-period=5s --start-interval=100ms \ +CMD ["entrypoint.sh", "healthcheck"] diff --git a/ue-lite/entrypoint.sh b/ue-lite/entrypoint.sh new file mode 100755 index 0000000..1e35949 --- /dev/null +++ b/ue-lite/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 ue-lite --config "$CONFIG_FILE" "$@" +else + exec ue-lite "$@" +fi diff --git a/ue-lite/template-script.sh b/ue-lite/template-script.sh new file mode 100755 index 0000000..8cec74c --- /dev/null +++ b/ue-lite/template-script.sh @@ -0,0 +1,40 @@ +#!/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 +mkdir -p "$(dirname "${CONFIG_FILE}")" + +if [ -z "$HTTP_ADDRESS" ]; then + echo "Missing mandatory environment variable (HTTP_ADDRESS)." > /dev/stderr + exit 1 +fi +if [ -z "$RAN" ]; then + echo "Missing mandatory environment variable (RAN)." > /dev/stderr + exit 1 +fi + +IFS=$'\n' + +RAN_SUB="" +for R in ${RAN}; do + if [ -n "${R}" ]; then + RAN_SUB="${RAN_SUB}\n ${R}" + fi +done + +awk \ + -v LOG_LEVEL="${LOG_LEVEL:-info}" \ + -v RAN="${RAN_SUB}" \ + -v HTTP_PORT="${HTTP_PORT:-80}" \ + -v HTTP_ADDRESS="${HTTP_ADDRESS}" \ + '{ + sub(/%LOG_LEVEL/, LOG_LEVEL); + sub(/%RAN/, RAN); + sub(/%HTTP_PORT/, HTTP_PORT); + sub(/%HTTP_ADDRESS/, HTTP_ADDRESS); + print; + }' \ + "${CONFIG_TEMPLATE}" > "${CONFIG_FILE}" diff --git a/ue-lite/template-ue-lite.yaml b/ue-lite/template-ue-lite.yaml new file mode 100644 index 0000000..3000860 --- /dev/null +++ b/ue-lite/template-ue-lite.yaml @@ -0,0 +1,7 @@ +control: + uri: "http://[%HTTP_ADDRESS]:%HTTP_PORT" + bind-addr: "[%HTTP_ADDRESS]:%HTTP_PORT" +ran: %RAN + +logger: + level: "%LOG_LEVEL"