Commit b9b1f38a authored by Jorge Moratinos's avatar Jorge Moratinos
Browse files

Changes on cd-deploy

parent 08830be9
Loading
Loading
Loading
Loading
+21 −13
Original line number Diff line number Diff line
@@ -65,19 +65,27 @@ variables:
    - docker-in-docker

include:
 # Official GitLab CI templates for SAST, Dependency Scanning, Container Scanning and Secret Detection
  - template: 'Jobs/SAST.gitlab-ci.yml'
  - template: 'Jobs/Dependency-Scanning.gitlab-ci.yml'
  - template: 'Jobs/Container-Scanning.gitlab-ci.yml'
  - template: 'Secret-Detection.gitlab-ci.yml'
 - project: 'ocf/pipeline-scripts'
   ref: jms_change
   file: 
   - 'capif/templates/ci_staging.gitlab-ci.yml'
   - 'capif/templates/ci_dev.gitlab-ci.yml'
   - 'capif/templates/ci_unit_test.gitlab-ci.yml'
   - 'capif/templates/cd-deploy-ocf.gitlab-ci.yml'
   - 'capif/templates/cicd-deploy-release.gitlab-ci.yml'
#   - 'capif/templates/ci_main.gitlab-ci.yml'

  # Include internal templates of ocf/pipeline-scripts repository
  - local: 'capif/templates/ci_staging.gitlab-ci.yml'
  - local: 'capif/templates/ci_dev.gitlab-ci.yml'
  - local: 'capif/templates/ci_unit_test.gitlab-ci.yml'
  - local: 'capif/templates/cd-deploy-ocf.gitlab-ci.yml'
  - local: 'capif/templates/cicd-deploy-release.gitlab-ci.yml'
#  - project: 'ocf/pipeline-scripts'
#    ref: jms_change
#    file: 
#    - 'capif/templates/ci_staging.gitlab-ci.yml'
#    - 'capif/templates/ci_dev.gitlab-ci.yml'
#    - 'capif/templates/ci_unit_test.gitlab-ci.yml'
#    - 'capif/templates/cd-deploy-ocf.gitlab-ci.yml'
#    - 'capif/templates/cicd-deploy-release.gitlab-ci.yml'
##   - 'capif/templates/ci_main.gitlab-ci.yml'

#sast:
#  variables:
+584 −337
Original line number Diff line number Diff line
@@ -364,7 +364,7 @@ delete_ocf_staging:
  <<: *staging_common
  script:
    - |
      export NAMESPACE_DEV_TO_STAGING=$(cat cd_env_endpoint.txt)
      # export NAMESPACE_DEV_TO_STAGING=$(cat cd_env_endpoint.txt)
      echo "### deleting environment $NAMESPACE_DEV_TO_STAGING###"

      if [[ -d helm/capif ]]; then
@@ -407,6 +407,7 @@ delete_ocf_staging:

      ## Default values on next variables
      ### Storage configuration
      # export CAPIF_RESOURCES_RESERVE="YES"
      # export CAPIF_STORAGE_CLASS=nfs-01
      # export CAPIF_GRAFANA_STORAGE_SIZE=10Gi
      # export CAPIF_LOKI_STORAGE_SIZE=100Mi
@@ -476,6 +477,9 @@ deploy_ocf_oficial_staging:
      whoami
      kubectl cluster-info
      yq --version

      if [[ -d helm/capif ]]; then
        echo "### helm capif directory exists ###"
        ls -rtt helm/capif
        cat helm/capif/Chart.yaml
        yq e -i ".appVersion = \"staging\"" helm/capif/Chart.yaml
