-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path.gitlab-ci.yml
More file actions
308 lines (288 loc) · 9.67 KB
/
.gitlab-ci.yml
File metadata and controls
308 lines (288 loc) · 9.67 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
stages:
- build
- test
- pre-merge
- deploy
- post-deploy
cache:
# TODO: Try key as package-lock.json to speed up across branches.
# key:
# files:
# - package-lock.json
key: $CI_COMMIT_REF_SLUG
paths:
- .npm
variables:
AUTO_DEVOPS_BUILD_IMAGE_CNB_ENABLED: 'true'
AUTO_DEVOPS_BUILD_IMAGE_CNB_BUILDER: 'heroku/buildpacks:20'
npm_config_cache: '$CI_PROJECT_DIR/.npm'
NEW_RELIC_ENABLED: 'false'
NEW_RELIC_NO_CONFIG_FILE: 'true'
.docker_service:
services:
- docker:29.0.3-dind
variables:
DOCKER_HOST: tcp://docker:2376
DOCKER_TLS_CERTDIR: '/certs'
DOCKER_TLS_VERIFY: '1'
DOCKER_CERT_PATH: "$DOCKER_TLS_CERTDIR/client"
.build_docker:
extends: .docker_service
stage: build
image: registry.gitlab.com/upchieve/subway/gitlab-ci-image:1.0.3
cache: []
id_tokens:
GITLAB_OIDC_TOKEN:
aud: api://AzureADTokenExchange
variables:
IMAGE_TAG: $AZURE_CONTAINER_REGISTRY/$CI_COMMIT_REF_SLUG:$CI_COMMIT_SHA
AZURE_TENANT_ID: $AZURE_TENANT_ID
environment:
action: prepare
before_script:
- az login --service-principal --username $AZURE_IDENTITY_CLIENT_ID --tenant $AZURE_TENANT_ID --federated-token $GITLAB_OIDC_TOKEN
- az acr login --name $AZURE_CONTAINER_REGISTRY
script:
- echo $IMAGE_TAG
- docker build -t $IMAGE_TAG .
- docker push $IMAGE_TAG
# Build the application as part of a MR - does not also push to registry.
build_ci:
extends: .docker_service
stage: build
image: docker:29.0.3
cache: []
script:
- docker build .
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event' # MR is created or updated.
# If you want to build/deploy for dev on a feature branch from CI, you can do so by:
# - changing the rule for `build_dev` and `deploy_dev`.
# - updating the subject of the federated credential. See grand-central-station/new-environment/ci-configuration/README.md for more details.
# For the vast majority of cases, it will be easier to simply deploy to dev from
# your machine.
build_dev:
extends: .build_docker
environment:
name: dev
variables:
AZURE_IDENTITY_CLIENT_ID: $AZURE_IDENTITY_CLIENT_ID_DEV
AZURE_CONTAINER_REGISTRY: $AZURE_CONTAINER_REGISTRY_DEV
rules:
- when: never
# - if: $CI_PIPELINE_SOURCE == 'merge_request_event' # MR is created or updated.
# Build the application and push to staging registry.
build_staging:
extends: .build_docker
environment:
name: staging
variables:
AZURE_IDENTITY_CLIENT_ID: $AZURE_IDENTITY_CLIENT_ID_STAGING
AZURE_CONTAINER_REGISTRY: $AZURE_CONTAINER_REGISTRY_STAGING
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH # Committed to main.
# Build the application and push to production registry.
build_production:
extends: .build_docker
environment:
name: production
allow_failure: false
variables:
AZURE_IDENTITY_CLIENT_ID: $AZURE_IDENTITY_CLIENT_ID_PRODUCTION
AZURE_CONTAINER_REGISTRY: $AZURE_CONTAINER_REGISTRY_PRODUCTION
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH # Committed to main.
.deploy:
stage: deploy
image: mcr.microsoft.com/azure-cli:latest
id_tokens:
GITLAB_OIDC_TOKEN:
aud: api://AzureADTokenExchange
variables:
IMAGE_TAG: $AZURE_CONTAINER_REGISTRY/$CI_COMMIT_REF_SLUG:$CI_COMMIT_SHA
before_script:
- az login --service-principal --username $AZURE_IDENTITY_CLIENT_ID --tenant $AZURE_TENANT_ID --federated-token $GITLAB_OIDC_TOKEN
- az extension add --name containerapp --upgrade
script:
- az containerapp update --name $CONTAINER_APP --resource-group $RESOURCE_GROUP --image $IMAGE_TAG --revision-suffix $CI_COMMIT_SHORT_SHA
- az containerapp update --name $CONTAINER_APP_WORKER --resource-group $RESOURCE_GROUP --image $IMAGE_TAG --revision-suffix $CI_COMMIT_SHORT_SHA
deploy_dev:
extends: .deploy
environment:
name: dev
resource_group: development
variables:
CONTAINER_APP: development-container-app-subway
CONTAINER_APP_WORKER: development-container-app-worker
RESOURCE_GROUP: development-resource-group
AZURE_IDENTITY_CLIENT_ID: $AZURE_IDENTITY_CLIENT_ID_DEV
AZURE_CONTAINER_REGISTRY: $AZURE_CONTAINER_REGISTRY_DEV
needs:
- job: build_dev
artifacts: true
rules:
- when: never
# - if: $CI_PIPELINE_SOURCE == 'merge_request_event' # MR is created or updated.
deploy_staging:
extends: .deploy
environment:
name: staging
resource_group: staging
variables:
CONTAINER_APP: staging-container-app-subway
CONTAINER_APP_WORKER: staging-container-app-worker
RESOURCE_GROUP: staging-resource-group
AZURE_IDENTITY_CLIENT_ID: $AZURE_IDENTITY_CLIENT_ID_STAGING
AZURE_CONTAINER_REGISTRY: $AZURE_CONTAINER_REGISTRY_STAGING
needs:
- job: build_staging
artifacts: true
- job: test_backend
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH # Committed to main.
deploy_production:
extends: .deploy
environment:
name: production
resource_group: production
variables:
CONTAINER_APP: production-container-app-subway
CONTAINER_APP_WORKER: production-container-app-worker
RESOURCE_GROUP: production-resource-group
AZURE_IDENTITY_CLIENT_ID: $AZURE_IDENTITY_CLIENT_ID_PRODUCTION
AZURE_CONTAINER_REGISTRY: $AZURE_CONTAINER_REGISTRY_PRODUCTION
needs:
- job: build_production
artifacts: true
- job: test_backend
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH # Committed to main.
when: manual
tag_commit_production:
stage: post-deploy
image: registry.gitlab.com/gitlab-org/release-cli:latest
needs:
- job: deploy_production
script:
- echo 'Tag commit $CI_COMMIT_SHA'
release:
tag_name: 'deployed-$(date +%Y-%m-%d_%H-%M-%S)'
description: 'Deployed from GitLab CI.'
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH # Committed to main.
new_relic_deploy_tracker:
stage: post-deploy
needs:
- job: deploy_production
variables:
NEW_RELIC_DEPLOYMENT_USER_KEY: $NEW_RELIC_DEPLOYMENT_USER_KEY
NEW_RELIC_SERVICE_GUID_PRODUCTION: $NEW_RELIC_SERVICE_GUID_PRODUCTION
script: >
curl -v https://api.newrelic.com/graphql
-H 'content-type: application/json; charset=utf-8'
-H "API-Key: $NEW_RELIC_DEPLOYMENT_USER_KEY"
--data-raw '{"query":"mutation { changeTrackingCreateDeployment(deployment: {version: \"'$CI_COMMIT_SHA'\", entityGuid: \"'$NEW_RELIC_SERVICE_GUID_PRODUCTION'\"}) { deploymentId timestamp } }"}'
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH # Committed to main.
test_backend:
stage: test
image: node:24.14.1-bullseye
variables:
NODE_OPTIONS: --max_old_space_size=5120
services:
- redis:latest
before_script:
- npm ci --cache .npm --prefer-offline
script:
- npm run test:backend
rules:
- if: '$TEST_DISABLED'
when: never
- if: $CI_PIPELINE_SOURCE == 'merge_request_event' # MR is created or updated.
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH # Committed to main.
test_database:
stage: test
image: node:24.14.1-bullseye
services:
- name: postgres:15.17
alias: postgres
command:
[
'postgres',
'-c',
'shared_preload_libraries=pg_stat_statements',
'-c',
'pg_stat_statements.track=all',
]
variables:
POSTGRES_USER: admin
POSTGRES_PASSWORD: Password123 # pragma: allowlist secret
POSTGRES_DB: upchieve
CI: 'true'
DB_PORT: 5432
before_script:
- npm ci --cache .npm --prefer-offline
- apt-get update && apt-get install -y postgresql-client
- export PGPASSWORD=$POSTGRES_PASSWORD
- psql -h "postgres" -U "$POSTGRES_USER" -d "$POSTGRES_DB" -c "SELECT 'OK' AS status;"
- |
for file in database/db_init/{schema,test_seeds,seed_migrations}.sql; do
PGPASSWORD=$POSTGRES_PASSWORD psql -h postgres -U $POSTGRES_USER -d $POSTGRES_DB -f $file
done
script:
- npm run test:database
rules:
- if: '$TEST_DISABLED'
when: never
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
lint:
stage: test
image: node:24.14.1-bullseye
before_script:
- npm ci --cache .npm --prefer-offline
script:
- npm run lint
rules:
- if: '$TEST_DISABLED'
when: never
- if: $CI_PIPELINE_SOURCE == 'merge_request_event' # MR is created or updated.
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH # Committed to main.
lint_sql:
stage: test
image: node:24.14.1-bullseye
before_script:
- npm ci --cache .npm --prefer-offline
script:
- npm run lint:sql:check
rules:
- if: '$TEST_DISABLED'
when: never
- if: $CI_PIPELINE_SOURCE == 'merge_request_event' # MR is created or updated.
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH # Committed to main.
lint_database:
stage: test
image: node:24.14.1-bullseye
before_script:
- npm ci --cache .npm --prefer-offline
script:
- npm run lint:database:dry
rules:
- if: '$TEST_DISABLED'
when: never
- if: $CI_PIPELINE_SOURCE == 'merge_request_event' # MR is created or updated.
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH # Committed to main.
verify_migration_data_deletion:
stage: pre-merge
image: alpine:latest
script:
- echo "When you're creating a database migration, there might be a new column or columns within a new table that should be deleted/anonymized when a user requests account deletion."
- echo ""
- echo "If anything should be deleted/anonymized, update the DeidentifyUser job accordingly, then go ahead and run this job to continue with merging."
- echo "If there is nothing to update, just go ahead and run this job!"
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event' # MR is created or updated.
changes:
- database/migrations/**/*.sql
when: manual
allow_failure: false