Fakultas Ilmu Komputer UI

.gitlab-ci.yml 2.25 KB
Newer Older
1
2
stages:
  - test
Dave Nathanael's avatar
Dave Nathanael committed
3
  - sonar-scanner
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  - deploy

test:
  image: python:3.6.5
  stage: test
  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
  script:
    - echo "Starting tests"
Dave Nathanael's avatar
Dave Nathanael committed
18
19
20
    - coverage erase
    - coverage run --include="./*/*" --omit="./env/*","./project/*","./manage.py" manage.py test apps
    - coverage xml -i
21
    - coverage report -m
Dave Nathanael's avatar
Dave Nathanael committed
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
  artifacts:
    paths:
      - coverage.xml

SonarScanner:
  image:
    name: sonarsource/sonar-scanner-cli:latest
    entrypoint: [""]
  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
37
38
39
40
41
42
43
44
45
46

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