@@ -641,7 +645,87 @@ deploy_ocf_oficial_staging:
        --set celery-worker.env.redisPort=6379 \
        --set celery-worker.env.logLevel="DEBUG" \
        --wait --timeout=10m --create-namespace --atomic
      else
        echo "### helm capif directory does not exist ###"
        echo "New deployment behaviour, creating env file and installing helm chart with it"

        echo "Generate env file for helm scripts"

        cat <<EOF > helm/scripts/envs/$NAMESPACE_STAGING.template
      # --------------------------------------------------------------------------------------------------------------
      # This file is generated by the GitLab CI pipeline for deploying CAPIF to the staging environment. 
      # It contains environment variables that are used in the deployment process. 
      # The values of these variables are set based on the current GitLab CI environment and the configuration 
      # of the CAPIF deployment.

      # Common variables
      ## Non Default values on next variables
      export CAPIF_NAMESPACE=$NAMESPACE_STAGING
      export CAPIF_CI_ENV_ENDPOINT=capif-staging
      export CAPIF_NAME_VERSION_CHART=ocf-staging
      export CAPIF_DOMAIN=$DOMAIN_STAGING
      export BASE_DOCKER_REGISTRY=labs.etsi.org:5050/ocf/capif
      export CAPIF_DOCKER_REGISTRY=$CI_REGISTRY/ocf/capif/staging
      export CAPIF_IMAGE_TAG=staging
      export VAULT_INTERNAL_HOSTNAME=$VAULT_HOSTNAME
      export VAULT_PORT=$VAULT_PORT
      export VAULT_ACCESS_TOKEN=<REDACTED>

      export CAPIF_HOSTNAME=capif-staging.$DOMAIN_STAGING
      export REGISTER_HOSTNAME=register-staging.$DOMAIN_STAGING

      ## Default values on next variables
      export LOG_LEVEL=DEBUG

      # Step 0 CAPIF Monitoring configuration
      ## Configuration of the monitoring components of CAPIF, such as Grafana, Loki, Fluentbit, Tempo and Otelcollector.
      export PROMETHEUS_URL=http://prometheus.ocf.pre-production

      ## Default values on next variables
      ### Storage configuration
      # export CAPIF_STORAGE_CLASS=nfs-01
      # export CAPIF_GRAFANA_STORAGE_SIZE=10Gi
      # export CAPIF_LOKI_STORAGE_SIZE=100Mi
      # export CAPIF_TEMPO_STORAGE_SIZE=100Mi
      # export CAPIF_TEMPO_STORAGE_SIZE=3Gi
      ### OpenCAPIF Monitoring configuration
      # export CAPIF_GRAFANA_ENABLED=true
      # export CAPIF_LOKI_ENABLED=true
      # export CAPIF_FLUENTBIT_ENABLED=true
      # export CAPIF_TEMPO_ENABLED=true
      # export CAPIF_OTELCOLLECTOR_ENABLED=true

      # Step 1: OpenCAPIF Mongo configuration
      ## Default values on next variables
      # export CAPIF_MONGO_REGISTER_STORAGE_SIZE=8Gi
      # export CAPIF_MONGO_STORAGE_SIZE=8Gi

      # Step 2: OpenCAPIF Mongo Express configuration
      # Only Common configuration of env apply to both mongo express components.

      # Step 3: OpenCAPIF Common Core Components configuration
      # Only Common configuration of env apply to both mongo express components.

      # Step 4: OpenCAPIF Core Components configuration
      # Only Common configuration of env apply to both mongo express components. CAPIF_HOSTNAME

      # Step 5: OpenCAPIF Register configuration
      # Only Common configuration of env apply to both mongo express components. REGISTER_HOSTNAME
      # --------------------------------------------------------------------------------------------------------------
      EOF
        sed -e "s/^[ ]*export VAULT_ACCESS_TOKEN=.*/export VAULT_ACCESS_TOKEN=$VAULT_ACCESS_TOKEN_PROD/" \
        helm/scripts/envs/$NAMESPACE_STAGING.template > helm/scripts/envs/$NAMESPACE_STAGING.env
        ./helm/scripts/install_capif.sh $NAMESPACE_STAGING
        kubectl delete pod --field-selector=status.phase=Failed -n $NAMESPACE_STAGING
        kubectl delete pod --field-selector=status.phase=Succeeded -n $NAMESPACE_STAGING

      fi
  artifacts:
    name: "$NAMESPACE_STAGING.template"
    paths:
      - helm/scripts/envs/$NAMESPACE_STAGING.template
    expire_in: 1 day
    when: always
