Fakultas Ilmu Komputer UI

.gitlab-ci.yml 2.47 KB
Newer Older
1
2
3
4
5
6
7
8
9
variables:
  POSTGRES_DB: $DB_NAME
  POSTGRES_USER: $DB_USER
  POSTGRES_PASSWORD: $DB_PASSWORD
  POSTGRES_HOST_AUTH_METHOD: $DB_HOST_AUTH_METHOD

services:
  - postgres:12.2-alpine

Bayukanta Iqbal Gunawan's avatar
a  
Bayukanta Iqbal Gunawan committed
10
stages:
Bayukanta Iqbal Gunawan's avatar
a    
Bayukanta Iqbal Gunawan committed
11
  - test
M. Abdurrahman's avatar
M. Abdurrahman committed
12
  - linter
13
  - sonarqube
14
15
  - staging
  - production
Bayukanta Iqbal Gunawan's avatar
a  
Bayukanta Iqbal Gunawan committed
16

Bayukanta Iqbal Gunawan's avatar
a    
Bayukanta Iqbal Gunawan committed
17
18
19
UnitTest:
  image: python:3.7
  stage: test
20
21
22
  only:
    refs:
      - staging
23
  coverage: '/TOTAL\s+\d+\s+\d+\s+(\d+)%/'
Bayukanta Iqbal Gunawan's avatar
a    
Bayukanta Iqbal Gunawan committed
24
25
26
27
28
29
  before_script:
    - pip install -r requirements.txt
    - python manage.py migrate
    - python manage.py collectstatic --no-input
  when: on_success
  script:
30
    - coverage run --include="./*" --omit="manage.py,pplbackend/*" manage.py test
Bayukanta Iqbal Gunawan's avatar
a    
Bayukanta Iqbal Gunawan committed
31
    - coverage report -m
32
    - coverage xml
33
  artifacts:
34
    paths:
35
    - coverage.xml
36

M. Abdurrahman's avatar
M. Abdurrahman committed
37
38
39
Pylint:
  image: python:3.7
  stage: linter
40
41
42
  only:
    refs:
      - staging
M. Abdurrahman's avatar
M. Abdurrahman committed
43
44
45
46
47
  allow_failure: true
  before_script:
    - pip install -r requirements.txt
  when: on_success
  script:
48
    - pylint --load-plugins pylint_django --rcfile=./.pylintrc informasi_fasilitas layanan_khusus new_rest_api oauth registrasi
M. Abdurrahman's avatar
M. Abdurrahman committed
49

M. Abdurrahman's avatar
M. Abdurrahman committed
50
SonarScanner:
M. Abdurrahman's avatar
M. Abdurrahman committed
51
52
53
  image: 
    name: sonarsource/sonar-scanner-cli:latest
    entrypoint: [""]
54
  stage: sonarqube
55
56
57
  only:
    refs:
      - staging
M. Abdurrahman's avatar
M. Abdurrahman committed
58
59
60
  script:
    - sonar-scanner
      -Dsonar.host.url=https://pmpl.cs.ui.ac.id/sonarqube
61
      -Dsonar.login=$SONARQUBE_TOKEN
M. Abdurrahman's avatar
M. Abdurrahman committed
62
63
      -Dsonar.branch.name=$CI_COMMIT_REF_NAME
      -Dsonar.projectKey=$SONARQUBE_PROJECT_KEY
Bayukanta Iqbal Gunawan's avatar
a    
Bayukanta Iqbal Gunawan committed
64

65
Staging:
66
  image: ruby:2.4
67
  stage: staging
68
69
70
71
72
73
  only:
    refs:
      - staging
  before_script:
    - gem install dpl
    - wget -qO- https://cli-assets.heroku.com/install-ubuntu.sh | sh
74
  script:
75
76
77
78
79
80
81
    - dpl --provider=heroku --app=$HEROKU_APPNAME_STAGING --api-key=$HEROKU_APIKEY
    - export HEROKU_API_KEY=$HEROKU_APIKEY
    - heroku run --app $HEROKU_APPNAME_STAGING migrate
  environment:
    name: staging
    url: $HEROKU_APP_HOST_STAGING

82
  
Bayukanta Iqbal Gunawan's avatar
a  
Bayukanta Iqbal Gunawan committed
83
84
Deployment:
  image: ruby:2.4
85
  stage: production
86
87
  only:
    refs:
88
      - master
Bayukanta Iqbal Gunawan's avatar
a  
Bayukanta Iqbal Gunawan committed
89
  before_script:
90
91
92
93
94
95
96
    - apt-get update -qq
    - apt-get install -qq git
    - 'which ssh-agent || ( apt-get install -qq openssh-client )'
    - eval $(ssh-agent -s)
    - ssh-add <(echo $SSH_PRIVATE_KEY | base64 -d)
    - mkdir -p ~/.ssh
    - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
Bayukanta Iqbal Gunawan's avatar
a  
Bayukanta Iqbal Gunawan committed
97
  script:
98
99
100
101
102
103
104
105
    - >
      ssh admin@10.119.106.23 
      "cd poipole-dtb-beasiswa-miskin-dan-disabilitas &&
      git checkout master &&
      git pull origin master &&
      bash stop.sh &&
      bash start.sh &&
      exit"
Bayukanta Iqbal Gunawan's avatar
a  
Bayukanta Iqbal Gunawan committed
106
107
  environment:
    name: production
108
    url: $VM_URL