-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path.gitlab-ci.yml
More file actions
417 lines (368 loc) · 13.4 KB
/
Copy path.gitlab-ci.yml
File metadata and controls
417 lines (368 loc) · 13.4 KB
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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
variables:
AUTO_DEPLOY_IMAGE_VERSION: v2.50.0
CI_TEMPLATE_REGISTRY_HOST: registry.gitlab.com
DOCKER_TLS_CERTDIR: ""
DOCKER_HOST: tcp://docker:2375/
DOCKER_DRIVER: overlay2
HELM_VERSION: 3.10.2
KUBE_CONTEXT: voltaire/www.1694.io:1694
KUBERNETES_SERVICE_ACCOUNT_OVERWRITE: gitlab-admin
KUBERNETES_VERSION: 1.24.9
DEPLOY_CARDANO_DBSYNC:
value: "false"
description: "Install cardano dbsync services (ogmios, hasura, postgres, grapql)"
DEPLOY_INFRA:
value: "false"
description: "Install infrastructure services (redis, db-sync)"
DEPLOY_WEBSITE:
value: "true"
description: "Build and deploy www.lidonation.com"
CYPRESS_CACHE_FOLDER: '$CI_PROJECT_DIR/frontend/cache/Cypress'
stages:
- build
- sancho
- preview
- production
- test
before_script:
- |
export APP_VERSION=$(awk '/version/{gsub(/("|",)/,"",$2);print $2};' frontend/package.json)
export APP_VERSION_AND_BUILD="${APP_VERSION}-${CI_PIPELINE_ID}"
export CI_APPLICATION_REPOSITORY=$CI_REGISTRY_IMAGE
export CI_APPLICATION_TAG=$APP_VERSION_AND_BUILD
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- ./node_modules
services:
- name: docker:dind
alias: docker
command: ["--tls=false"]
.auto-deploy:
image: "${CI_TEMPLATE_REGISTRY_HOST}/gitlab-org/cluster-integration/auto-deploy-image:${AUTO_DEPLOY_IMAGE_VERSION}"
dependencies: []
.setup: &setup
- apk add --no-cache ca-certificates curl bash openssl git
- curl -LO https://dl.k8s.io/release/v1.25.9/bin/linux/amd64/kubectl && chmod +x kubectl && mv kubectl /usr/local/bin/kubectl
- curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 && chmod 700 get_helm.sh && DESIRED_VERSION=v$HELM_VERSION ./get_helm.sh
- kubectl config get-contexts
- kubectl config use-context voltaire/www.1694.io:1694
.infra_rules: &infra_rules
- if: '$CI_COMMIT_BRANCH == "main" &&
($DEPLOY_INFRA == "true")'
when: manual
- if: '$CI_COMMIT_BRANCH != "main" &&
($DEPLOY_INFRA == "true")'
when: manual
.deploy_template: &deploy_template
image: alpine:3.16.1
retry: 0
cache: {}
.deploy_postgres_web_script: &deploy_postgres_web_script
- |
DEPLOYMENT_NAME="www-1694-$CI_ENVIRONMENT_SLUG"
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
echo "install postgres for web"
helm upgrade --install \
--timeout 300s \
--wait \
--atomic \
--namespace="$KUBE_NAMESPACE" \
--create-namespace \
-f ./chart/values.postgresql.yaml \
--set global.postgresql.auth.username="$POSTGRESQL_WEB_USERNAME" \
--set global.postgresql.auth.database="$POSTGRESQL_WEB_DATABASE" \
--set global.postgresql.auth.password="$POSTGRESQL_WEB_PASSWORD" \
--set global.postgresql.auth.postgresPassword="$POSTGRESQL_WEB_POSTGRES_PASSWORD" \
--set primary.persistence.size="$POSTGRESQL_WEB_SIZE" \
--set namespace=$KUBE_NAMESPACE \
$DEPLOYMENT_NAME-web-db \
bitnami/postgresql
.deploy_postgres_dbsync_script: &deploy_postgres_dbsync_script
- |
DEPLOYMENT_NAME="www-1694-$CI_ENVIRONMENT_SLUG"
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
echo "install postgres for dbsync"
helm upgrade --install \
--timeout 300s \
--wait \
--atomic \
--namespace="$KUBE_NAMESPACE" \
--create-namespace \
-f ./chart/values.postgresql.yaml \
--set global.postgresql.auth.username="$POSTGRESQL_DBSYNC_USERNAME" \
--set global.postgresql.auth.database="$POSTGRESQL_DBSYNC_DATABASE" \
--set global.postgresql.auth.password="$POSTGRESQL_DBSYNC_PASSWORD" \
--set global.postgresql.auth.postgresPassword="$POSTGRESQL_DBSYNC_POSTGRES_PASSWORD" \
--set primary.persistence.size="$POSTGRESQL_DBSYNC_SIZE" \
--set namespace=$KUBE_NAMESPACE \
$DEPLOYMENT_NAME-dbsync-db \
bitnami/postgresql
build_frontend:
stage: build
image: docker:24.0.2-git
retry: 1
script:
- *setup
- |
set -xev
cp $ENV_FILE_NEXT_PUBLIC_TEMPLATE frontend/.env.production
# cat $ENV_FILE_FRONTEND > frontend/.env.production
docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" "$CI_REGISTRY"
echo "Building Dockerfile with tags $CI_APPLICATION_REPOSITORY/1694.io-frontend:$CI_APPLICATION_TAG and $CI_APPLICATION_REPOSITORY/www.1694.io-frontend:latest ..."
docker build --network host -f frontend/Dockerfile \
-t "$CI_APPLICATION_REPOSITORY/1694.io-frontend:$CI_APPLICATION_TAG" \
-t "$CI_APPLICATION_REPOSITORY/1694.io-frontend:latest" .
docker push "$CI_APPLICATION_REPOSITORY/1694.io-frontend:$CI_APPLICATION_TAG"
docker push "$CI_APPLICATION_REPOSITORY/1694.io-frontend:latest"
only:
- branches
build_backend:
stage: build
image: docker:24.0.2-git
retry: 1
script:
- *setup
- |
set -xev
cp $ENV_FILE backend/.env.production
cat $ENV_FILE_BACKEND > backend/.env.production
cat $ENV_FILE_FRONTEND > frontend/.env.production
cp backend/.env.production ./chart/backend_env
docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" "$CI_REGISTRY"
echo "Building Dockerfile with tags $CI_APPLICATION_REPOSITORY/1694.io-backend:$CI_APPLICATION_TAG and $CI_APPLICATION_REPOSITORY/www.1694.io-backend:latest ..."
docker build --network host -f backend/Dockerfile \
-t "$CI_APPLICATION_REPOSITORY/1694.io-backend:$CI_APPLICATION_TAG" \
-t "$CI_APPLICATION_REPOSITORY/1694.io-backend:latest" .
docker push "$CI_APPLICATION_REPOSITORY/1694.io-backend:$CI_APPLICATION_TAG"
docker push "$CI_APPLICATION_REPOSITORY/1694.io-backend:latest"
only:
- branches
.deploy_postgres_web: &deploy_postgres_web
<<: *deploy_template
script:
- *setup
- *deploy_postgres_web_script
rules: *infra_rules
.deploy_postgres_dbsync: &deploy_postgres_dbsync
<<: *deploy_template
script:
- *setup
- *deploy_postgres_dbsync_script
rules: *infra_rules
postgres-app-sancho:
<<: *deploy_postgres_web
stage: sancho
needs: []
environment:
name: sancho
postgres-dbsync-sancho:
<<: *deploy_postgres_dbsync
stage: sancho
needs: []
environment:
name: sancho
app-sancho:
image: "${CI_TEMPLATE_REGISTRY_HOST}/gitlab-org/cluster-integration/auto-deploy-image:${AUTO_DEPLOY_IMAGE_VERSION}"
stage: sancho
script:
- *setup
- auto-deploy check_kube_domain
- auto-deploy download_chart
- auto-deploy create_secret
- |
set -xev
DEPLOYMENT_NAME="www-1694.$CI_ENVIRONMENT_SLUG"
cp $ENV_FILE backend/.env.production
cat $ENV_FILE_BACKEND > backend/.env.production
cat $ENV_FILE_FRONTEND > frontend/.env.production
cp backend/.env.production ./chart/backend_env
cp $ENV_FILE frontend/.env.production
cat $ENV_FILE_FRONTEND > frontend/.env.production
cp frontend/.env.production ./chart/frontend_env
cp $ENV_FILE_FRONTEND ./chart/frontend_env
kubectl delete secret 1694-registry-deploy-token --ignore-not-found --namespace="$KUBE_NAMESPACE"
kubectl create secret docker-registry 1694-registry-deploy-token \
--namespace="$KUBE_NAMESPACE" \
--docker-server=registry.lidonation.com \
--docker-username=$CI_REGISTRY_USER \
--docker-password=$CI_REGISTRY_PASSWORD \
--docker-email=$REGISTRY_EMAIL
helm template ./chart --debug \
-f ./chart/values.yaml \
--set image.repository=$CI_APPLICATION_REPOSITORY/www.1694.io \
--set secrets.NEXT_PUBLIC_GOOGLE_API="$NEXT_PUBLIC_GOOGLE_API" \
--set ingress.hosts[0]="$AUTO_DEVOPS_WEB_DOMAIN" \
--set image.tag=$CI_APPLICATION_TAG \
--namespace="$KUBE_NAMESPACE" \
--create-namespace
helm upgrade $DEPLOYMENT_NAME ./chart --install \
-f ./chart/values.yaml \
--timeout 300s \
--wait \
--atomic \
--namespace="$KUBE_NAMESPACE" \
--set image.tag=$CI_APPLICATION_TAG \
--set backend.replicaCount=1 \
--set frontend.replicaCount=1 \
--set secrets.NEXT_PUBLIC_GOOGLE_API="$NEXT_PUBLIC_GOOGLE_API" \
--set ingress.hosts[0]="$AUTO_DEVOPS_WEB_DOMAIN" \
--namespace="$KUBE_NAMESPACE" \
--create-namespace
- auto-deploy persist_environment_url
artifacts:
paths: [ environment_url.txt ]
needs:
- job: build_frontend
- job: build_backend
environment:
name: sancho
only:
- branches
postgres-app-preview:
<<: *deploy_postgres_web
stage: preview
needs: []
environment:
name: preview
postgres-dbsync-preview:
<<: *deploy_postgres_dbsync
stage: preview
needs: []
environment:
name: preview
app-preview:
image: "${CI_TEMPLATE_REGISTRY_HOST}/gitlab-org/cluster-integration/auto-deploy-image:${AUTO_DEPLOY_IMAGE_VERSION}"
stage: preview
script:
- *setup
- auto-deploy check_kube_domain
- auto-deploy download_chart
- auto-deploy create_secret
# - auto-deploy ensure_namespace
- |
set -xev
DEPLOYMENT_NAME="www-1694.$CI_ENVIRONMENT_SLUG"
cp $ENV_FILE backend/.env.production
cat $ENV_FILE_BACKEND > backend/.env.production
cat $ENV_FILE_FRONTEND > frontend/.env.production
cp backend/.env.production ./chart/backend_env
cp $ENV_FILE frontend/.env.production
cat $ENV_FILE_FRONTEND > frontend/.env.production
cp frontend/.env.production ./chart/frontend_env
cp $ENV_FILE_FRONTEND ./chart/frontend_env
kubectl delete secret 1694-registry-deploy-token --ignore-not-found --namespace="$KUBE_NAMESPACE"
kubectl create secret docker-registry 1694-registry-deploy-token \
--namespace="$KUBE_NAMESPACE" \
--docker-server=registry.lidonation.com \
--docker-username=$CI_REGISTRY_USER \
--docker-password=$CI_REGISTRY_PASSWORD \
--docker-email=$REGISTRY_EMAIL
echo "AUTO_DEVOPS_WEB_DOMAIN: $AUTO_DEVOPS_WEB_DOMAIN"
helm upgrade $DEPLOYMENT_NAME ./chart --install \
-f ./chart/values.yaml \
--timeout 300s \
--wait \
--atomic \
--namespace="$KUBE_NAMESPACE" \
--set image.tag=$CI_APPLICATION_TAG \
--set backend.replicaCount=1 \
--set frontend.replicaCount=1 \
--set secrets.NEXT_PUBLIC_GOOGLE_API="$NEXT_PUBLIC_GOOGLE_API" \
--set ingress.hosts[0]="$AUTO_DEVOPS_WEB_DOMAIN" \
--set namespace=$KUBE_NAMESPACE \
--namespace="$KUBE_NAMESPACE" \
--create-namespace
- auto-deploy persist_environment_url
artifacts:
paths: [ environment_url.txt ]
needs:
- job: build_frontend
- job: build_backend
environment:
name: preview
rules:
- if: $DEPLOY_WEBSITE == 'true'
when: manual
postgres-app-production:
<<: *deploy_postgres_web
stage: production
needs:
- job: postgres-app-preview
environment:
name: production
postgres-dbsync-production:
<<: *deploy_postgres_dbsync
stage: production
environment:
name: production
needs:
- job: postgres-dbsync-preview
production:
stage: production
image: "${CI_TEMPLATE_REGISTRY_HOST}/gitlab-org/cluster-integration/auto-deploy-image:${AUTO_DEPLOY_IMAGE_VERSION}"
environment:
name: production
script:
- auto-deploy check_kube_domain
- auto-deploy download_chart
- auto-deploy create_secret
# - auto-deploy ensure_namespace
- |
DEPLOYMENT_NAME="www-1694.$CI_ENVIRONMENT_SLUG"
cp $ENV_FILE backend/.env.production
cat $ENV_FILE_BACKEND > backend/.env.production
cat $ENV_FILE_FRONTEND > frontend/.env.production
cp backend/.env.production ./chart/backend_env
cp $ENV_FILE frontend/.env.production
cat $ENV_FILE_FRONTEND > frontend/.env.production
cp frontend/.env.production ./chart/frontend_env
cp $ENV_FILE_FRONTEND ./chart/frontend_env
helm upgrade $DEPLOYMENT_NAME ./chart --install \
-f ./chart/values.yaml \
--timeout 300s \
--wait \
--atomic \
--set image.repository=$CI_APPLICATION_REPOSITORY/www.1694.io \
--set image.tag=$CI_APPLICATION_TAG \
--set backend.replicaCount=5 \
--set frontend.replicaCount=5 \
--set secrets.NEXT_PUBLIC_GOOGLE_API="$NEXT_PUBLIC_GOOGLE_API" \
--set ingress.hosts[0]="$AUTO_DEVOPS_WEB_DOMAIN" \
--set namespace=$KUBE_NAMESPACE \
--namespace="$KUBE_NAMESPACE" \
--create-namespace
- auto-deploy persist_environment_url
artifacts:
paths: [ environment_url.txt ]
needs:
- job: app-preview
rules:
- if: $CI_COMMIT_BRANCH == 'main'
when: manual
ui-chrome-tests:
image: cypress/included:cypress-13.13.1-node-20.15.1-chrome-126.0.6478.126-1-ff-128.0-edge-126.0.2592.102-1
stage: test
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- frontend/.cache/*
- frontend/cache/Cypress
- frontend/*node_modules
- frontend/build
script:
- cd frontend
- yarn install --frozen-lockfile
# start the server in the background
- yarn run build
- yarn run start
# run Cypress tests in parallel
- npx cypress run
artifacts:
when: on_failure
paths:
- ${PWD}/frontend/cypress/videos/**/*.mp4
- ${PWD}/frontend/cypress/screenshots/**/*.png
expire_in: 1 day