## dev ###

prep_ocf_cd_dev:
@@ -655,9 +739,15 @@ prep_ocf_cd_dev:
      echo $CD_ENV_NAME
      echo $CD_ENV_NAME | rev | cut -c 1-6 | rev
      echo $(echo $CD_ENV_NAME | rev | cut -c 1-6 | rev) > cd_env_endpoint.txt
      echo "Setting up a namespace .env file for the dev environment"
      CI_ENV_ENDPOINT=$(cat cd_env_endpoint.txt)
      echo "CI_ENV_ENDPOINT=$CI_ENV_ENDPOINT" > namespace.env

  artifacts:
    paths:
      - cd_env_endpoint.txt
    reports:
      dotenv: namespace.env

deploy_ocf_dev:
  stage: deploy_ocf_dev
@@ -683,6 +773,8 @@ deploy_ocf_dev:
      echo "### setting kubeconfig###"
      kubectl cluster-info
      yq --version
      if [[ -d helm/capif ]]; then
        echo "### helm capif directory exists ###"
        ### Chart main ocf###
        cat helm/capif/Chart.yaml
        yq e -i ".appVersion = \"$IMAGE_TAG_DEV\"" helm/capif/Chart.yaml
@@ -699,8 +791,6 @@ deploy_ocf_dev:
          yq e -i ".appVersion = \"$IMAGE_TAG_DEV\"" "helm/capif/charts/$chart/Chart.yaml"
        done

      export CI_ENV_ENDPOINT=$(cat cd_env_endpoint.txt)

        echo "### download dependencies###"
        helm dependency build helm/capif
        echo "### updating capif###"
