Commit ebeae7b6 authored by Alexandros Valantasis's avatar Alexandros Valantasis
Browse files

Merge branch 'refactor-telemetry' into 'main'

Refactor telemetry

See merge request maestro-v2/mdg-hypo/org.etsi.osl.hypo.clients/org.etsi.osl.hypo.clients.telemetry!1
parents de2a3ae2 314997f6
Loading
Loading
Loading
Loading

.ci-settings.xml

0 → 100644
+17 −0
Original line number Diff line number Diff line
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
  <servers>
    <server>
      <id>gitlab-maven</id>
      <configuration>
        <httpHeaders>
          <property>
            <name>Job-Token</name>
            <value>${env.CI_JOB_TOKEN}</value>
          </property>
        </httpHeaders>
      </configuration>
    </server>
  </servers>
</settings>

.dockerignore

0 → 100644
+5 −0
Original line number Diff line number Diff line
*
!target/*-runner
!target/*-runner.jar
!target/lib/*
!target/quarkus-app/*
 No newline at end of file

.env.example

0 → 100644
+9 −0
Original line number Diff line number Diff line
QUARKUS_APPLICATION_NAME=telemetry-api
QUARKUS_APPLICATION_ROOT_NAME=telemetry-services
QUARKUS_APPLICATION_PORT=8089
QUARKUS_APPLICATION_PORT_EXPORT=8089


# Image
TELEMETRY_MANAGEMENT_IMAGE_NAME=registry.ubitech.eu/maestro-v2/io.maestro.clients/io.maestro.clients.telemetry/telemetry-api-jvm
TELEMETRY_MANAGEMENT_IMAGE_VERSION=latest
 No newline at end of file

.gitignore

0 → 100644
+45 −0
Original line number Diff line number Diff line
#Maven
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
release.properties
.flattened-pom.xml

# Eclipse
.project
.classpath
.settings/
bin/

# IntelliJ
.idea
*.ipr
*.iml
*.iws

# NetBeans
nb-configuration.xml

# Visual Studio Code
.vscode
.factorypath

# OSX
.DS_Store

# Vim
*.swp
*.swo

# patch
*.orig
*.rej

# Local environment
.env

# Plugin directory
/.quarkus/cli/plugins/
# TLS Certificates
.certs/

.gitlab-ci.yml

0 → 100644
+311 −0
Original line number Diff line number Diff line
stages:
  - dev_test
  - dev_verify
  - dev_measure_quality
  - dev_package
  - dev_image_build
  - dev_deploy
  - dev_workflows
  - prod_extract_next_release
  - prod_package
  - prod_release
  - prod_image_build_release

default:
  image: registry.ubitech.eu/nsit/maestro-apps/maven:3.8.3-openjdk-17

variables:
  DOCKER_HOST: tcp://docker:2375
  DOCKER_TLS_CERTDIR: ""
  DOCKER_DRIVER: overlay2
  DOCKER_API_VERSION: "1.41"
  TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX: "registry.ubitech.eu/nsit/maestro-apps/"
  IMAGE_NAME: "telemetry-api-jvm"
  MAVEN_REPO: "${CI_PROJECT_ROOT_NAMESPACE}/.m2/repository"
  MAVEN_OPTS: "-Dmaven.repo.local=${CI_PROJECT_ROOT_NAMESPACE}/.m2/repository"
  COVERAGE_CONSOLIDATED_JACOCO_XML: "target/site/jacoco/jacoco.xml"
  SONAR_USER_HOME: "${CI_PROJECT_ROOT_NAMESPACE}/${CI_PROJECT_NAME}/.sonar"
  MAVEN_CLI_OPTS_SONAR: "-s .ci-settings.xml --no-transfer-progress"
  MAVEN_CLI_OPTS: "-s .ci-settings.xml --no-transfer-progress"

cache:
  key: "${CI_PROJECT_ROOT_NAMESPACE}"
  paths:
    - .m2/repository/
    - ${SONAR_USER_HOME}/cache


dev_tests_job:
  stage: dev_test
  image: registry.ubitech.eu/nsit/maestro-apps/maven:3.8.3-openjdk-17-slim
  services:
    - name: registry.ubitech.eu/nsit/maestro-apps/docker:20.10.16-dind
      command: [ "--tls=false" ]
      alias: docker
  before_script:
    - curl -fsSL https://get.docker.com -o get-docker.sh
    - chmod +x ./get-docker.sh
    - ./get-docker.sh
    - docker info
    - echo "$MAESTRO_APPS_TOKEN" | docker login $MAESTRO_APPS_REGISTRY -u $MAESTRO_APPS_USER --password-stdin
    - touch ~/.testcontainers.properties
    - echo "ryuk.container.privileged=true" > ~/.testcontainers.properties
  script:
    - chmod +x ./mvnw
    - ./mvnw ${MAVEN_CLI_OPTS} test ${MAVEN_OPTS}
  artifacts:
    # Upload artifacts even if job fails.
    when: always
    paths:
      - target/jacoco.exec
    expire_in: 1 hour
    reports:
      junit:
        - target/surefire-reports/TEST-*.xml
  except:
    - main
    - tags


dev_verify_job:
  stage: dev_verify
  image: registry.ubitech.eu/nsit/maestro-apps/maven:3.8.3-openjdk-17
  services:
    - name: registry.ubitech.eu/nsit/maestro-apps/docker:20.10.16-dind
      command: [ "--tls=false" ]
      alias: docker
  script:
    - chmod +x ./mvnw
    -  ./mvnw ${MAVEN_CLI_OPTS} post-integration-test failsafe:verify -DskipUTs ${MAVEN_OPTS}
  artifacts:
    paths:
      - target/**
  dependencies:
     - dev_tests_job
  except:
    - main
    - tags


dev_measure_quality_job:
  stage: dev_measure_quality
  # Needs init_job to retrieve ENV variables.
  needs:
    - dev_tests_job
    - dev_verify_job
  dependencies:
    - dev_tests_job
    - dev_verify_job
  # As per https://docs.sonarqube.org/8.8/analysis/gitlab-integration/
  variables:
    GIT_DEPTH: "0"  # Tells git to fetch all the branches of the project, required by the analysis task
  script:
    # -Dsonar.qualitygate.wait=true fails the build if SonarQube quality gate fails
    - mvn ${MAVEN_CLI_OPTS_SONAR} verify sonar:sonar -Dsonar.host.url=${SONAR_HOST_URL} -Pgenerate-consolidated-coverage -DskipUTs -DskipITs -Dsonar.qualitygate.wait=true
    - cat target/site/jacoco/index.html | grep -o 'Total[^%]*%' | sed 's/<.*>/ /; s/Total/JaCoCo Coverage Total:/'
  allow_failure: true
  coverage: '/JaCoCo Coverage Total: ([0-9]{1,3})%/'
  artifacts:
    when: always
    paths:
      - ${COVERAGE_CONSOLIDATED_JACOCO_XML}
    expire_in: 1 day
  except:
    - tags
    - main


dev_package_job:
  stage: dev_package
  script:
    - chmod +x ./mvnw
    - ./mvnw ${MAVEN_CLI_OPTS} clean package -DskipITs -DskipUTs -DskipTests ${MAVEN_OPTS}
  artifacts:
    paths:
      - target/**
  rules:
    - if: ' $CI_PIPELINE_SOURCE == "merge_request_event"'

dev_image_build_job:
  stage: dev_image_build
  image:
    name: registry.ubitech.eu/nsit/maestro-apps/docker:20.10.16
    pull_policy: [always, if-not-present]
  services:
    - name: registry.ubitech.eu/nsit/maestro-apps/docker:20.10.16-dind
      command: [ "--tls=false" ]
      alias: docker
  before_script:
    - docker info > /dev/null
  script:
    - echo -n $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY
    - docker build -t $CI_REGISTRY/$CI_PROJECT_PATH/$IMAGE_NAME:$CI_COMMIT_SHORT_SHA -f src/main/docker/Dockerfile.jvm .
    - IMAGE_ID=$(docker images | grep $CI_REGISTRY/$CI_PROJECT_PATH\/$IMAGE_NAME | awk '{print $3}')
    - docker push $CI_REGISTRY/$CI_PROJECT_PATH/$IMAGE_NAME:$CI_COMMIT_SHORT_SHA
  dependencies:
    - dev_package_job
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'


dev_deploy_job:
  stage: dev_deploy
  image:
    name: registry.ubitech.eu/nsit/maestro-apps/python-argocd:3.9
    pull_policy: [always, if-not-present]
  before_script:
    - git clone --depth 1 --branch gitops-cd https://oauth2:$INSTALLER_TOKEN@$INSTALLER_REPO
    - cd io.maestro.installer.orchestrator.helm

  script:
    - python3 scripts/helm_update.py $CI_REGISTRY/$CI_PROJECT_PATH/$IMAGE_NAME:$CI_COMMIT_SHORT_SHA $DEV_SONATA_CORE_IMAGE $DEV_SONATA_OSS_IMAGE $DEV_SONATA_HELM_IMAGE $DEV_ZTC_CLIENT_IMAGE $DEV_PORTAL_CART_IMAGE $DEV_TMF_API_IMAGE $DEV_PEERING_IMAGE $DEV_REGISTRY_IMAGE $DEV_FABRIC_IMAGE $DEV_PORTAL
    - git add .
    - git config --global user.email "$GITLAB_USER_NAME"
    - git config --global user.name "$GITLAB_USER_EMAIL"

    - |
      if git commit -m "Update values.yaml for GitOps CD [skip ci]"; then
        git push origin gitops-cd
      else
        echo "No changes to commit."
      fi

    - |
      set -e
      argocd login "$ARGOCD_SERVER" --username "$ARGOCD_USERNAME" --password "$ARGOCD_PASSWORD" --insecure
      argocd app get maestro --refresh >/dev/null
      argocd app wait maestro --sync --health --timeout 120
      echo "Argo CD application 'maestro' is synced and healthy."

  dependencies:
     - dev_image_build_job
  rules:
     - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'



dev_workflows_job:
  stage: dev_workflows
  image:
    name: registry.ubitech.eu/nsit/maestro-apps/newman-ci:latest
  before_script:
    - git clone --depth 1 https://oauth2:$COLLECTION_TOKEN@$COLLECTION_REPO
    - cp io.maestro.cd.collections/files/collection.json .
    - cp io.maestro.cd.collections/files/env.json .
  script:
    - newman run collection.json --environment env.json
  dependencies:
    - dev_deploy_job
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'


prod_extract_next_release_job:
  image: 
    name: registry.ubitech.eu/nsit/maestro-apps/node:lts
  stage: prod_extract_next_release
  variables:
    GITLAB_TOKEN: $GITLAB_TOKEN_SEMANTIC_VERSIONING
  before_script:
    - node --version
  script:
    - DEV_RELEASE_VERSION=$(npx -y
      -p @semantic-release/commit-analyzer@9.0.2
      -p @semantic-release/git@10.0.1
      -p @semantic-release/gitlab@9.5.0
      -p @semantic-release/release-notes-generator@10.0.3
      -p @semantic-release/exec@6.0.3
      -p @semantic-release/changelog@6.0.2
      -p conventional-changelog-conventionalcommits@5.0.0
      -p semantic-release@19.0.5
      semantic-release --dry-run | grep -oP '(?<=Published release ).*' | awk '{print $1}' || echo "no-release" )
    - echo "$DEV_RELEASE_VERSION" > dev_release_version.txt
    - cat dev_release_version.txt
  artifacts:
    paths:
      - dev_release_version.txt
  only:
    - main

   
prod_package_job:
  stage: prod_package
  dependencies:
    - prod_extract_next_release_job
  script:
    - DEV_RELEASE_VERSION=$(cat dev_release_version.txt)
    - echo  $DEV_RELEASE_VERSION
    - if [ "$DEV_RELEASE_VERSION" = "no-release" ]; then exit 0; fi
    - chmod +x ./mvnw
    - ./mvnw ${MAVEN_CLI_OPTS}  -q versions:set -DnewVersion=$DEV_RELEASE_VERSION
    - ./mvnw ${MAVEN_CLI_OPTS} -q -Dexec.executable="echo" -Dexec.args='${project.version}' --non-recursive exec:exec
    - ./mvnw ${MAVEN_CLI_OPTS} clean package -DskipITs -DskipUTs -DskipTests ${MAVEN_OPTS}
    - git add pom.xml
    - git status
    - git config --global user.email $GITLAB_USER_EMAIL
    - git config --global user.name $GITLAB_USER_NAME
    - |
      if git commit -m "Release $DEV_RELEASE_VERSION: Update project version [skip ci]"; then
        git remote set-url origin "https://${GITLAB_USER_NAME}:${GITLAB_TOKEN_SEMANTIC_VERSIONING}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git"
        git push -f origin HEAD:main
      else
        echo "No changes to commit."
      fi
  artifacts:
    paths:
      - target/**
  only:
    - main

prod_semantic_versioning_job:
  image: 
    name: registry.ubitech.eu/nsit/maestro-apps/node:lts
  stage: prod_release
  variables:
    GITLAB_TOKEN: $GITLAB_TOKEN_SEMANTIC_VERSIONING
  before_script:
    - git pull origin HEAD
  script:
    - RELEASE_VERSION=$(npx -y
      -p @semantic-release/commit-analyzer@9.0.2
      -p @semantic-release/git@10.0.1
      -p @semantic-release/gitlab@9.5.0
      -p @semantic-release/release-notes-generator@10.0.3
      -p @semantic-release/exec@6.0.3
      -p @semantic-release/changelog@6.0.2
      -p conventional-changelog-conventionalcommits@5.0.0
      -p semantic-release@19.0.5
      semantic-release | grep -oP '(?<=Published release ).*' | awk '{print $1}' || echo "no-release" )
    - echo "$RELEASE_VERSION" > release_version.txt
    - cat release_version.txt
  artifacts:
    paths:
      - release_version.txt
  only:
    - main

prod_image_build_and_release_job:
  stage: prod_image_build_release
  image:
    name: registry.ubitech.eu/nsit/maestro-apps/docker:20.10.16
  services:
    - name: registry.ubitech.eu/nsit/maestro-apps/docker:20.10.16-dind
      command: [ "--tls=false" ]
      alias: docker
  before_script:
    - docker info > /dev/null
    - RELEASE_VERSION=$(cat release_version.txt)
    - echo  $RELEASE_VERSION
    - if [ "$RELEASE_VERSION" = "no-release" ]; then exit 0; fi
  script:
    - echo -n $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY
    - docker build -t $CI_REGISTRY/$CI_PROJECT_PATH/$IMAGE_NAME:latest -f src/main/docker/Dockerfile.jvm .
    - IMAGE_ID=$(docker images | grep $CI_REGISTRY/$CI_PROJECT_PATH\/$IMAGE_NAME | awk '{print $3}')
    - docker tag $IMAGE_ID $CI_REGISTRY/$CI_PROJECT_PATH/$IMAGE_NAME:$RELEASE_VERSION
    - docker push $CI_REGISTRY/$CI_PROJECT_PATH/$IMAGE_NAME:latest
    - docker push $CI_REGISTRY/$CI_PROJECT_PATH/$IMAGE_NAME:$RELEASE_VERSION
  dependencies:
    - prod_semantic_versioning_job
    - prod_package_job
  only:
    - main
Loading