Commit 41fc6d67 authored by coconux's avatar coconux
Browse files

update ci

parent ee827539
Loading
Loading
Loading
Loading
+69 −25
Original line number Diff line number Diff line
stages:
  - static_tests
  - project_setup
  - build
  - deployment
  - deploy

include:
  - remote: 'https://jobs.r2devops.io/1.2.0/mkdocs.yml?scope=0.yml'
  - remote: 'https://jobs.r2devops.io/0.2.0/pages.yml?scope=0.yml'

mkdocs:
  variables:
    PIPENV_PIPFILE: tools/builder/Pipfile
  before_script:
    - pip install pipenv && pipenv install
    - pipenv run python tools/builder/builder.py
    - pip3 install mkdocs-awesome-pages-plugin==2.4.0 # temporary, it will be removed after #202

pages:
  rules:
    - if: '$CI_COMMIT_BRANCH == "latest"'
  - remote: 'https://jobs.r2devops.io/1.4.0/mkdocs.yml?scope=0.yml'
  - remote: 'https://jobs.r2devops.io/0.3.0/pages.yml?scope=0.yml'

ci_linter:
  image: golang:1.15.2-alpine3.12
  stage: static_tests
  image:
    name: alpine/httpie:2.4.0
    entrypoint: [""]
  variables:
    GITLAB_CI_LINT_URL: "https://gitlab.com/api/v4/ci/lint?include_merged_yaml=true"
    JOB_FILES_EXTENSION: ".yml"
  script:
    - apk add --no-cache git
    - go get gitlab.com/orobardet/gitlab-ci-linter
    - apk add --no-cache jq
    - mkdir ci_linter_reports
    - for JOB_PATH in jobs/*; do
    -   echo "Start checking ${JOB_PATH}/${JOB} using Gitlab CI linter API"
    -   JOB=$(basename ${JOB_PATH})
    -   gitlab-ci-linter ${JOB_PATH}/${JOB}.yml
    -   jq --null-input --arg yaml "$(cat ${JOB_PATH}/${JOB}${JOB_FILES_EXTENSION})" '.content=$yaml' | http --print 'b' --check-status "$GITLAB_CI_LINT_URL" Content-Type:"application/json" PRIVATE-TOKEN:${API_TOKEN} > ci_linter_reports/${JOB}.json
    -   if [ $(jq -r '.status' ci_linter_reports/${JOB}.json) == "valid" ]; then
    -     echo "👍 job ${JOB_PATH}/${JOB} is valid"
    -   else
    -     echo "👎 job ${JOB_PATH}/${JOB} is invalid"
    -     jq '.' ci_linter_reports/${JOB}.json
    -     exit 1
    -   fi
    - done
  artifacts:
    expose_as: "job_ci_lint"
    paths:
      - ci_linter_reports/
    when: always

structure:
job_structure:
  image: python:3.9.1-alpine
  stage: static_tests
  variables:
@@ -42,9 +49,9 @@ structure:
  script:
    - pipenv run python3 tools/job_structure/job_structure.py
  artifacts:
    expose_as: "job_structure"
    paths:
      - ${JOB_LOGFILE}
    expire_in: 30 days
    when: always

job_customs:
@@ -59,10 +66,11 @@ job_customs:
  script:
    - pipenv run python3 tools/job_customs/job_customs.py
  artifacts:
    expose_as: "jobs_customs"
    paths:
      - ${JOB_LOGFILE}

scan_images_dep:
job_image_scan:
  image: docker:19.03
  stage: static_tests
  services:
@@ -111,7 +119,7 @@ scan_images_dep:

    - mkdir ${OUTPUT_DIR}
  script:
    - for JOB in $(ls jobs); do
    - for JOB in $(ls -A jobs); do
    -   IMAGE=$(pipenv run python3 tools/job_image/job_image.py ${JOB})
    -   if [ ! -z ${IMAGE} ]; then
    -     NAME=$(basename ${IMAGE})
@@ -126,22 +134,54 @@ scan_images_dep:
    paths:
      - "$TRIVY_CACHE_DIR"
  artifacts:
    expose_as: "job_image_scan"
    paths:
      - "${JOB_LOGFILE}"
      - "${OUTPUT_DIR}/*.xml"
      - "${OUTPUT_DIR}"
    reports:
      junit:
        - "${OUTPUT_DIR}/*.xml"
    expire_in: 30 days
    when: always


# See https://docs.gitlab.com/ee/api/labels.html
job_labels:
  image: python:3.9.1-alpine
  stage: project_setup
  variables:
    PIPENV_PIPFILE: tools/job_labels/Pipfile
    JOB_LOGFILE: "job_labels.log"
  before_script:
    - pip install --ignore-installed distlib pipenv
    - pipenv install
  script:
    - pipenv run python3 tools/job_labels/job_labels.py
  artifacts:
    expose_as: "job_labels"
    paths:
      - ${JOB_LOGFILE}
    expire_in: 30 days
    when: always
  rules:
    - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_PROJECT_PATH_SLUG == "r2devops/hub"'


mkdocs:
  variables:
    PIPENV_PIPFILE: tools/builder/Pipfile
  before_script:
    - pip install pipenv && pipenv install
    - pipenv run python tools/builder/builder.py


# See https://docs.gitlab.com/ee/api/releases/
# We can only control the link to the hub, the release is still storing the source code
release:
  stage: deploy
  image:
    name: alpine/httpie:2.2.0
    entrypoint: [""]
  stage: deployment
  variables:
    PIPENV_PIPFILE: tools/notify/Pipfile
  before_script:
@@ -180,3 +220,7 @@ release:
    done
  rules:
    - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'

pages:
  rules:
    - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'