diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ce1c4e4bf9c7c37bf5fa128361cd89938c5e6d2f..56d7db9a9e5a75c53e1956d6c1dd15e2f6405091 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,14 +1,21 @@ image: gitlab-registry.cern.ch/linuxsupport/alma9-base +include: + - project : 'ci-tools/container-image-ci-templates' + file : 'helm.gitlab-ci.yml' + ref: master + stages: - lint - test - build - - tag - - release + - deploy docs_lint: stage: lint + rules: + - if: '$CI_COMMIT_TAG' + when: never script: - dnf install -y python-pip - python3 -m pip install linkcheckmd @@ -17,6 +24,9 @@ docs_lint: yaml_lint: stage: lint + rules: + - if: '$CI_COMMIT_TAG' + when: never script: - dnf install -y epel-release - dnf install -y yamllint @@ -24,6 +34,9 @@ yaml_lint: helm_lint: stage: lint + rules: + - if: '$CI_COMMIT_TAG' + when: never image: alpine/helm script: - helm dep update . @@ -32,22 +45,25 @@ helm_lint: version_test: stage: test rules: - - if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "qa"' - changes: - paths: - - Chart.yaml - - values.yaml - - templates/* + - if: '$CI_COMMIT_TAG' script: | - dnf install -y python3-pip - pip install yq - MASTER_VERSION=$(curl https://gitlab.cern.ch/monitoring/helm-charts/kubernetes-monitoring/-/raw/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME/Chart.yaml?ref_type=heads | yq .version) - LOCAL_VERSION=$(cat Chart.yaml | yq .version) - if [ $MASTER_VERSION == $LOCAL_VERSION ]; then - echo "Please, update Chart.yaml version before merge." - exit -1 + # Installing helm... + dnf install -y diffutils wget tar + wget https://get.helm.sh/helm-v3.15.3-linux-386.tar.gz + tar -zxvf helm-v3.15.3-linux-386.tar.gz + mv linux-386/helm /usr/local/bin/helm + rm helm-v3.15.3-linux-386.tar.gz + rm -rf linux-386 + + # Check if the tag already exists in harbor to avoid overrides. + if helm pull oci://registry.cern.ch/monit/cern-it-kubernetes-monitoring --version $CI_COMMIT_TAG; then + # Command was successful (exit code 0), so the tag exists + echo "The tag $TAG already exists in harbor. Please update it." + exit 1 # Exit with non-zero status to indicate tag exists else - echo "Chart version changed from $MASTER_VERSION to $LOCAL_VERSION." + # Command failed (non-zero exit code), so the tag does not exist + echo "The tag $TAG does not exist in harbor. All ok..." + exit 0 # Exit with 0 status fi helm_test: @@ -141,3 +157,21 @@ helm_test: echo "Deleting temporal cluster." openstack coe cluster delete $CLUSTER_NAME + +helm_deploy: + stage: deploy + needs: + - version_test + rules: + - if: '$CI_COMMIT_TAG' + script: | + dnf install -y diffutils wget tar + wget https://get.helm.sh/helm-v3.15.3-linux-386.tar.gz + tar -zxvf helm-v3.15.3-linux-386.tar.gz + mv linux-386/helm /usr/local/bin/helm + rm helm-v3.15.3-linux-386.tar.gz + rm -rf linux-386 + sed -i "s/^version:.*/version: ${CI_COMMIT_TAG}/" Chart.yaml + helm package . + echo $REGISTRY_PASSWORD | helm registry login https://registry.cern.ch/v2/ -u $REGISTRY_USER --password-stdin + helm push cern-it-kubernetes-monitoring-$CI_COMMIT_TAG.tgz oci://registry.cern.ch/monit diff --git a/Chart.yaml b/Chart.yaml index cbb8dfc0a6e88a731c3a85d4714edde55798a80c..b30ba1c8fb217a85a6484eda52a293c34a9d49c2 100644 --- a/Chart.yaml +++ b/Chart.yaml @@ -1,7 +1,7 @@ apiVersion: v2 name: cern-it-kubernetes-monitoring +version: 0.0.0 # DO NOT UPDATE MANUALLY! type: application -version: 0.2.0 kubeVersion: ">=1.27.0-0" description: Helm Chart provided by IT Monitoring Service to install and configure required components to gather and send monitoring data from kubernetes clusters to central service. home: https://cern.ch/monitoring