-
Notifications
You must be signed in to change notification settings - Fork 1
/
.gitlab-ci.yml
204 lines (183 loc) · 4.34 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
stages:
- code
- tests
- quality scan
- quality metrics
- build
- build chart
- deploy
.only_branches: &only_branches
only:
- /^(\d{2,})(\_[a-zA-Z0-9]+)+$/
- /^((hotfix)\_\d{2,})(\_[a-zA-Z0-9]+)+$/
- main
- devel
- tags
########### Code ###########
eslint:
image: node:14-slim
stage: code
before_script:
- npm install
script:
- npm run lint-report
artifacts:
public: true
paths:
- lint-report.html
extends:
- .only_branches
########### Tests ###########
unit_test:
image: node:14-slim
stage: tests
before_script:
- npm install
- cp $FIREBASE_SERVICE service-account.json
- cp $FIREBASE_CLIENT firebase-account.json
script:
- npm run test
artifacts:
public: true
paths:
- test-report.xml
- coverage/lcov.info
extends:
- .only_branches
########### Quality Scan ###########
sonar_scanner:
image: sonarsource/sonar-scanner-cli:4.4
stage: quality scan
script:
- sonar-scanner -Dproject.settings=$CI_PROJECT_DIR/sonar-project.properties -Dsonar.login=$SONAR_TOKEN
extends:
- .only_branches
dependencies:
- unit_test
sonar metrics:
image: debian
stage: quality metrics
variables:
METRICS_URL: https://sonarcloud.io/api/measures/component_tree?component=Eccoar_2020.2-Eccoar_Users&metricKeys=files,functions,complexity,comment_lines_density,duplicated_lines_density,security_rating,tests,test_success_density,test_execution_time,reliability_rating,coverage,ncloc&ps=500
before_script:
- apt update
- apt install wget git -y
- mkdir tmp && cd tmp
script:
- wget $METRICS_URL -O eccoar-user-$CI_COMMIT_BRANCH-metrics.json
only:
- main
- tags
- 186_pipeline_user
artifacts:
public: true
paths:
- tmp/*.json
########### Build ###########
.build_:
image: docker:19.03.12
services:
- docker:19.03.12-dind
stage: build
before_script:
- docker login -u $DOCKER_USER -p $DOCKER_PASSWORD
- export DOCKER_IMAGE=$(echo "$DOCKER_IMAGE:$DOCKER_TAG" | tr '[:upper:]' '[:lower:]')
- cp $FIREBASE_SERVICE service-account.json
- cp $FIREBASE_CLIENT firebase-account.json
script:
- docker build . -t $DOCKER_IMAGE
- docker push $DOCKER_IMAGE
extends:
- .only_branches
build general:
variables:
DOCKER_TAG: $CI_COMMIT_SHORT_SHA
DOCKER_IMAGE: $DOCKER_USER/$CI_PROJECT_NAME
extends:
- .only_branches
- .build_
build homolog:
variables:
DOCKER_TAG: homolog
DOCKER_IMAGE: $DOCKER_USER/$CI_PROJECT_NAME
only:
- main
- 186_pipeline_user
extends:
- .build_
build prod:
variables:
DOCKER_TAG: $CI_COMMIT_TAG
DOCKER_IMAGE: $DOCKER_USER/$CI_PROJECT_NAME
only:
- tags
extends:
- .build_
########## Chart ##########
.helm_build:
stage: build chart
image: dtzar/helm-kubectl:3.5.0
script:
- cd chart
- kubectl get services -n $AMBIENTE
- helm lint ./$CHART_NAME
- echo $CHART_VERSION
- helm package ./$CHART_NAME --app-version $APP_VERSION --version $CHART_VERSION
artifacts:
public: true
paths:
- chart/$CHART_NAME-$CHART_VERSION.tgz
helm hm:
variables:
CHART_NAME: eccoar-user
AMBIENTE: homolog
APP_VERSION: $CI_COMMIT_SHORT_SHA
CHART_VERSION: 1.0.0-hm.$CI_COMMIT_REF_SLUG.$CI_COMMIT_SHORT_SHA
only:
- 186_pipeline_user
- main
extends:
- .helm_build
helm prod:
variables:
CHART_NAME: eccoar-user
AMBIENTE: prod
APP_VERSION: $CI_COMMIT_TAG
CHART_VERSION: $CI_COMMIT_TAG
only:
- tags
extends:
- .helm_build
########## Deploy ##########
.deploy_:
image: dtzar/helm-kubectl:3.5.0
stage: deploy
before_script:
- export CHART_PATH=chart/$CHART_NAME-$CHART_VERSION.tgz
script:
- kubectl get services -n $AMBIENTE
- helm upgrade $WORKLOAD_NAME $CHART_PATH --install --namespace $AMBIENTE --set image.tag=$DOCKER_TAG
deploy hm:
variables:
DOCKER_TAG: homolog
WORKLOAD_NAME: eccoar-user
AMBIENTE: homolog
CHART_NAME: eccoar-user
CHART_VERSION: 1.0.0-hm.$CI_COMMIT_REF_SLUG.$CI_COMMIT_SHORT_SHA
only:
- 186_pipeline_user
- main
extends:
- .deploy_
deploy prod:
variables:
DOCKER_TAG: $CI_COMMIT_TAG
WORKLOAD_NAME: eccoar-user
AMBIENTE: prod
APP_VERSION: $CI_COMMIT_TAG
CHART_NAME: eccoar-user
CHART_VERSION: $CI_COMMIT_TAG
only:
- tags
extends:
- .deploy_