Skip to content
Snippets Groups Projects
.gitlab-ci.yml 2.75 KiB
Newer Older
# GitLab CI in conjunction with GitLab Runner can use Docker Engine to test and build any application.
# Docker, when used with GitLab CI, runs each job in a separate and isolated container using the predefined image that is set up in .gitlab-ci.yml.
# In this case we use the latest python docker image to build and test this project.

# cache is used to specify a list of files and directories which should be cached between jobs. You can only use paths that are within the project workspace.
# If cache is defined outside the scope of jobs, it means it is set globally and all jobs will use that definition
cache:
  paths:
    
# before_script is used to define the command that should be run before all jobs, including deploy jobs, but after the restoration of artifacts. 
# This can be an array or a multi-line string.
before_script:
  - pip install pipenv
  - pipenv install
Matteo04052017's avatar
.  
Matteo04052017 committed
stages:
  - test
  - deploy

# The YAML file defines a set of jobs with constraints stating when they should be run. 
# You can specify an unlimited number of jobs which are defined as top-level elements with an arbitrary name and always have to contain at least the script clause.
# In this case we have only the test job which produce an artifacts (it must be placed into a directory called "public")
# It is also specified that only the master branch will be subject of this job. 
Matteo04052017's avatar
.  
Matteo04052017 committed
test:
Matteo04052017's avatar
.  
Matteo04052017 committed
  stage: test
Matteo04052017's avatar
.  
Matteo04052017 committed
  tags:
   - docker-executor
  script:
Matteo04052017's avatar
.  
Matteo04052017 committed
   - pipenv run python setup.py test
   - mv coverage.xml htmlcov
Matteo04052017's avatar
.  
Matteo04052017 committed
  artifacts:
    paths:
    - htmlcov
dependency_check:
  stage: test
  script:
    - pipenv graph >> pipenv_deps.txt
    - dpkg -l >> system_deps.txt
    - awk 'FNR>5 {print $2 ", " $3}' system_deps.txt >> system_deps.csv
    - mv pipenv_deps.txt htmlcov
    - mv system_deps.txt htmlcov
    - mv system_deps.csv htmlcov
code_quality:
Matteo04052017's avatar
.  
Matteo04052017 committed
  tags:
    - docker-executor
  image: docker:stable
  variables:
    DOCKER_DRIVER: overlay2
  allow_failure: true
  services:
    - docker:stable-dind
Matteo04052017's avatar
Matteo04052017 committed
  before_script:
    - ls -la
  script:
    - export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
    - docker run
        --env SOURCE_CODE="$PWD"
        --volume "$PWD":/code
        --volume /var/run/docker.sock:/var/run/docker.sock
        "registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
Matteo04052017's avatar
Matteo04052017 committed
    - more gl-code-quality-report.json
Matteo04052017's avatar
.  
Matteo04052017 committed
  artifacts:
Matteo04052017's avatar
.  
Matteo04052017 committed
    paths: [gl-code-quality-report.json]

Matteo04052017's avatar
.  
Matteo04052017 committed
    - pipenv run bash code-analysis.sh
    
pages:
  stage: deploy
  tags:
   - docker-executor
  dependencies:
    - test
  script:
   - ls -la
   - mkdir .public
   - cp -r htmlcov/* .public
   - mv .public public
  artifacts:
    paths:
      - public
    expire_in: 30 days