diff --git a/src/service/.gitlab-ci.yml b/src/service/.gitlab-ci.yml index 83d01a903ab64403d8730ad7d98ef6686f32a57d..7209fed227f2a88b1f8d5bba0c97e758ae68af03 100644 --- a/src/service/.gitlab-ci.yml +++ b/src/service/.gitlab-ci.yml @@ -48,22 +48,27 @@ unit_test service: - build service before_script: - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY - - if docker network list | grep teraflowbridge; then echo "teraflowbridge is already created"; else docker network create --driver=bridge teraflowbridge; fi - - | - # Context-related - if docker container ls | grep crdb; then docker rm -f crdb; else echo "CockroachDB container is not in the system"; fi - if docker volume ls | grep crdb; then docker volume rm -f crdb; else echo "CockroachDB volume is not in the system"; fi + - > + if docker network list | grep teraflowbridge; then + echo "teraflowbridge is already created"; + else + docker network create --driver=bridge teraflowbridge; + fi + - > + # Context-related cleanup + if docker container ls | grep crdb; then docker rm -f crdb; else echo "CockroachDB container is not in the system"; fi; + if docker volume ls | grep crdb; then docker volume rm -f crdb; else echo "CockroachDB volume is not in the system"; fi; if docker container ls | grep nats; then docker rm -f nats; else echo "NATS container is not in the system"; fi - - | - # Device-related - if docker container ls | grep context; then docker rm -f context; else echo "context image is not in the system"; fi + - > + # Device-related cleanup + if docker container ls | grep context; then docker rm -f context; else echo "context image is not in the system"; fi; if docker container ls | grep device; then docker rm -f device; else echo "device image is not in the system"; fi - - | - # Pathcomp-related - if docker container ls | grep pathcomp-frontend; then docker rm -f pathcomp-frontend; else echo "pathcomp-frontend image is not in the system"; fi + - > + # Pathcomp-related cleanup + if docker container ls | grep pathcomp-frontend; then docker rm -f pathcomp-frontend; else echo "pathcomp-frontend image is not in the system"; fi; if docker container ls | grep pathcomp-backend; then docker rm -f pathcomp-backend; else echo "pathcomp-backend image is not in the system"; fi - - | - # Service-related + - > + # Service-related cleanup if docker container ls | grep $IMAGE_NAME; then docker rm -f $IMAGE_NAME; else echo "$IMAGE_NAME image is not in the system"; fi script: - docker pull "cockroachdb/cockroach:latest-v22.2" @@ -73,27 +78,24 @@ unit_test service: - docker pull "$CI_REGISTRY_IMAGE/pathcomp-frontend:$IMAGE_TAG" - docker pull "$CI_REGISTRY_IMAGE/pathcomp-backend:$IMAGE_TAG" - docker pull "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG" - - | + - > # Context preparation - docker volume create crdb + docker volume create crdb; docker run --name crdb -d --network=teraflowbridge -p 26257:26257 -p 8080:8080 \ --env COCKROACH_DATABASE=tfs_test --env COCKROACH_USER=tfs --env COCKROACH_PASSWORD=tfs123 \ --volume "crdb:/cockroach/cockroach-data" \ cockroachdb/cockroach:latest-v22.2 start-single-node - - | + - > docker run --name nats -d --network=teraflowbridge -p 4222:4222 -p 8222:8222 \ nats:2.9 --http_port 8222 --user tfs --pass tfs123 - echo "Waiting for initialization..." - while ! docker logs crdb 2>&1 | grep -q 'finished creating default user "tfs"'; do sleep 1; done - - docker logs crdb - while ! docker logs nats 2>&1 | grep -q 'Server is ready'; do sleep 1; done - - docker logs nats - - docker ps -a - CRDB_ADDRESS=$(docker inspect crdb --format "{{.NetworkSettings.Networks.teraflowbridge.IPAddress}}") - - echo $CRDB_ADDRESS - NATS_ADDRESS=$(docker inspect nats --format "{{.NetworkSettings.Networks.teraflowbridge.IPAddress}}") - - echo $NATS_ADDRESS - - | + - echo "CRDB Address: $CRDB_ADDRESS" + - echo "NATS Address: $NATS_ADDRESS" + - > docker run --name context -d -p 1010:1010 \ --env "CRDB_URI=cockroachdb://tfs:tfs123@${CRDB_ADDRESS}:26257/tfs_test?sslmode=require" \ --env "MB_BACKEND=nats" \ @@ -101,34 +103,33 @@ unit_test service: --network=teraflowbridge \ $CI_REGISTRY_IMAGE/context:$IMAGE_TAG - CONTEXTSERVICE_SERVICE_HOST=$(docker inspect context --format "{{.NetworkSettings.Networks.teraflowbridge.IPAddress}}") - - echo $CONTEXTSERVICE_SERVICE_HOST - - | + - echo "Context Service Host: $CONTEXTSERVICE_SERVICE_HOST" + - > # Device preparation docker run --name device -d -p 2020:2020 \ --env "CONTEXTSERVICE_SERVICE_HOST=${CONTEXTSERVICE_SERVICE_HOST}" \ --network=teraflowbridge \ $CI_REGISTRY_IMAGE/device:$IMAGE_TAG - DEVICESERVICE_SERVICE_HOST=$(docker inspect device --format "{{.NetworkSettings.Networks.teraflowbridge.IPAddress}}") - - echo $DEVICESERVICE_SERVICE_HOST - - | + - echo "Device Service Host: $DEVICESERVICE_SERVICE_HOST" + - > # PathComp preparation docker run --name pathcomp-backend -d -p 8081:8081 \ --network=teraflowbridge \ $CI_REGISTRY_IMAGE/pathcomp-backend:$IMAGE_TAG - PATHCOMP_BACKEND_HOST=$(docker inspect pathcomp-backend --format "{{.NetworkSettings.Networks.teraflowbridge.IPAddress}}") - - echo $PATHCOMP_BACKEND_HOST - - sleep 1 - - | + - echo "PathComp Backend Host: $PATHCOMP_BACKEND_HOST" + - > docker run --name pathcomp-frontend -d -p 10020:10020 \ --env "CONTEXTSERVICE_SERVICE_HOST=${CONTEXTSERVICE_SERVICE_HOST}" \ --env "PATHCOMP_BACKEND_HOST=${PATHCOMP_BACKEND_HOST}" \ --env "PATHCOMP_BACKEND_PORT=8081" \ --network=teraflowbridge \ $CI_REGISTRY_IMAGE/pathcomp-frontend:$IMAGE_TAG - - sleep 1 + - sleep 5 - PATHCOMPSERVICE_SERVICE_HOST=$(docker inspect pathcomp-frontend --format "{{.NetworkSettings.Networks.teraflowbridge.IPAddress}}") - - echo $PATHCOMPSERVICE_SERVICE_HOST - - | + - echo "PathComp Frontend Host: $PATHCOMPSERVICE_SERVICE_HOST" + - > # Service preparation docker run --name $IMAGE_NAME -d -p 3030:3030 \ --env "CONTEXTSERVICE_SERVICE_HOST=${CONTEXTSERVICE_SERVICE_HOST}" \ @@ -144,49 +145,49 @@ unit_test service: - docker logs pathcomp-frontend - docker logs pathcomp-backend - docker logs $IMAGE_NAME - - | + - > # Run the tests docker exec -i $IMAGE_NAME bash -c \ "coverage run -m pytest --log-level=INFO --verbose $IMAGE_NAME/tests/test_unitary.py --junitxml=/opt/results/${IMAGE_NAME}_report.xml" - docker exec -i $IMAGE_NAME bash -c "coverage report --include='${IMAGE_NAME}/*' --show-missing" - echo "Starting stage: deploy_mock_nodes" - - | + - > for port in 11111 22222 33333; do if lsof -i:$port >/dev/null 2>&1; then - echo "Freeing up port $port..." - fuser -k $port/tcp - fi + echo "Freeing up port $port..."; + fuser -k $port/tcp; + fi; done - MOCK_NODES_DIR="$PWD/src/tests/tools/mock_qkd_nodes" - - | + - > if [ -d "$MOCK_NODES_DIR" ]; then - cd "$MOCK_NODES_DIR" || exit - ./start.sh & - MOCK_NODES_PID=$! + cd "$MOCK_NODES_DIR" || exit; + ./start.sh &; + MOCK_NODES_PID=$!; else - echo "Error: Mock QKD nodes directory '$MOCK_NODES_DIR' not found." - exit 1 + echo "Error: Mock QKD nodes directory '$MOCK_NODES_DIR' not found."; + exit 1; fi - echo "Waiting for mock nodes to be up..." - RETRY_COUNT=0 - MAX_RETRIES=15 - - | + - > while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do if curl -s http://127.0.0.1:11111 > /dev/null && \ curl -s http://127.0.0.1:22222 > /dev/null && \ curl -s http://127.0.0.1:33333 > /dev/null; then - echo "Mock nodes are up!" - break + echo "Mock nodes are up!"; + break; else - echo "Mock nodes not ready, retrying in 5 seconds..." - RETRY_COUNT=$((RETRY_COUNT + 1)) - sleep 5 - fi + echo "Mock nodes not ready, retrying in 5 seconds..."; + RETRY_COUNT=$((RETRY_COUNT + 1)); + sleep 5; + fi; done - - | + - > if [ $RETRY_COUNT -ge $MAX_RETRIES ]; then - echo "Error: Mock nodes failed to start after multiple attempts." - exit 1 + echo "Error: Mock nodes failed to start after multiple attempts."; + exit 1; fi - docker exec -i $IMAGE_NAME bash -c "coverage run --append -m pytest --log-level=INFO --verbose service/tests/qkd/test_functional_bootstrap.py" coverage: '/TOTAL\s+\d+\s+\d+\s+(\d+%)/' @@ -219,9 +220,9 @@ unit_test service: - manifests/${IMAGE_NAME}service.yaml - .gitlab-ci.yml artifacts: - when: always - reports: - junit: src/$IMAGE_NAME/tests/${IMAGE_NAME}_report.xml + when: always + reports: + junit: src/$IMAGE_NAME/tests/${IMAGE_NAME}_report.xml ## Deployment of the service in Kubernetes Cluster #deploy service: @@ -247,4 +248,4 @@ unit_test service: # - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH)' # when: manual # - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "develop"' -# when: manual \ No newline at end of file +# when: manual