Fakultas Ilmu Komputer UI

.gitlab-ci.yml 2.3 KB
Newer Older
1
2
stages:
  - test
3
  - sonar-scanner
4
5
6
  - deploy

test:
7
  image: python:3.6.5
8
  stage: test
9
10
11
12
13
14
15
  before_script:
    - pip install -r requirements.txt
    - python manage.py makemigrations
    - python manage.py migrate
    - python manage.py collectstatic --no-input
    - python manage.py runserver 8000 &
  when: on_success
16
  script:
17
18
    - echo "Starting linter"
    - sh lint.sh
19
    - echo "Starting tests"
20
    - coverage erase
21
    - coverage run --include="./*/*" --omit="./env/*","./project/*","./manage.py" manage.py test apps
22
    - coverage xml -i
23
    - coverage report -m
24
25
26
27
28
  artifacts:
    paths:
      - coverage.xml

SonarScanner:
29
30
31
  image:
    name: sonarsource/sonar-scanner-cli:latest
    entrypoint: [""]
32
33
34
35
36
37
38
  stage: sonar-scanner
  script:
    - sonar-scanner
      -Dsonar.host.url=$SONARQUBE_URL
      -Dsonar.login=$SONARQUBE_TOKEN
      -Dsonar.branch.name=$CI_COMMIT_REF_NAME
      -Dsonar.projectKey=$SONARQUBE_PROJECT_KEY
39
40

deploy:
41
  image: ruby:2.4
42
  stage: deploy
43
44
45
  before_script:
    - gem install dpl
    - wget -qO- https://cli-assets.heroku.com/install-ubuntu.sh | sh
46
47
48
    - >
      if [[ "${CI_COMMIT_REF_NAME}" == "staging" ]];
      then
49
        export HEROKU_APP_NAME=$HEROKU_STAGING_APP
50
51
        HEROKU_APP_HOST=http://tuberculosis-ppti-staging.herokuapp.com/
        ENVIRONMENT_NAME=staging
52
53
54
55
56
        DATABASE_URL=$DATABASE_URL_STAGING
        export DATABASE_NAME=$DATABASE_NAME_STAGING
        export DATABASE_USER=$DATABASE_USER_STAGING
        export DATABASE_PASSWORD=$DATABASE_PASSWORD_STAGING
        export DATABASE_HOST=$DATABASE_HOST_STAGING
57
58
      elif [[ "${CI_COMMIT_REF_NAME}" == "master" ]];
      then
59
        export HEROKU_APP_NAME=$HEROKU_PRODUCTION_APP
60
61
        HEROKU_APP_HOST=http://tuberculosis-ppti.herokuapp.com/
        ENVIRONMENT_NAME=production
62
        DATABASE_URL=$DATABASE_URL_PRODUCTION
63
64
65
66
        export DATABASE_NAME=$DATABASE_NAME_PROD
        export DATABASE_USER=$DATABASE_USER_PROD
        export DATABASE_PASSWORD=$DATABASE_PASSWORD_PROD
        export DATABASE_HOST=$DATABASE_HOST_PROD
67
      fi
68
69
    - export DATABASE_PORT=5432
    - export DATABASE_IS_PSQL=true
70
  script:
71
    - dpl --provider=heroku --app=$HEROKU_APP_NAME --api-key=$HEROKU_API_KEY
72
    - export HEROKU_API_KEY=$HEROKU_API_KEY
73
74
75
  only:
    - staging
    - master
76
77
78
  environment:
    name: $ENVIRONMENT_NAME
    url: $HEROKU_APP_HOST