Fakultas Ilmu Komputer UI

.gitlab-ci.yml 2.88 KB
Newer Older
1
---
2
image: python:buster
3
4
5
6
7
8

stages:
  - build
  - test
  - deploy

9
10
11
12
13
14
15
16
17
18
19
20
test-frontend:
  image: amio/node-chrome:latest
  stage: test
  script:
    - npm install
    - npm run build-production
    - npm run karma
  artifacts:
    paths:
      - test/

test-backend:
21
22
23
24
25
26
27
  services:
    - postgres:9.6-alpine
  variables:
    POSTGRES_DB: kape
    POSTGRES_USER: kape
    POSTGRES_PASSWORD: kape
  stage: test
Zamil Majdy's avatar
Zamil Majdy committed
28
  script:
29
    - pip install -r requirements.txt
30
31
    - python3 manage.py makemigrations
    - python3 manage.py migrate
32
    - python3 manage.py test -v 2
33
34
35
  artifacts:
    paths:
      - test/
Zamil Majdy's avatar
Zamil Majdy committed
36

37
38
SonarScanner Analysis:
  image: addianto/sonar-scanner-cli:latest
Syahrul Findi's avatar
Syahrul Findi committed
39
40
41
42
  stage: deploy
  dependencies:
    - test-backend
    - test-frontend
43
44
45
46
47
48
49
  script:
    - sonar-scanner
      -Dsonar.host.url=$SONARQUBE_HOST
      -Dsonar.login=$SONARQUBE_TOKEN
  only:
    - master

50
51
52
pages:
  stage: deploy
  dependencies:
53
54
    - test-backend
    - test-frontend
55
56
57
58
59
60
  script:
    - mv test/ public/
  artifacts:
    paths:
      - public
    expire_in: 30 days
61

Zamil Majdy's avatar
Zamil Majdy committed
62
staging:
63
  stage: deploy
Zamil Majdy's avatar
Zamil Majdy committed
64
  script:
65
66
67
68
69
70
71
72
73
74
    - apt-get update -qy
    - apt-get install sshpass
    - git clone https://gitlab.com/PPL2017csui/PPLA1.git
    - cd PPLA1
    - git checkout develop
    - git pull
    - git remote add deployment ssh://kape@bot.recruit.id:8023/home/kape.git
    - mkdir ~/.ssh
    - echo -e "Host bot.recruit.id\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
    - sshpass -p yukcarikape git push deployment develop:master --force
75
  only:
76
    - develop
Zamil Majdy's avatar
Zamil Majdy committed
77
78

production:
79
  stage: deploy
Zamil Majdy's avatar
Zamil Majdy committed
80
  script:
Hafiyyan 's avatar
Hafiyyan committed
81
82
83
84
85
86
87
88
89
90
    - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
    - eval $(ssh-agent -s)
    - ssh-add <(echo "$KEY_DEPLOYMENT")
    - mkdir -p ~/.ssh
    - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
    - ssh-keyscan -t rsa 10.119.234.71 >> ~/.ssh/known_hosts
    - ssh hafiyyan94_gmail_com@35.240.226.230 'sudo bash /home/hafiyyan94_gmail_com/deployment.sh'
  environment:
    name: production_gcp
    url: $PRODUCTION_GCP
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
  only:
    - master

Publish Container Image:
  image: docker:19-git
  stage: deploy
  services:
    # Workaround from https://forum.gitlab.com/t/docker-dind-stops-working-after-12-1-0-update/28664/2
    - name: docker:19-dind
      entrypoint: ["env", "-u", "DOCKER_HOST"]
      command: ["dockerd-entrypoint.sh"]
  variables:
    DOCKER_HOST: tcp://docker:2375/
    DOCKER_DRIVER: overlay2
    DOCKER_TLS_CERTDIR: ""
  before_script:
    - docker info
    - docker login -u $DOCKERHUB_USERNAME -p $DOCKERHUB_PASSWORD
  script:
    - docker build
      --build-arg=NPM_PROXY=$NPM_PROXY
      --build-arg=IMAGE_CREATED="$(date --utc -Iseconds)"
      --build-arg=IMAGE_REVISION="$(git show --pretty=oneline | tac | tail -n 1 | awk '{print $1}')"
      --tag $IMAGE_NAMESPACE/kape:latest .
    - docker push $IMAGE_NAMESPACE/kape:latest
  tags:
    - docker
  retry: 1
  allow_failure: true
Zamil Majdy's avatar
Zamil Majdy committed
120
  only:
121
    - master