From ab62dcf944416a5827fe3ce0d5e45f7c601d20f1 Mon Sep 17 00:00:00 2001 From: velazquez Date: Thu, 16 Oct 2025 10:50:20 +0200 Subject: [PATCH 1/2] Create dockerfile to build the nsc image Create deploy script to build and run the nsc container Add docker ignore file --- .dockerignore | 5 ++++ Dockerfile | 38 ++++++++++++++++++++++++++ deploy.sh | 60 +++++++++++++++++++++++++++++++++++++++++ requirements.txt | 16 +++++++++++ src/config/.env.example | 7 +++-- src/config/constants.py | 3 ++- 6 files changed, 126 insertions(+), 3 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 deploy.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..b895f09 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +__pycache__/ +*.pyc +*.db +.env +.git/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1d520d5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,38 @@ +# Copyright 2022-2025 ETSI SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/) +# +# Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 +# +# 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. + +# This file is an original contribution from Telefonica Innovación Digital S.L. + +FROM python:3.12-slim + +# Establece el directorio de trabajo +WORKDIR /app + +# Instala dependencias del sistema +RUN apt-get update -qq && \ + apt-get install -y -qq git python3-dev && \ + apt-get clean && rm -rf /var/lib/apt/lists/* + +# Copia el contenido del proyecto +COPY . /app + +# Instala dependencias de Python +RUN pip install --upgrade pip && \ + pip install -r requirements.txt + +# Expone el puerto +EXPOSE 8081 + +# Comando de inicio +ENTRYPOINT ["python3", "app.py"] diff --git a/deploy.sh b/deploy.sh new file mode 100644 index 0000000..8bd99bf --- /dev/null +++ b/deploy.sh @@ -0,0 +1,60 @@ +#!/bin/bash + +# Copyright 2022-2025 ETSI SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/) + +# Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 + +# 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. + +# This file is an original contribution from Telefonica Innovación Digital S.L. + +# Container name +CONTAINER_NAME=nsc + +# Verify if docker is active +if ! docker info > /dev/null 2>&1; then + echo "Error: Docker not running. Please, restart Docker service and try again." + exit 1 +fi + +# Stop container if running +echo "Verify if '$CONTAINER_NAME' is running..." +if [ $(docker ps -q -f name=$CONTAINER_NAME) ]; then + echo "Stopping current container '$CONTAINER_NAME'..." + docker stop $CONTAINER_NAME +fi + +# Cleaning residual containers and images +echo "Cleaning old Docker containers and images..." +docker container prune -f +docker image prune -f + +# Verificar que .env.example existe +if [ ! -f src/config/.env.example ]; then + echo "Error: .env.example not found" + exit 1 +fi + +# Copy .env.example to .env +echo "Generating .env file..." +cp src/config/.env.example .env + +# Read NSC_PORT from .env +NSC_PORT=$(grep '^NSC_PORT=' .env | cut -d '=' -f2) + +# Docker build +echo "Building docker image..." +docker build -t nsc . + +# Executing nsc +echo "Running nsc on port $NSC_PORT..." +docker run -d --env-file .env -p $NSC_PORT:$NSC_PORT --name $CONTAINER_NAME $CONTAINER_NAME +echo "---READY---" diff --git a/requirements.txt b/requirements.txt index 8e50394..1622628 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,19 @@ +# Copyright 2022-2025 ETSI SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/) +# +# Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 +# +# 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. + +# This file is an original contribution from Telefonica Innovación Digital S.L. + Flask flask-cors flask-restx diff --git a/src/config/.env.example b/src/config/.env.example index 784d74e..fb565b7 100644 --- a/src/config/.env.example +++ b/src/config/.env.example @@ -17,7 +17,9 @@ # ------------------------- # General # ------------------------- -LOGGING_LEVEL=INFO # Options: CRITICAL, ERROR, WARNING, INFO, DEBUG, NOTSET +NSC_PORT=8081 +# Options: CRITICAL, ERROR, WARNING, INFO, DEBUG, NOTSET +LOGGING_LEVEL=INFO DUMP_TEMPLATES=false # ------------------------- @@ -46,7 +48,8 @@ DUMMY_MODE=true # Teraflow # ------------------------- TFS_IP=127.0.0.1 -UPLOAD_TYPE=WEBUI # Options: WEBUI o NBI +# Options: WEBUI or NBI +UPLOAD_TYPE=WEBUI # Flag to determine if additional L2VPN configuration support is required for deploying L2VPNs with path selection TFS_L2VPN_SUPPORT=false diff --git a/src/config/constants.py b/src/config/constants.py index 5f5bb85..b3d6b87 100644 --- a/src/config/constants.py +++ b/src/config/constants.py @@ -15,9 +15,10 @@ # This file includes original contributions from Telefonica Innovación Digital S.L. from pathlib import Path +import os # Default port for NSC deployment -NSC_PORT = 8081 +NSC_PORT = os.getenv("NSC_PORT", "8081") # Paths BASE_DIR = Path(__file__).resolve().parent.parent.parent -- GitLab From 130ac23bfdfdf8c1e80c6bcd59b88df16c516a2b Mon Sep 17 00:00:00 2001 From: velazquez Date: Thu, 16 Oct 2025 10:59:00 +0200 Subject: [PATCH 2/2] Add script to show NSC logs --- scripts/show_logs_nsc.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 scripts/show_logs_nsc.sh diff --git a/scripts/show_logs_nsc.sh b/scripts/show_logs_nsc.sh new file mode 100644 index 0000000..53a02fc --- /dev/null +++ b/scripts/show_logs_nsc.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +# Copyright 2022-2025 ETSI SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/) +# +# Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 +# +# 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. + +# This file is an original contribution from Telefonica Innovación Digital S.L. + +docker logs nsc \ No newline at end of file -- GitLab