-
Notifications
You must be signed in to change notification settings - Fork 12
/
bitbucket-pipelines.yml
309 lines (269 loc) · 8.55 KB
/
bitbucket-pipelines.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
image: node:14.16.0
definitions:
services:
docker:
memory: 2048
caches:
docker-cache: docker-cache
steps:
- step: &set-environment
name: Set Environment
artifacts:
- environment.sh
- step: &set-aggregator
conditions: &aggregator-condition
changesets:
includePaths:
- "apps/aggregator/**"
- "libs/**"
name: Check Aggregator Changed
script:
- source environment.sh
- echo "export UPDATED_APPS='$UPDATED_APPS aggregator'" >> environment.sh
artifacts:
- environment.sh
- step: &set-aggregator-dao
conditions: &aggregator-dao-condition
changesets:
includePaths:
- "apps/aggregator-dao/**"
- "libs/**"
name: Check Aggregator DAO Changed
script:
- source environment.sh
- echo "export UPDATED_APPS='$UPDATED_APPS aggregator-dao'" >> environment.sh
artifacts:
- environment.sh
- step: &set-api
conditions: &api-condition
changesets:
includePaths:
- "apps/api/**"
- "libs/**"
name: Check API Changed
script:
- source environment.sh
- echo "export UPDATED_APPS='$UPDATED_APPS api'" >> environment.sh
artifacts:
- environment.sh
- step: &set-notifier
conditions: ¬ifier-condition
changesets:
includePaths:
- "apps/notifier/**"
- "libs/**"
name: Check Notifier Changed
script:
- source environment.sh
- echo "export UPDATED_APPS='$UPDATED_APPS notifier'" >> environment.sh
artifacts:
- environment.sh
- parallel: &build-test
- step:
conditions: *aggregator-condition
name: Build and test aggregator
caches:
- node
script:
- yarn install
- yarn test || true
- yarn lint . || true
- yarn build aggregator
- step:
conditions: *aggregator-dao-condition
name: Build and test aggregator-dao
caches:
- node
script:
- yarn install
- yarn test || true
- yarn lint . || true
- yarn build aggregator-dao
- step:
conditions: *api-condition
name: Build and test api
caches:
- node
script:
- yarn install
- yarn test || true
- yarn lint . || true
- yarn build api
- step:
conditions: *notifier-condition
name: Build and test notifier
caches:
- node
script:
- yarn install
- yarn test || true
- yarn lint . || true
- yarn build notifier
- parallel: &docker-build-publish
- step:
conditions: *aggregator-condition
name: Docker - Build and Publish aggregator
<<: &docker-service
services:
- docker
caches:
- docker-cache
script:
- source environment.sh
- export APP_NAME=aggregator
- &docker-load-cache >-
if [[ -f "docker-cache/cache.tar" ]]; then
docker load < docker-cache/cache.tar;
fi
- &docker-build >-
docker build
--build-arg APP_NAME=$APP_NAME
-t sputnik-v2-${APP_NAME}:latest
-t sputnik-v2-${APP_NAME}:develop-latest
-t sputnik-v2-${APP_NAME}:$DOCKER_ENV_TAG
.
- >-
docker save $(docker images -qa) > docker-cache/cache.tar;
- &docker-push
pipe: atlassian/aws-ecr-push-image:1.4.2
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION
IMAGE_NAME: sputnik-v2-${APP_NAME}
TAGS: >-
latest
develop-latest
$DOCKER_ENV_TAG
- step:
conditions: *aggregator-dao-condition
name: Docker - Build and Publish aggregator-dao
<<: *docker-service
script:
- source environment.sh
- export APP_NAME=aggregator-dao
- *docker-load-cache
- *docker-build
- *docker-push
- step:
conditions: *api-condition
name: Docker - Build and Publish api
<<: *docker-service
script:
- source environment.sh
- export APP_NAME=api
- *docker-load-cache
- *docker-build
- *docker-push
- step:
conditions: *notifier-condition
name: Docker - Build and Publish notifier
<<: *docker-service
script:
- source environment.sh
- export APP_NAME=notifier
- *docker-load-cache
- *docker-build
- *docker-push
- step: &helm-build-deploy
name: Helm - Build and Deploy
image: alpine/helm:3.6.3
script:
- source environment.sh
- mkdir manifests
- |
for APP_NAME in $UPDATED_APPS
do
export CHART_FOLDER=apps/${APP_NAME}/deployment/app-chart
helm lint $CHART_FOLDER
helm template sputnik-v2-$APP_NAME $CHART_FOLDER \
--set image.tag=$DOCKER_ENV_TAG \
--set environment.near_env=$NEAR_ENV \
--set environment.near_contract_name=$NEAR_CONTRACT_NAME \
--set environment.near_token_factory_contract_name=$NEAR_TOKEN_FACTORY_CONTRACT_NAME \
--set environment.near_bridge_token_factory_contract_name=$NEAR_BRIDGE_TOKEN_FACTORY_CONTRACT_NAME \
--set environment.wallet_callback_url=$WALLET_CALLBACK_URL \
--set environment.frontend_url=FRONTEND_URL \
--set ingress.host=$K8S_INGRESS_HOST \
> manifests/$APP_NAME.yml
done
- pipe: atlassian/aws-eks-kubectl-run:2.2.0
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION
CLUSTER_NAME: $EKS_CLUSTER_NAME
KUBECTL_COMMAND: 'apply'
RESOURCE_PATH: 'manifests'
KUBECTL_ARGS:
- "--namespace=$DEPLOYMENT_NAMESPACE"
artifacts:
- manifests/**
- environment.sh
pipelines:
pull-requests:
'**':
- parallel: *build-test
branches:
develop:
- step:
<<: *set-environment
script:
- >-
echo export DOCKER_ENV_TAG=develop-$BITBUCKET_COMMIT >> environment.sh
- step: *set-aggregator
- step: *set-aggregator-dao
- step: *set-api
- step: *set-notifier
- parallel: *build-test
- parallel: *docker-build-publish
- step:
<<: *helm-build-deploy
deployment: Development
staging:
- step:
<<: *set-environment
script:
- >-
echo export DOCKER_ENV_TAG=staging-$BITBUCKET_COMMIT >> environment.sh
- step: *set-aggregator
- step: *set-aggregator-dao
- step: *set-api
- step: *set-notifier
- parallel: *build-test
- parallel: *docker-build-publish
- step:
<<: *helm-build-deploy
deployment: Staging
custom:
test:
- step:
<<: *set-environment
script:
- >-
echo export DOCKER_ENV_TAG=test-$BITBUCKET_COMMIT >> environment.sh
- step: *set-aggregator
- step: *set-aggregator-dao
- step: *set-api
- step: *set-notifier
- parallel: *build-test
- parallel: *docker-build-publish
- step:
<<: *helm-build-deploy
deployment: Test
tags:
'*':
- step:
<<: *set-environment
script:
- >-
echo export DOCKER_ENV_TAG=$BITBUCKET_TAG >> environment.sh
- step: *set-aggregator
- step: *set-aggregator-dao
- step: *set-api
- step: *set-notifier
- parallel: *build-test
- parallel: *docker-build-publish
- step:
<<: *helm-build-deploy
deployment: Production