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

execution

parent 3e1c6f15
Loading
Loading
Loading
Loading
+23 −12
Original line number Diff line number Diff line
stages:
  - cancel_previous_action
  - staging_cancel_previous_action
  - workflow_ci
  - ci_in_staging
  - ci_deploy_in_staging
@@ -9,7 +9,7 @@ variables:
  GITLAB_API: "https://labs.etsi.org/api/v4"
  CI_JOB_TOKEN: $CI_JOB_TOKEN

.common: &common
.staging_common: &staging_common
  only:
    - merge_requests
  except:
@@ -18,8 +18,12 @@ variables:
  tags:
    - shell

cancel_previous_action:
  stage: cancel_previous_action
.dev_common: &dev_common
  tags:
    - shell

staging_cancel_previous_action:
  stage: staging_cancel_previous_action
  script:
   - >
     if [[ -n "$CI_JOB_TOKEN" ]]; then
@@ -37,12 +41,19 @@ cancel_previous_action:
         fi
       done
     fi
  <<: *common
  <<: *staging_common

dev_cancel_previous_action:
  stage: dev_cancel_previous_action
  script:
   - >
     echo "dev_cancel_previous_action job"
  <<: *dev_common

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'
#include:
# - 'capif/templates/ci_staging.gitlab-ci.yml'
# - 'capif/templates/ci_dev.gitlab-ci.yml'
# - 'capif/templates/cd-deploy-ocf.gitlab-ci.yml'


#ci_in_staging:
@@ -50,18 +61,18 @@ include:
#  script:
#    - echo "Define the ci_in_staging job here"
#  needs: ["workflow_ci"]
#  <<: *common
#  <<: *staging_common
#
#ci_deploy_in_staging:
#  stage: ci_deploy_in_staging
#  script:
#    - echo "Define the ci_deploy_in_staging job here"
#  needs: ["ci_in_staging"]
#  <<: *common
#  <<: *staging_common
#
#cleaning_in_staging:
#  stage: cleaning_in_staging
#  script:
#    - echo "Define the cleaning_in_staging job here"
#  needs: ["ci_deploy_in_staging"]
#  <<: *common
 No newline at end of file
#  <<: *staging_common
 No newline at end of file
+83 −21
Original line number Diff line number Diff line
stages:
  - deploy_ocf_staging
  - delete_ocf_staging
  - deploy_ocf_dev
  - delete_ocf_dev

variables:
  INGRESS: "10.43.32.232"
  NAMESPACE: "ocf-staging"
  DOMAIN: staging.int
  NAMESPACE_DEV: "ocf-dev-$CI_JOB_USER"
  NAMESPACE_STAGING: "ocf-staging"
  DOMAIN_STAGING: staging.int
  DOAMIN_DEV: developer.int
  CI_JOB_TOKEN: $CI_JOB_TOKEN
  IMAGE_TAG: "v0.0.1-staging"
  IMAGE_TAG_DEV: "v0.0.1-$CI_COMMIT_SHA"
  IMAGE_TAG_STAGING: "v0.0.1-staging"

.common: &common
.staging_common: &staging_common
  only:
    - merge_requests
  except:
@@ -18,13 +23,17 @@ variables:
  tags:
    - shell

deploy_ocf_dev:
  stage: deploy_ocf_dev
  <<: *common
.dev_common: &dev_common
  tags:
    - shell

deploy_ocf_staging:
  stage: deploy_ocf_staging
  <<: *staging_common
  environment:
    name: review/staging
    url: https://$NAMESPACE.$DOMAIN
    on_stop: delete_ocf_dev
    url: https://$NAMESPACE_STAGING.$DOMAIN_STAGING
    on_stop: delete_ocf_staging
    auto_stop_in: 3 day
  rules:
    - if: $CI_COMMIT_BRANCH == "main"
@@ -51,31 +60,84 @@ deploy_ocf_dev:
    - 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
    - yq e -i '.version = "$IMAGE_TAG_STAGING"' helm/capif/Chart.yaml
    - yq e -i '.appVersion = "$IMAGE_TAG_STAGING"' 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 \
    - helm uninstall -n $NAMESPACE_STAGING ocf --kubeconfig ~/cluster.kubeconfig || true
    - helm upgrade --install -n $NAMESPACE_STAGING ocf helm/capif/ \
      --set nginx.nginx.env.capifHostname=capif.$DOMAIN_STAGING \
      --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].host="grafana.$DOMAIN_STAGING" \
      --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
      --create-NAMESPACE_STAGING --kubeconfig ~/cluster.kubeconfig


delete_ocf_dev:
  stage: delete_ocf_dev
  <<: *common
delete_ocf_staging:
  stage: delete_ocf_staging
  <<: *staging_common
  script:
    - echo "### deleting environment $NAMESPACE ###"
    - helm uninstall -n $NAMESPACE ocf --kubeconfig ~/cluster.kubeconfig
    - echo "### deleting environment $NAMESPACE_STAGING ###"
    - helm uninstall -n $NAMESPACE_STAGING ocf --kubeconfig ~/cluster.kubeconfig
  when: manual
  environment:
    name: review/staging
    action: stop

