Commit 3e1c6f15 authored by Andres Anaya Amariels's avatar Andres Anaya Amariels 🚀
Browse files

staging gitlab ci

parent 078ebf01
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -13,7 +13,8 @@ variables:
  only:
    - merge_requests
  except:
    - $CI_PIPELINE_SOURCE == "merge_request_event"
    variables:
      - $CI_MERGE_REQUEST_TARGET_BRANCH_NAME != "staging"
  tags:
    - shell

@@ -38,9 +39,10 @@ cancel_previous_action:
     fi
  <<: *common

#include:
#  - 'capif/templates/workflow_ci.gitlab-ci.yml'
#- 'templates/ci_in_staging.gitlab-ci.yml'
include:
 - 'capif/templates/workflow_ci.gitlab-ci.yml'
# - 'capif/templates/ci_in_staging.gitlab-ci.yml'
# - 'capif/templates/cd-deploy-ocf-dev.gitlab-ci.yml'


#ci_in_staging:
+81 −0
Original line number Diff line number Diff line
stages:
  - deploy_ocf_dev
  - delete_ocf_dev

variables:
  INGRESS: "10.43.32.232"
  NAMESPACE: "ocf-staging"
  DOMAIN: staging.int
  CI_JOB_TOKEN: $CI_JOB_TOKEN
  IMAGE_TAG: "v0.0.1-staging"

.common: &common
  only:
    - merge_requests
  except:
    variables:
      - $CI_MERGE_REQUEST_TARGET_BRANCH_NAME != "staging"
  tags:
    - shell

deploy_ocf_dev:
  stage: deploy_ocf_dev
  <<: *common
  environment:
    name: review/staging
    url: https://$NAMESPACE.$DOMAIN
    on_stop: delete_ocf_dev
    auto_stop_in: 3 day
  rules:
    - if: $CI_COMMIT_BRANCH == "main"
      when: never
    - if: $CI_COMMIT_BRANCH
  script:
    - echo "### git clone OCF repo ###" 
    - git clone https://oauth2:${CI_JOB_TOKEN}@labs.etsi.org/rep/ocf/capif.git
    - echo "### install helm ###"
    - curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
    - chmod 700 get_helm.sh
    - ./get_helm.sh
    - helm version
    - echo "### install kubectl ###" 
    - curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
    - chmod +x kubectl
    - sudo mv kubectl /usr/local/bin
    - kubectl version --output=yaml
    - echo "### setting kubeconfig ###"
    - echo $KUBECONFIG | base64 -d > ~/cluster.kubeconfig
    - kubectl get nodes --kubeconfig ~/cluster.kubeconfig
    - kubectl cluster-info --kubeconfig ~/cluster.kubeconfig #comment that when is working
    - echo "### install yq ###"
    - sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
    - sudo chmod a+x /usr/local/bin/yq
    - yq --version
    - yq e -i '.version = "$IMAGE_TAG"' helm/capif/Chart.yaml
    - yq e -i '.appVersion = "$IMAGE_TAG"' helm/capif/Chart.yaml
    - cat helm/capif/Chart.yaml
    - echo "### download dependencies ###"
    - helm dependency build helm/capif
    - echo "### updating capif ###"
    - helm uninstall -n $NAMESPACE ocf --kubeconfig ~/cluster.kubeconfig || true
    - helm upgrade --install -n $NAMESPACE ocf helm/capif/ \
      --set nginx.nginx.env.capifHostname=capif.$DOMAIN \
      --set ingress_ip.oneke="$INGRESS" --atomic \
      --set monitoring.prometheus.enable="" \
      --set monitoring.grafana.ingress.hosts[0].host="grafana.$DOMAIN" \
      --set monitoring.grafana.ingress.hosts[0].paths[0].path="/" \
      --set monitoring.grafana.ingress.hosts[0].paths[0].pathType="Prefix" \
      --wait --timeout=10m \
      --create-namespace --kubeconfig ~/cluster.kubeconfig


delete_ocf_dev:
  stage: delete_ocf_dev
  <<: *common
  script:
    - echo "### deleting environment $NAMESPACE ###"
    - helm uninstall -n $NAMESPACE ocf --kubeconfig ~/cluster.kubeconfig
  when: manual
  environment:
    name: review/staging
    action: stop
 No newline at end of file
+13 −8
Original line number Diff line number Diff line
@@ -8,12 +8,20 @@ variables:
  GITLAB_API: "https://labs.etsi.org/api/v4"
  CI_JOB_TOKEN: $CI_JOB_TOKEN

.common: &common
  only:
    - merge_requests
  except:
    variables:
      - $CI_MERGE_REQUEST_TARGET_BRANCH_NAME != "staging"
  tags:
    - shell

pulling_repo:
  stage: pulling_repo
  script:
    - git clone https://oauth2:${CI_JOB_TOKEN}@labs.etsi.org/rep/ocf/capif.git
  tags:
    - shell
  <<: *common

secrets_in_repo:
  stage: secrets_in_repo
@@ -21,8 +29,7 @@ secrets_in_repo:
    - pip install trufflehog
    - trufflehog capif --exclude_paths cicd/exclusions --max_depth=5
  needs: ["pulling_repo"]
  tags:
    - shell
  <<: *common

# define the process to do linting code: Sonarque, ruff?
linting_code:
@@ -30,8 +37,7 @@ linting_code:
  script:
    - echo "ruff checks"
  needs: ["secrets_in_repo"]
  tags:
    - shell
  <<: *common

linting_docker:
  stage: linting_docker
@@ -49,5 +55,4 @@ linting_docker:
        - docker-lint.json
  interruptible: true    
  needs: ["linting_code"]
  tags:
    - shell
  <<: *common