@@ -851,6 +941,87 @@ deploy_ocf_dev:
        --set celery-worker.env.redisPort=6379 \
        --set celery-worker.env.logLevel="DEBUG" \
        --wait --timeout=10m --create-namespace --atomic
      else
        echo "### helm capif directory does not exist ###"
        echo "New deployment behaviour, creating env file and installing helm chart with it"

        echo "Generate env file for helm scripts"

        cat <<EOF > helm/scripts/envs/$NAMESPACE_DEV.template
      # --------------------------------------------------------------------------------------------------------------
      # This file is generated by the GitLab CI pipeline for deploying CAPIF to the staging environment. 
      # It contains environment variables that are used in the deployment process. 
      # The values of these variables are set based on the current GitLab CI environment and the configuration 
      # of the CAPIF deployment.

      # Common variables
      ## Non Default values on next variables
      export CAPIF_NAMESPACE=$NAMESPACE_DEV
      export CAPIF_CI_ENV_ENDPOINT=$CI_ENV_ENDPOINT-dev
      export CAPIF_NAME_VERSION_CHART=ocf-developer
      export CAPIF_DOMAIN=$DOMAIN_DEV
      export BASE_DOCKER_REGISTRY=labs.etsi.org:5050/ocf/capif
      export CAPIF_DOCKER_REGISTRY=$CI_REGISTRY/ocf/capif/$CI_COMMIT_REF_SLUG
      export CAPIF_IMAGE_TAG=$CI_COMMIT_REF_SLUG
      export VAULT_INTERNAL_HOSTNAME=$VAULT_HOSTNAME
      export VAULT_PORT=$VAULT_PORT
      export VAULT_ACCESS_TOKEN=<REDACTED>

      export CAPIF_HOSTNAME=capif-$CI_ENV_ENDPOINT-dev.$DOMAIN_DEV
      export REGISTER_HOSTNAME=register-$CI_ENV_ENDPOINT-dev.$DOMAIN_DEV

      ## Default values on next variables
      export LOG_LEVEL=DEBUG

      # Step 0 CAPIF Monitoring configuration
      ## Configuration of the monitoring components of CAPIF, such as Grafana, Loki, Fluentbit, Tempo and Otelcollector.
      export PROMETHEUS_URL=http://prometheus.ocf.pre-production

      ## Default values on next variables
      ### Storage configuration
      # export CAPIF_STORAGE_CLASS=nfs-01
      # export CAPIF_GRAFANA_STORAGE_SIZE=10Gi
      # export CAPIF_LOKI_STORAGE_SIZE=100Mi
      # export CAPIF_TEMPO_STORAGE_SIZE=100Mi
      # export CAPIF_TEMPO_STORAGE_SIZE=3Gi
      ### OpenCAPIF Monitoring configuration
      # export CAPIF_GRAFANA_ENABLED=true
      # export CAPIF_LOKI_ENABLED=true
      # export CAPIF_FLUENTBIT_ENABLED=true
      # export CAPIF_TEMPO_ENABLED=true
      # export CAPIF_OTELCOLLECTOR_ENABLED=true

      # Step 1: OpenCAPIF Mongo configuration
      ## Default values on next variables
      # export CAPIF_MONGO_REGISTER_STORAGE_SIZE=8Gi
      # export CAPIF_MONGO_STORAGE_SIZE=8Gi

      # Step 2: OpenCAPIF Mongo Express configuration
      # Only Common configuration of env apply to both mongo express components.

      # Step 3: OpenCAPIF Common Core Components configuration
      # Only Common configuration of env apply to both mongo express components.

      # Step 4: OpenCAPIF Core Components configuration
      # Only Common configuration of env apply to both mongo express components. CAPIF_HOSTNAME

      # Step 5: OpenCAPIF Register configuration
      # Only Common configuration of env apply to both mongo express components. REGISTER_HOSTNAME
      # --------------------------------------------------------------------------------------------------------------
      EOF
        sed -e "s/^[ ]*export VAULT_ACCESS_TOKEN=.*/export VAULT_ACCESS_TOKEN=$VAULT_ACCESS_TOKEN/" \
        helm/scripts/envs/$NAMESPACE_DEV.template > helm/scripts/envs/$NAMESPACE_DEV.env
        ./helm/scripts/install_capif.sh $NAMESPACE_DEV
        kubectl delete pod --field-selector=status.phase=Failed -n $NAMESPACE_DEV
        kubectl delete pod --field-selector=status.phase=Succeeded -n $NAMESPACE_DEV

      fi
  artifacts:
    name: "$NAMESPACE_DEV.template"
    paths:
      - helm/scripts/envs/$NAMESPACE_DEV.template
    expire_in: 1 day
    when: always

delete_ocf_dev:
  stage: delete_ocf_dev
