From aa8b860d643e7371e20650b413d377bdb5700f64 Mon Sep 17 00:00:00 2001 From: Sergio <sergio.gonzalez.diaz@atos.net> Date: Mon, 9 Aug 2021 13:35:40 +0200 Subject: [PATCH] test deployment in k8s of the monitoring service --- ...monitoringservice.yaml => monitoring.yaml} | 12 ++--- src/monitoring/.gitlab-ci.yml | 49 +++++++++++-------- 2 files changed, 35 insertions(+), 26 deletions(-) rename manifests/{monitoringservice.yaml => monitoring.yaml} (81%) diff --git a/manifests/monitoringservice.yaml b/manifests/monitoring.yaml similarity index 81% rename from manifests/monitoringservice.yaml rename to manifests/monitoring.yaml index bf886f4f9..f115e5f16 100644 --- a/manifests/monitoringservice.yaml +++ b/manifests/monitoring.yaml @@ -1,20 +1,20 @@ apiVersion: apps/v1 kind: Deployment metadata: - name: monitoringservice + name: monitoring spec: selector: matchLabels: - app: monitoringservice + app: monitoring template: metadata: labels: - app: monitoringservice + app: monitoring spec: terminationGracePeriodSeconds: 5 containers: - name: server - image: myregistrydomain.com/monitoringservice + image: registry.gitlab.com/teraflow-h2020/controller/monitoring:latest ports: - containerPort: 8080 env: @@ -39,11 +39,11 @@ spec: apiVersion: v1 kind: Service metadata: - name: monitoringservice + name: monitoring spec: type: ClusterIP selector: - app: monitoringservice + app: monitoring ports: - name: grpc port: 8080 diff --git a/src/monitoring/.gitlab-ci.yml b/src/monitoring/.gitlab-ci.yml index 27a0f3b85..3a99ce18a 100644 --- a/src/monitoring/.gitlab-ci.yml +++ b/src/monitoring/.gitlab-ci.yml @@ -2,7 +2,6 @@ build monitoring: variables: IMAGE_NAME: 'monitoring' # name of the microservice - IMAGE_NAME_TEST: 'monitoring-test' # name of the microservice IMAGE_TAG: 'latest' # tag of the container image (production, development, etc) stage: build before_script: @@ -17,13 +16,13 @@ build monitoring: - src/$IMAGE_NAME/Dockerfile - src/$IMAGE_NAME/tests/*.py - src/$IMAGE_NAME/tests/Dockerfile + - manifests/$IMAGE_NAME.yaml - .gitlab-ci.yml # test if the Docker image can be pulled from the gitlab registry test monitoring pull: variables: IMAGE_NAME: 'monitoring' # name of the microservice - IMAGE_NAME_TEST: 'monitoring-test' # name of the microservice IMAGE_TAG: 'latest' # tag of the container image (production, development, etc) stage: test needs: @@ -38,13 +37,13 @@ test monitoring pull: - src/$IMAGE_NAME/Dockerfile - src/$IMAGE_NAME/tests/*.py - src/$IMAGE_NAME/tests/Dockerfile + - manifests/$IMAGE_NAME.yaml - .gitlab-ci.yml # test if the Docker image can be executed test monitoring run: variables: IMAGE_NAME: 'monitoring' # name of the microservice - IMAGE_NAME_TEST: 'monitoring-test' # name of the microservice IMAGE_TAG: 'latest' # tag of the container image (production, development, etc) stage: test needs: @@ -52,7 +51,7 @@ test monitoring run: before_script: - if docker network list | grep teraflowbridge; then echo "teraflowbridge is already created"; else docker network create -d bridge teraflowbridge; fi script: - - docker run -d -p 7070:7070 --name monitoring --network=teraflowbridge --rm "$IMAGE_NAME:$IMAGE_TAG" + - docker run -d -p 7070:7070 --name $IMAGE_NAME --network=teraflowbridge --rm "$IMAGE_NAME:$IMAGE_TAG" - docker ps after_script: - docker stop monitoring @@ -62,6 +61,7 @@ test monitoring run: - src/$IMAGE_NAME/Dockerfile - src/$IMAGE_NAME/tests/*.py - src/$IMAGE_NAME/tests/Dockerfile + - manifests/$IMAGE_NAME.yaml - .gitlab-ci.yml # apply unit test to the monitoring component @@ -75,33 +75,42 @@ test monitoring pytest: - build monitoring script: - docker build -t "$IMAGE_NAME_TEST:$IMAGE_TAG" -f ./src/$IMAGE_NAME/tests/Dockerfile ./src/ - - docker run -v "$PWD/src/monitoring/tests:/opt/results" monitoring-test:latest + - docker run -v "$PWD/src/$IMAGE_NAME/tests:/opt/results" $IMAGE_NAME_TEST:$IMAGE_TAG rules: - changes: - src/$IMAGE_NAME/*.{py,in,yml} - src/$IMAGE_NAME/Dockerfile - src/$IMAGE_NAME/tests/*.py - src/$IMAGE_NAME/tests/Dockerfile + - manifests/$IMAGE_NAME.yaml - .gitlab-ci.yml artifacts: when: always reports: - junit: src/monitoring/tests/report.xml + junit: src/$IMAGE_NAME/tests/report.xml # Deployment of the monitoring service in Kubernetes Cluster -#deploy monitoring development: -# variables: -# IMAGE_NAME: 'monitoring' # name of the microservice -# IMAGE_TAG: 'latest' # tag of the container image (production, development, etc) -# stage: deploy -# needs: -# - build monitoring -# - test monitoring run -# script: -# - kubectl version -# - kubectl get all -# - kubectl apply -f "manifests/monitoringservice.yaml" -# - kubectl get all -# when: manual +deploy monitoring development: + variables: + IMAGE_NAME: 'monitoring' # name of the microservice + IMAGE_TAG: 'latest' # tag of the container image (production, development, etc) + stage: deploy + needs: + - build monitoring + - test monitoring run + script: + - kubectl version + - kubectl get all + - kubectl apply -f "manifests/$IMAGE_NAME.yaml" + - kubectl get all + when: manual + rules: + - changes: + - src/$IMAGE_NAME/*.{py,in,yml} + - src/$IMAGE_NAME/Dockerfile + - src/$IMAGE_NAME/tests/*.py + - src/$IMAGE_NAME/tests/Dockerfile + - manifests/$IMAGE_NAME.yaml + - .gitlab-ci.yml -- GitLab