-
Notifications
You must be signed in to change notification settings - Fork 1
/
.gitlab-ci.yml
232 lines (211 loc) · 5.96 KB
/
.gitlab-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
stages:
- merge-check
- build
- analyze
- package
- deploy
variables:
SONAR_HOST_URL: "http://gitlab.itti.com.pl:8083"
.cache_web_def: &cache_web_def
cache:
key: "${CI_PROJECT_NAME}_web"
untracked: true
paths:
- $CI_PROJECT_DIR/web/node_modules
- $CI_PROJECT_DIR/cache
.cache_api_def: &cache_api_def
cache:
key: "${CI_PROJECT_NAME}_api"
untracked: true
paths:
- $CI_PROJECT_DIR/cache
.ssh_deploy_key_testing_def: &ssh_deploy_key_testing_def
before_script:
# Install ssh-agent if not already installed
- 'which ssh-agent || ( apk update && apk add --update openssh-client && echo -e "Host *\nUseRoaming no" >> /etc/ssh/ssh_config )'
# Run ssh-agent (inside the build environment)
- 'eval $(ssh-agent -s)'
# Add the SSH key stored in variable to the agent store
- 'mkdir -m 700 -p ~/.ssh && echo "$SSH_DEPLOY_KEY_TESTING" > ~/.ssh/id_rsa && chmod 600 ~/.ssh/id_rsa'
- 'ssh-add ~/.ssh/id_rsa'
# Add the the server's host key stored in SSH_HOST_KEY_*
# variable to the list of known hosts
- '[[ -f /.dockerenv ]] && echo "$SSH_HOST_KEY_TESTING" >> ~/.ssh/known_hosts'
# ====================
# API - DEVELOP
# ====================
develop:api:build:
stage: build
only:
- develop
tags:
- default-api
<<: *cache_api_def
image: openjdk:8
script:
- cd api ; ./gradlew -g $CI_PROJECT_DIR/cache/gradle clean assemble -i
artifacts:
when: on_success
expire_in: 12 hrs
paths:
- api/build/
# develop:api:analyze:
# stage: analyze
# only:
# - develop
# tags:
# - default-api
# <<: *cache_api_def
# image: openjdk:8
# services:
# - postgres:9.6-alpine
# variables:
# POSTGRES_DB: itti_driver
# POSTGRES_USER: itti_driver
# POSTGRES_PASSWORD: APEKxySwg4Ku9yxz
# SPRING_PROFILES_ACTIVE: integration
# script:
# - cd api ; ./gradlew -g $CI_PROJECT_DIR/cache/gradle clean test sonarqube -i
develop:api:package:
stage: package
only:
- develop
tags:
- default-api
image: alpine:3.5
dependencies:
- develop:api:build
script:
- cd api/build/libs ; tar zcvf "dist_${CI_PROJECT_NAME}_api_$(date +%Y-%m-%d)_${CI_PIPELINE_ID}.tar.gz" *.war
artifacts:
when: on_success
expire_in: 1 week
paths:
- "api/build/libs/dist_${CI_PROJECT_NAME}_api_$(date +%Y-%m-%d)_${CI_PIPELINE_ID}.tar.gz"
develop:api:deploy:
stage: deploy
only:
- develop
tags:
- default-api
image: alpine:3.5
dependencies:
- develop:api:package
<<: *ssh_deploy_key_testing_def
script:
- scp api/build/libs/dist_${CI_PROJECT_NAME}_api_$(date +%Y-%m-%d)_${CI_PIPELINE_ID}.tar.gz [email protected]:/home/perpixel/driver/dist
- ssh [email protected] "sudo /home/perpixel/driver/bin/deploy-api.sh"
environment:
name: testing
# ====================
# API - MERGE-CHECK
# ====================
merge-check:api:build:
stage: merge-check
only:
- /^be-.*$/
tags:
- default-api
<<: *cache_api_def
image: openjdk:8
services:
- name: postgres:9.6-alpine
alias: ost_db
variables:
POSTGRES_DB: itti_driver
POSTGRES_USER: itti_driver
POSTGRES_PASSWORD: EyDdqz7qPZFFJNUs
SPRING_PROFILES_ACTIVE: integration
before_script:
- 'which git || ( apk update && apk add --update bash git openssh-client )'
- git config --global user.email "[email protected]" ; git config --global user.name "GitLab CI Runner"
script:
- git fetch ; git merge origin/develop
- cd api ; ./gradlew -g $CI_PROJECT_DIR/cache/gradle clean test -i
# ====================
# WEB - DEVELOP
# ====================
develop:web:build:
stage: build
only:
- develop
tags:
- default-web
<<: *cache_web_def
image: node:6.10-alpine
script:
- cd web ;
- npm install phantomjs-prebuilt
- npm install node-sass
- npm install
- npm run deploy:prod
artifacts:
when: on_success
expire_in: 12 hrs
paths:
- web/dist/
# develop:web:analyze:
# stage: analyze
# only:
# - develop
# tags:
# - default-web
# image: openjdk:8-alpine
# before_script:
# - apk add --no-cache curl grep sed unzip
# - mkdir -p $CI_PROJECT_DIR/cache/sonar ; cd $CI_PROJECT_DIR/cache/sonar ; curl --insecure -o ./sonarscanner.zip -L http://central.maven.org/maven2/org/sonarsource/scanner/cli/sonar-scanner-cli/3.0.3.778/sonar-scanner-cli-3.0.3.778.zip && unzip sonarscanner.zip && rm sonarscanner.zip
# - echo "sonar.host.url=$SONAR_HOST_URL" > $CI_PROJECT_DIR/cache/sonar/sonar-scanner-3.0.3.778/conf/sonar-scanner.properties
# script:
# - cd $CI_PROJECT_DIR/web ; $CI_PROJECT_DIR/cache/sonar/sonar-scanner-*/bin/sonar-scanner
develop:web:package:
stage: package
only:
- develop
tags:
- default-web
image: alpine:3.5
dependencies:
- develop:web:build
script:
- cd web/dist; echo "1.0.$CI_PIPELINE_ID" > version.txt; tar zcvf "dist_${CI_PROJECT_NAME}_web_$(date +%Y-%m-%d)_${CI_PIPELINE_ID}.tar.gz" *
artifacts:
when: on_success
expire_in: 1 week
paths:
- "web/dist/dist_${CI_PROJECT_NAME}_web_$(date +%Y-%m-%d)_${CI_PIPELINE_ID}.tar.gz"
develop:web:deploy:
stage: deploy
only:
- develop
tags:
- default-web
image: alpine:3.5
dependencies:
- develop:web:package
<<: *ssh_deploy_key_testing_def
script:
- scp web/dist/dist_${CI_PROJECT_NAME}_web_$(date +%Y-%m-%d)_${CI_PIPELINE_ID}.tar.gz [email protected]:/home/perpixel/driver/dist
- ssh [email protected] "sudo /home/perpixel/driver/bin/deploy-web.sh"
environment:
name: testing
# ====================
# WEB - MERGE-CHECK
# ====================
merge-check:web:build:
stage: merge-check
only:
- /^fe-.*$/
tags:
- default-web
<<: *cache_web_def
image: node:6.10-alpine
before_script:
- 'which git || ( apk update && apk add --update bash git openssh-client )'
- git config --global user.email "[email protected]" ; git config --global user.name "GitLab CI Runner"
script:
- git fetch ; git merge origin/develop
- cd web
- npm install phantomjs-prebuilt
- npm install node-sass
- npm install
- npm run deploy:prod