## dev ###
deploy_ocf_dev:
  stage: deploy_ocf_dev
  <<: *dev_common
  environment:
    name: review/$CI_COMMIT_REF_SLUG
    url: https://$NAMESPACE_DEV.$DOMAIN_DEV
    on_stop: delete_ocf_dev
    auto_stop_in: 3 day
  rules:
    - if: $CI_COMMIT_BRANCH == "main"
      when: never
    - if: $CI_COMMIT_BRANCH == "staging"
      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_STAGING"' helm/capif/Chart.yaml
    - yq e -i '.appVersion = "$IMAGE_TAG_STAGING"' helm/capif/Chart.yaml
    - cat helm/capif/Chart.yaml
    - echo "### download dependencies ###"
    - helm dependency build helm/capif
    - echo "### updating capif ###"
    - helm uninstall -n $NAMESPACE_STAGING ocf --kubeconfig ~/cluster.kubeconfig || true
    - helm upgrade --install -n $NAMESPACE_STAGING ocf helm/capif/ \
      --set nginx.nginx.env.capifHostname=capif.$DOMAIN_STAGING \
      --set ingress_ip.oneke="$INGRESS" --atomic \
      --set monitoring.prometheus.enable="" \
      --set monitoring.grafana.ingress.hosts[0].host="grafana.$DOMAIN_STAGING" \
      --set monitoring.grafana.ingress.hosts[0].paths[0].path="/" \
      --set monitoring.grafana.ingress.hosts[0].paths[0].pathType="Prefix" \
      --wait --timeout=10m \
      --create-NAMESPACE_STAGING --kubeconfig ~/cluster.kubeconfig
+53 −0
Original line number Diff line number Diff line
stages:
  - dev_pulling_repo
  - dev_secrets_in_repo
  - dev_linting_code
  - dev_linting_docker

variables:
  GITLAB_API: "https://labs.etsi.org/api/v4"
  CI_JOB_TOKEN: $CI_JOB_TOKEN

.dev_common: &dev_common
  tags:
    - shell

dev_pulling_repo:
  stage: dev_pulling_repo
  script:
    - git clone https://oauth2:${CI_JOB_TOKEN}@labs.etsi.org/rep/ocf/capif.git
  <<: *dev_common

dev_secrets_in_repo:
  stage: dev_secrets_in_repo
  script:
    - pip install trufflehog
    - trufflehog capif --exclude_paths cicd/exclusions --max_depth=5
  needs: ["dev_pulling_repo"]
  <<: *dev_common

# define the process to do linting code: Sonarque, ruff?
dev_linting_code:
  stage: dev_linting_code
  script:
    - echo "ruff checks"
  needs: ["dev_secrets_in_repo"]
  <<: *dev_common

dev_linting_docker:
  stage: dev_linting_docker
  image: hadolint/hadolint:latest-debian
  script:
   - find . -name 'capif/services/Dockerfile*' -exec hadolint --no-fail -f gitlab_codeclimate {} + > docker-lint.json
    - hadolint services/capif-client/Dockerfile
#    - hadolint services/nginx/Dockerfile
#    - hadolint services/register/Dockerfile
  artifacts:
    name: "$CI_JOB_NAME artifacts from $CI_PROJECT_NAME on $CI_COMMIT_REF_SLUG"
    when: always
    reports:
      codequality:
        - docker-lint.json
  interruptible: true    
  needs: ["dev_linting_code"]
  <<: *dev_common
+21 −21
Original line number Diff line number Diff line
stages:
  - pulling_repo
  - secrets_in_repo
  - linting_code
  - linting_docker
  - staging_pulling_repo
  - staging_secrets_in_repo
  - staging_linting_code
  - staging_linting_docker

variables:
  GITLAB_API: "https://labs.etsi.org/api/v4"
  CI_JOB_TOKEN: $CI_JOB_TOKEN

.common: &common
.staging_common: &staging_common
  only:
    - merge_requests
  except:
@@ -17,34 +17,34 @@ variables:
  tags:
    - shell

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

secrets_in_repo:
  stage: secrets_in_repo
staging_secrets_in_repo:
  stage: staging_secrets_in_repo
  script:
    - pip install trufflehog
    - trufflehog capif --exclude_paths cicd/exclusions --max_depth=5
  needs: ["pulling_repo"]
  <<: *common
  needs: ["staging_pulling_repo"]
  <<: *staging_common

# define the process to do linting code: Sonarque, ruff?
linting_code:
  stage: linting_code
staging_linting_code:
  stage: staging_linting_code
  script:
    - echo "ruff checks"
  needs: ["secrets_in_repo"]
  <<: *common
  needs: ["staging_secrets_in_repo"]
  <<: *staging_common

linting_docker:
  stage: linting_docker
staging_linting_docker:
  stage: staging_linting_docker
  image: hadolint/hadolint:latest-debian
  script:
   - find . -name 'capif/services/Dockerfile*' -exec hadolint --no-fail -f gitlab_codeclimate {} + > docker-lint.json
#    - hadolint services/capif-client/Dockerfile
    - hadolint services/capif-client/Dockerfile
#    - hadolint services/nginx/Dockerfile
#    - hadolint services/register/Dockerfile
  artifacts:
@@ -54,5 +54,5 @@ linting_docker:
      codequality:
        - docker-lint.json
  interruptible: true    
  needs: ["linting_code"]
  <<: *common
  needs: ["staging_linting_code"]
  <<: *staging_common