-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.gitlab-ci.yml
337 lines (304 loc) · 11.1 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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
# Gitlab CI yml file
# This is the major part of the code which explains the stages present in our pipeline.
# In a django application we have various stages which include testing, packing the code,
# performing migrations, collecting static files and running the application.
# The various stages are broadly classified into 3 main categories:
# 1. Test 2. Release 3. Deploy
stages:
- test
- release
- deploy
variables:
OMIT_COVERAGE: '*/tests/*,*/tests.py,*/migrations/*,*/urls.py,*/settings.py,*/wsgi.py,manage.py'
# Stage I
# Testing Phase:
# This is where the main code is tested.
# Other options like code coverage, etc are also written in this phase
unit_test:
stage: test
# This repo includes python3, pip3
image: python:3-alpine
before_script:
- apk add --no-cache git
# install requiriment to hubcare_api
- pip install -r hubcare/hubcare_api/requirements.txt
- python hubcare/hubcare_api/manage.py makemigrations
- python hubcare/hubcare_api/manage.py migrate
# install requiriment to commit metrics
- pip install -r hubcare/metrics/commit_metrics/requirements.txt
- python hubcare/metrics/commit_metrics/manage.py makemigrations
- python hubcare/metrics/commit_metrics/manage.py migrate
# install requiriment to community metrics
- pip install -r hubcare/metrics/community_metrics/requirements.txt
- python hubcare/metrics/community_metrics/manage.py makemigrations
- python hubcare/metrics/community_metrics/manage.py migrate
# install requiriment to issue metrics
- pip install -r hubcare/metrics/issue_metrics/requirements.txt
- python hubcare/metrics/issue_metrics/manage.py makemigrations
- python hubcare/metrics/issue_metrics/manage.py migrate
# install requiriment to pull_request metrics
- pip install -r hubcare/metrics/pull_request_metrics/requirements.txt
- python hubcare/metrics/pull_request_metrics/manage.py makemigrations
- python hubcare/metrics/pull_request_metrics/manage.py migrate
# install requiriment to repository service
- pip install -r hubcare/repository/requirements.txt
- python hubcare/repository/manage.py makemigrations
- python hubcare/repository/manage.py migrate
script:
# Command to test our application
- coverage run --source='.' --omit=$OMIT_COVERAGE hubcare/hubcare_api/manage.py test hubcare/hubcare_api/
- coverage run --source='.' --omit=$OMIT_COVERAGE --append hubcare/metrics/commit_metrics/manage.py test hubcare/metrics/commit_metrics/
- coverage run --source='.' --omit=$OMIT_COVERAGE --append hubcare/metrics/community_metrics/manage.py test hubcare/metrics/community_metrics/
- coverage run --source='.' --omit=$OMIT_COVERAGE --append hubcare/metrics/issue_metrics/manage.py test hubcare/metrics/issue_metrics/
- coverage run --source='.' --omit=$OMIT_COVERAGE --append hubcare/metrics/pull_request_metrics/manage.py test hubcare/metrics/pull_request_metrics/
- coverage run --source='.' --omit=$OMIT_COVERAGE --append hubcare/repository/manage.py test hubcare/repository/
- coverage report
- coveralls
codestyle:
stage: test
# This repo includes python3, pip3
image: python:3-alpine
before_script:
- pip install pycodestyle
script:
- pycodestyle .
# Stage II
# Release Phase
# In this phase, we package our code using docker
.release:
stage: release
image: docker:latest
services:
- docker:dind
script:
# Build our image using docker
- docker build -f docker/Dockerfile $IMAGEPATH --build-arg NAME=$NAME --build-arg TOKEN=$TOKEN -t registry.gitlab.com/cjjcastro/2019-1-hubcare-api/$DOCKERIMAGE:$DOCKERTAG
# Configure container registry to push using docker
- docker login -u "$DOCKERLOGIN" -p "$DOCKERPASSWORD" registry.gitlab.com
# Push the image using docker
- docker push registry.gitlab.com/cjjcastro/2019-1-hubcare-api/$DOCKERIMAGE:$DOCKERTAG
# The tag, only master indicates that whenever code is pushed to master branch,
# only then run the pipeline
# Release to hubcare api service
release_hubcare_api_production:
extends: .release
environment: production_hubcare_api
only:
- master
release_hubcare_api_development:
extends: .release
environment: development_hubcare_api
only:
- devel
# Release to commit metrics service
release_commit_metrics_production:
extends: .release
environment: production_commit_metrics
only:
- master
release_commit_metrics_development:
extends: .release
environment: development_commit_metrics
only:
- devel
# Release to community metrics service
release_community_metrics_production:
extends: .release
environment: production_community_metrics
only:
- master
release_community_metrics_development:
extends: .release
environment: development_community_metrics
only:
- devel
# Release to issue metrics service
release_issue_metrics_production:
extends: .release
environment: production_issue_metrics
only:
- master
release_issue_metrics_development:
extends: .release
environment: development_issue_metrics
only:
- devel
# Release to pull request metrics service
release_pull_request_metrics_production:
extends: .release
environment: production_pull_request_metrics
only:
- master
release_pull_request_metrics_development:
extends: .release
environment: development_pull_request_metrics
only:
- devel
# Release to repository service
release_repository_production:
extends: .release
environment: production_repository
only:
- master
release_repository_development:
extends: .release
environment: development_repository
only:
- devel
# Stage III - I
# Deployment Phase
# Production deploy
deploy_hubcare_api:
image: cdrx/rancher-gitlab-deploy
stage: deploy
script:
- "upgrade
--rancher-url $RANCHER_URL
--rancher-key $RANCHER_ACCESS_KEY
--rancher-secret $RANCHER_SECRET_KEY
--environment $RANCHER_ENVIRONMENT
--stack $RANCHER_STACK
--service hubcare-api"
only:
- master
deploy_commit_metrics:
image: cdrx/rancher-gitlab-deploy
stage: deploy
script:
- "upgrade
--rancher-url $RANCHER_URL
--rancher-key $RANCHER_ACCESS_KEY
--rancher-secret $RANCHER_SECRET_KEY
--environment $RANCHER_ENVIRONMENT
--stack $RANCHER_STACK
--service commit-metrics"
only:
- master
deploy_community_metrics:
image: cdrx/rancher-gitlab-deploy
stage: deploy
script:
- "upgrade
--rancher-url $RANCHER_URL
--rancher-key $RANCHER_ACCESS_KEY
--rancher-secret $RANCHER_SECRET_KEY
--environment $RANCHER_ENVIRONMENT
--stack $RANCHER_STACK
--service community-metrics"
only:
- master
deploy_issue_metrics:
image: cdrx/rancher-gitlab-deploy
stage: deploy
script:
- "upgrade
--rancher-url $RANCHER_URL
--rancher-key $RANCHER_ACCESS_KEY
--rancher-secret $RANCHER_SECRET_KEY
--environment $RANCHER_ENVIRONMENT
--stack $RANCHER_STACK
--service issue-metrics"
only:
- master
deploy_pull_request_metrics:
image: cdrx/rancher-gitlab-deploy
stage: deploy
script:
- "upgrade
--rancher-url $RANCHER_URL
--rancher-key $RANCHER_ACCESS_KEY
--rancher-secret $RANCHER_SECRET_KEY
--environment $RANCHER_ENVIRONMENT
--stack $RANCHER_STACK
--service pull-request-metrics"
only:
- master
deploy_repository:
image: cdrx/rancher-gitlab-deploy
stage: deploy
script:
- "upgrade
--rancher-url $RANCHER_URL
--rancher-key $RANCHER_ACCESS_KEY
--rancher-secret $RANCHER_SECRET_KEY
--environment $RANCHER_ENVIRONMENT
--stack $RANCHER_STACK
--service repository"
only:
- master
# Development deploy in Heroku
deploy_hubcare_api_dev:
stage: deploy
image: docker:latest
services:
- docker:dind
script:
- docker login --username=_ --password=$HEROKU_API_KEY registry.heroku.com
- docker pull registry.gitlab.com/cjjcastro/2019-1-hubcare-api/hubcare_api:latest
- docker tag registry.gitlab.com/cjjcastro/2019-1-hubcare-api/hubcare_api:latest registry.heroku.com/hubcare-api/web:latest
- docker push registry.heroku.com/hubcare-api/web:latest
- docker run --rm -e HEROKU_API_KEY=$HEROKU_API_KEY wingrunr21/alpine-heroku-cli container:release web --app hubcare-api
tags:
- docker
only:
- devel
deploy_commit_metrics_dev:
stage: deploy
image: docker:latest
services:
- docker:dind
script:
- docker login --username=_ --password=$HEROKU_API_KEY registry.heroku.com
- docker pull registry.gitlab.com/cjjcastro/2019-1-hubcare-api/commit_metrics:latest
- docker tag registry.gitlab.com/cjjcastro/2019-1-hubcare-api/commit_metrics:latest registry.heroku.com/hubcare-commit-metrics/web:latest
- docker push registry.heroku.com/hubcare-commit-metrics/web:latest
- docker run --rm -e HEROKU_API_KEY=$HEROKU_API_KEY wingrunr21/alpine-heroku-cli container:release web --app hubcare-commit-metrics
tags:
- docker
only:
- devel
deploy_community_metrics_dev:
stage: deploy
image: docker:latest
services:
- docker:dind
script:
- docker login --username=_ --password=$HEROKU_API_KEY registry.heroku.com
- docker pull registry.gitlab.com/cjjcastro/2019-1-hubcare-api/community_metrics:latest
- docker tag registry.gitlab.com/cjjcastro/2019-1-hubcare-api/community_metrics:latest registry.heroku.com/hubcare-community-metrics/web:latest
- docker push registry.heroku.com/hubcare-community-metrics/web:latest
- docker run --rm -e HEROKU_API_KEY=$HEROKU_API_KEY wingrunr21/alpine-heroku-cli container:release web --app hubcare-community-metrics
tags:
- docker
only:
- devel
deploy_issue_metrics_dev:
stage: deploy
image: docker:latest
services:
- docker:dind
script:
- docker login --username=_ --password=$HEROKU_API_KEY registry.heroku.com
- docker pull registry.gitlab.com/cjjcastro/2019-1-hubcare-api/issue_metric:latest
- docker tag registry.gitlab.com/cjjcastro/2019-1-hubcare-api/issue_metric:latest registry.heroku.com/hubcare-issue-metrics/web:latest
- docker push registry.heroku.com/hubcare-issue-metrics/web:latest
- docker run --rm -e HEROKU_API_KEY=$HEROKU_API_KEY wingrunr21/alpine-heroku-cli container:release web --app hubcare-issue-metrics
tags:
- docker
only:
- devel
deploy_pull_request_metrics_metrics_dev:
stage: deploy
image: docker:latest
services:
- docker:dind
script:
- docker login --username=_ --password=$HEROKU_API_KEY registry.heroku.com
- docker pull registry.gitlab.com/cjjcastro/2019-1-hubcare-api/pull_request_metrics:latest
- docker tag registry.gitlab.com/cjjcastro/2019-1-hubcare-api/pull_request_metrics:latest registry.heroku.com/hubcare-pull-request-metrics/web:latest
- docker push registry.heroku.com/hubcare-pull-request-metrics/web:latest
- docker run --rm -e HEROKU_API_KEY=$HEROKU_API_KEY wingrunr21/alpine-heroku-cli container:release web --app hubcare-pull-request-metrics
tags:
- docker
only:
- devel