@@ -858,9 +1029,85 @@ delete_ocf_dev:
  tags:
    - shell
  script:
    - echo "### deleting environment $NAMESPACE_DEV###"
    - helm uninstall -n $NAMESPACE_DEV ocf-developer
    - kubectl delete ns $NAMESPACE_DEV --force
    - |
      echo "### deleting environment $NAMESPACE_DEV###"
      if [[ -d helm/capif ]]; then
        helm uninstall -n $NAMESPACE_DEV ocf-developer
        kubectl delete ns $NAMESPACE_DEV --force
      else
        if [[ -f helm/scripts/envs/$NAMESPACE_DEV.env ]]; then
          echo "### env file found for $NAMESPACE_DEV, deleting with helm script ###"
        else
          echo "### No helm capif directory and no env file found for $NAMESPACE_DEV, create file ###"
          cat <<EOF > helm/scripts/envs/$NAMESPACE_DEV.template
      # --------------------------------------------------------------------------------------------------------------
      # This file is generated by the GitLab CI pipeline for deploying CAPIF to the staging environment. 
      # It contains environment variables that are used in the deployment process. 
      # The values of these variables are set based on the current GitLab CI environment and the configuration 
      # of the CAPIF deployment.

      # Common variables
      ## Non Default values on next variables
      export CAPIF_NAMESPACE=$NAMESPACE_DEV
      export CAPIF_CI_ENV_ENDPOINT=$CI_ENV_ENDPOINT-dev
      export CAPIF_NAME_VERSION_CHART=ocf-developer
      export CAPIF_DOMAIN=$DOMAIN_DEV
      export BASE_DOCKER_REGISTRY=labs.etsi.org:5050/ocf/capif
      export CAPIF_DOCKER_REGISTRY=$CI_REGISTRY/ocf/capif/$CI_COMMIT_REF_SLUG
      export CAPIF_IMAGE_TAG=$CI_COMMIT_REF_SLUG
      export VAULT_INTERNAL_HOSTNAME=$VAULT_HOSTNAME
      export VAULT_PORT=$VAULT_PORT
      export VAULT_ACCESS_TOKEN=<REDACTED>

      export CAPIF_HOSTNAME=capif-$CI_ENV_ENDPOINT-dev.$DOMAIN_DEV
      export REGISTER_HOSTNAME=register-$CI_ENV_ENDPOINT-dev.$DOMAIN_DEV

      ## Default values on next variables
      export LOG_LEVEL=DEBUG

      # Step 0 CAPIF Monitoring configuration
      ## Configuration of the monitoring components of CAPIF, such as Grafana, Loki, Fluentbit, Tempo and Otelcollector.
      export PROMETHEUS_URL=http://prometheus.ocf.pre-production

      ## Default values on next variables
      ### Storage configuration
      # export CAPIF_STORAGE_CLASS=nfs-01
      # export CAPIF_GRAFANA_STORAGE_SIZE=10Gi
      # export CAPIF_LOKI_STORAGE_SIZE=100Mi
      # export CAPIF_TEMPO_STORAGE_SIZE=100Mi
      # export CAPIF_TEMPO_STORAGE_SIZE=3Gi
      ### OpenCAPIF Monitoring configuration
      # export CAPIF_GRAFANA_ENABLED=true
      # export CAPIF_LOKI_ENABLED=true
      # export CAPIF_FLUENTBIT_ENABLED=true
      # export CAPIF_TEMPO_ENABLED=true
      # export CAPIF_OTELCOLLECTOR_ENABLED=true

      # Step 1: OpenCAPIF Mongo configuration
      ## Default values on next variables
      # export CAPIF_MONGO_REGISTER_STORAGE_SIZE=8Gi
      # export CAPIF_MONGO_STORAGE_SIZE=8Gi

      # Step 2: OpenCAPIF Mongo Express configuration
      # Only Common configuration of env apply to both mongo express components.

      # Step 3: OpenCAPIF Common Core Components configuration
      # Only Common configuration of env apply to both mongo express components.

      # Step 4: OpenCAPIF Core Components configuration
      # Only Common configuration of env apply to both mongo express components. CAPIF_HOSTNAME

      # Step 5: OpenCAPIF Register configuration
      # Only Common configuration of env apply to both mongo express components. REGISTER_HOSTNAME
      # --------------------------------------------------------------------------------------------------------------
      EOF
          sed -e "s/^[ ]*export VAULT_ACCESS_TOKEN=.*/export VAULT_ACCESS_TOKEN=$VAULT_ACCESS_TOKEN/" \
          helm/scripts/envs/$NAMESPACE_DEV_TO_STAGING-mr.template > helm/scripts/envs/$NAMESPACE_DEV_TO_STAGING-mr.env

        fi
        ./helm/scripts/uninstall_capif.sh $NAMESPACE_DEV_TO_STAGING-mr -y
      fi

  when: manual
  environment:
    name: review/$CI_COMMIT_REF_SLUG