From f6585ef5ccc878f7d62189ab88fc2468eb02a4e9 Mon Sep 17 00:00:00 2001
From: Lluis Gifre <lluis.gifre@cttc.es>
Date: Thu, 5 Aug 2021 15:59:53 +0200
Subject: [PATCH] Corrections in device and context GitLab CI pipelines

---
 src/context/.gitlab-ci.yml   | 16 ++++++----------
 src/context/tests/Dockerfile |  2 +-
 src/device/.gitlab-ci.yml    | 16 ++++++----------
 src/device/tests/Dockerfile  |  2 +-
 4 files changed, 14 insertions(+), 22 deletions(-)

diff --git a/src/context/.gitlab-ci.yml b/src/context/.gitlab-ci.yml
index 8c80196ac..feb894bf1 100644
--- a/src/context/.gitlab-ci.yml
+++ b/src/context/.gitlab-ci.yml
@@ -11,16 +11,13 @@ build context:
     - docker build -t "$IMAGE_NAME:$IMAGE_TAG" -f ./src/$IMAGE_NAME/Dockerfile ./src/
     - docker tag "$IMAGE_NAME:$IMAGE_TAG" "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG"
     - docker push "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG"
-    - docker build -t "$IMAGE_NAME_TEST:$IMAGE_TAG" -f ./src/$IMAGE_NAME/tests/Dockerfile ./src/
-    - docker tag "$IMAGE_NAME_TEST:$IMAGE_TAG" "$CI_REGISTRY_IMAGE/$IMAGE_NAME_TEST:$IMAGE_TAG"
-    - docker push "$CI_REGISTRY_IMAGE/$IMAGE_NAME_TEST:$IMAGE_TAG"
   rules:
     - changes:
       - src/$IMAGE_NAME/**
       - .gitlab-ci.yml
 
-# Pull, execute, and test the Docker image from the GitLab registry
-test context:
+# Pull, execute, and run unitary tests for the Docker image from the GitLab registry
+test unitary context:
   variables:
     IMAGE_NAME: 'context' # name of the microservice
     IMAGE_NAME_TEST: 'context-test' # name of the microservice
@@ -34,10 +31,9 @@ test context:
   script:
     - docker pull "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG"
     - docker run -d -p 1010:1010 --name $IMAGE_NAME --network=teraflowbridge --rm "$IMAGE_NAME:$IMAGE_TAG"
-    - docker ps > deploy_test_report.txt
-    - docker run -d --name $IMAGE_NAME_TEST --network=teraflowbridge --rm "$IMAGE_NAME_TEST:$IMAGE_TAG" > pytest_report.txt
+    - docker ps > $IMAGE_NAME--deploy_test_report.txt
+    - docker exec -i $IMAGE --network=teraflowbridge "pytest --log-level=DEBUG --verbose $IMAGE_NAME/tests/test_unitary.py" > $IMAGE_NAME--pytest_unitary_report.txt
   after_script:
-    - docker stop $IMAGE_NAME_TEST
     - docker stop $IMAGE_NAME
   rules:
     - changes:
@@ -46,8 +42,8 @@ test context:
   artifacts:
     when: always
     paths:
-      - deploy_test_report.txt
-      - pytest_report.txt
+      - $IMAGE_NAME--deploy_test_report.txt
+      - $IMAGE_NAME--pytest_unitary_report.txt
     expire_in: 1 day
 
 # Deployment of the monitoring service in Kubernetes Cluster
diff --git a/src/context/tests/Dockerfile b/src/context/tests/Dockerfile
index 5487a3ac9..ed70aa86e 100644
--- a/src/context/tests/Dockerfile
+++ b/src/context/tests/Dockerfile
@@ -1,4 +1,4 @@
-FROM context_service:develop
+FROM context:latest
 
 # Run integration tests
 ENTRYPOINT ["pytest", "-v", "--log-level=DEBUG", "context/tests/test_integration.py"]
diff --git a/src/device/.gitlab-ci.yml b/src/device/.gitlab-ci.yml
index d2840502a..c8e7716e0 100644
--- a/src/device/.gitlab-ci.yml
+++ b/src/device/.gitlab-ci.yml
@@ -11,16 +11,13 @@ build device:
     - docker build -t "$IMAGE_NAME:$IMAGE_TAG" -f ./src/$IMAGE_NAME/Dockerfile ./src/
     - docker tag "$IMAGE_NAME:$IMAGE_TAG" "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG"
     - docker push "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG"
-    - docker build -t "$IMAGE_NAME_TEST:$IMAGE_TAG" -f ./src/$IMAGE_NAME/tests/Dockerfile ./src/
-    - docker tag "$IMAGE_NAME_TEST:$IMAGE_TAG" "$CI_REGISTRY_IMAGE/$IMAGE_NAME_TEST:$IMAGE_TAG"
-    - docker push "$CI_REGISTRY_IMAGE/$IMAGE_NAME_TEST:$IMAGE_TAG"
   rules:
     - changes:
       - src/$IMAGE_NAME/**
       - .gitlab-ci.yml
 
-# Pull, execute, and test the Docker image from the GitLab registry
-test device:
+# Pull, execute, and run unitary tests for the Docker image from the GitLab registry
+test unitary device:
   variables:
     IMAGE_NAME: 'device' # name of the microservice
     IMAGE_NAME_TEST: 'device-test' # name of the microservice
@@ -34,10 +31,9 @@ test device:
   script:
     - docker pull "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG"
     - docker run -d -p 1010:1010 --name $IMAGE_NAME --network=teraflowbridge --rm "$IMAGE_NAME:$IMAGE_TAG"
-    - docker ps > deploy_test_report.txt
-    - docker run -d --name $IMAGE_NAME_TEST --network=teraflowbridge --rm "$IMAGE_NAME_TEST:$IMAGE_TAG" > pytest_report.txt
+    - docker ps > $IMAGE_NAME--deploy_test_report.txt
+    - docker exec -i $IMAGE --network=teraflowbridge "pytest --log-level=DEBUG --verbose $IMAGE_NAME/tests/test_unitary.py" > $IMAGE_NAME--pytest_unitary_report.txt
   after_script:
-    - docker stop $IMAGE_NAME_TEST
     - docker stop $IMAGE_NAME
   rules:
     - changes:
@@ -46,8 +42,8 @@ test device:
   artifacts:
     when: always
     paths:
-      - deploy_test_report.txt
-      - pytest_report.txt
+      - $IMAGE_NAME--deploy_test_report.txt
+      - $IMAGE_NAME--pytest_unitary_report.txt
     expire_in: 1 day
 
 # Deployment of the monitoring service in Kubernetes Cluster
diff --git a/src/device/tests/Dockerfile b/src/device/tests/Dockerfile
index b1f6411c3..e8789ce74 100644
--- a/src/device/tests/Dockerfile
+++ b/src/device/tests/Dockerfile
@@ -1,4 +1,4 @@
-FROM device_service:develop
+FROM device:latest
 
 # Run integration tests
 ENTRYPOINT ["pytest", "-v", "--log-level=DEBUG", "device/tests/test_integration.py"]
-- 
GitLab