Commit 4865020a authored by Javier Velázquez's avatar Javier Velázquez
Browse files

Merge branch 'feat/ci-cd-pipeline' into 'develop'

Implement CI/CD pipeline

See merge request !18
parents 4e756df9 076357f3
Loading
Loading
Loading
Loading
Loading

.gitlab-ci.yml

0 → 100644
+81 −0
Original line number Diff line number Diff line
# 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.

stages:
  - build
  - unit_test

# Build, tag, and push the Docker image to the GitLab Docker registry
build nsc:
  variables:
    IMAGE_NAME: 'nsc'
    IMAGE_TAG: 'test'
  stage: build
  before_script:
    - docker image prune --force
    - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
  script:
    - docker buildx build -t "$IMAGE_NAME:$IMAGE_TAG" -f ./Dockerfile .
    - docker tag "$IMAGE_NAME:$IMAGE_TAG" "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG"
    - docker push "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG"
  after_script:
    - docker image prune --force
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH)'
    - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "develop"'

# Apply unit test to the component
unit_test nsc:
  timeout: 15m
  variables:
    IMAGE_NAME: 'nsc' # name of the microservice
    IMAGE_TAG: 'test' # tag of the container image (production, development, etc)
  stage: unit_test
  needs:
    - build nsc
  before_script:
    # Do Docker cleanup
    - docker ps --all --quiet | xargs --no-run-if-empty docker stop
    - docker container prune --force
    - docker ps --all --quiet | xargs --no-run-if-empty docker rm --force
    - docker image prune --force
    - docker network prune --force
    - docker volume prune --all --force
    - docker buildx prune --force

    - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
  script:
    - docker pull "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG"
    - docker run --name $IMAGE_NAME -d -p 8081:8081 -v "$PWD/src/tests:/opt/results" $CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG
    - sleep 5
    - docker ps -a
    - docker logs $IMAGE_NAME
    - docker exec -i $IMAGE_NAME bash -c "coverage run -m pytest --log-level=INFO --verbose --junitxml=/opt/results/report.xml"
    - docker exec -i $IMAGE_NAME bash -c "coverage report --show-missing"
  coverage: '/TOTAL\s+\d+\s+\d+\s+(\d+%)/'
  after_script:
    # Clean up
    - docker ps --all --quiet | xargs --no-run-if-empty docker stop
    - docker container prune --force
    - docker ps --all --quiet | xargs --no-run-if-empty docker rm --force
    - docker network prune --force
    - docker volume prune --all --force
    - docker image prune --force
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH)'
    - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "develop"'
  artifacts:
      when: always
      reports:
        junit: src/tests/report.xml
+14 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ The Network Slice Controller (NSC) is a component defined by the IETF to orchest
   - [Ixia Configuration](#ixia-configuration)  
   - [WebUI](#webui-1)  
9. [Usage](#usage)  
10. [Available Branches and Releases](#available-branches-and-releases)

---

@@ -175,3 +176,16 @@ To use the NSC, just build the image an run it in a container following these st

    Send slice requests via **API** (/nsc) or **WebUI** (/webui)

## Available branches and releases

[![Latest Release](https://labs.etsi.org/rep/tfs/nsc/-/badges/release.svg)](https://labs.etsi.org/rep/tfs/nsc/-/releases)

- The branch `main` ([![pipeline status](https://labs.etsi.org/rep/tfs/nsc/badges/main/pipeline.svg)](https://labs.etsi.org/rep/tfs/nsc/-/commits/main) [![coverage report](https://labs.etsi.org/rep/tfs/nsc/badges/main/coverage.svg)](https://labs.etsi.org/rep/tfs/nsc/-/commits/main)), points always to the latest stable version of the TeraFlowSDN Network Slice Controller (NSC).

- The branches `release/X.Y.Z`, point to the code for the different release versions indicated in the branch name.
  - Code in these branches can be considered stable, and no new features are planned.
  - In case of bugs, point releases increasing revision number (Z) might be created.

- The `develop` ([![pipeline status](https://labs.etsi.org/rep/tfs/nsc/badges/develop/pipeline.svg)](https://labs.etsi.org/rep/tfs/nsc/-/commits/develop) [![coverage report](https://labs.etsi.org/rep/tfs/nsc/badges/develop/coverage.svg)](https://labs.etsi.org/rep/tfs/nsc/-/commits/develop)) branch is the main development branch and contains the latest contributions.
  - **Use it with care! It might not be stable.**
  - The latest developments and contributions are added to this branch for testing and validation before reaching a release.
+3 −1
Original line number Diff line number Diff line
@@ -21,3 +21,5 @@ netmiko
requests
pandas
dotenv
coverage
pytest
+3 −0
Original line number Diff line number Diff line
@@ -134,6 +134,9 @@ class Api:
                message="Slice modified successfully",
                data=result
            )
        except ValueError as e:
            # Handle case where no slices are found
            return send_response(False, code=404, message=str(e))
        except Exception as e:
            # Handle unexpected errors
            return send_response(False, code=500, message=str(e))
+1 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ def slo_viability(slice_slos, nrp_slos):
                "one-way-packet-loss", "two-way-packet-loss"],
        "min": ["one-way-bandwidth", "two-way-bandwidth", "shared-bandwidth"]
    }
    score = 0
    flexibility_scores = []
    for slo in slice_slos:
        for nrp_slo in nrp_slos['slos']:
Loading