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

frist commit

parent 68a2966e
Loading
Loading
Loading
Loading

capif/.gitlab-ci.yml

0 → 100644
+65 −0
Original line number Diff line number Diff line
stages:
  - cancel_previous_action
  - workflow_ci
  - ci_in_staging
  - ci_deploy_in_staging
  - cleaning_in_staging

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

.common: &common
  only:
    - merge_requests
  except:
    - $CI_PIPELINE_SOURCE == "merge_request_event" && $GITLAB_USER_LOGIN == "andresanaya21"
  tags:
    - shell

cancel_previous_action:
  stage: cancel_previous_action
  script:
   - >
     if [[ -n "$CI_JOB_TOKEN" ]]; then
       echo "Checking for running jobs in the same pipeline..."
       jobs=$(curl --header "PRIVATE-TOKEN: $CI_JOB_TOKEN" "$GITLAB_API/projects/$CI_PROJECT_ID/pipelines/$CI_PIPELINE_ID/jobs")
       for job in $(echo "$jobs" | jq -r '.[] | @base64'); do
         _jq() {
           echo ${job} | base64 --decode | jq -r ${1}
         }
         status=$(_jq '.status')
         id=$(_jq '.id')
         if [[ "$status" == "running" ]] && [[ "$id" != "$CI_JOB_ID" ]]; then
           echo "Cancelling job $id"
           curl --request POST --header "PRIVATE-TOKEN: $CI_JOB_TOKEN" "$GITLAB_API/projects/$CI_PROJECT_ID/jobs/$id/cancel"
         fi
       done
     fi
  <<: *common

include:
- 'templates/workflow_ci.gitlab-ci.yml'
#- 'templates/ci_in_staging.gitlab-ci.yml'


#ci_in_staging:
#  stage: ci_in_staging
#  script:
#    - echo "Define the ci_in_staging job here"
#  needs: ["workflow_ci"]
#  <<: *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
#
#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
+54 −0
Original line number Diff line number Diff line
stages:
  - pulling_repo
  - secrets_in_repo
  - linting_code
  - linting_docker

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

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

secrets_in_repo:
  stage: secrets_in_repo
  script:
    - pip install trufflehog
    - trufflehog capif --exclude_paths cicd/exclusions --max_depth=5
  needs: ["pulling_repo"]
  tags:
    - shell

# define the process to do linting code: Sonarque, ruff?
linting_code:
  stage: linting_code
  script:
    - echo "ruff checks"
  needs: ["secrets_in_repo"]
  tags:
    - shell

linting_docker:
  stage: 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: ["linting_code"]
  tags:
    - shell