-
Notifications
You must be signed in to change notification settings - Fork 10
/
.gitlab-ci.yml
executable file
·297 lines (280 loc) · 8.77 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
---
variables:
DEFAULT_LOCALE: en
.staging:
variables: &staging
FIREBASE_DOMAIN: https://staging.adblockplus.dev/
PREVIEW_CHANNEL_EXPIRATION: 30d
.production:
variables: &production
DOMAIN: adblockplus.org
FIREBASE_DOMAIN: https://www.adblockplus.dev/
.common:
tags:
- &NODE_IMAGE node:16-alpine
- &GOOGLE_CLOUD_SDK_IMAGE google/cloud-sdk:409.0.0
- &BUILD_IMAGE registry.gitlab.com/eyeo/websites/docker/adblockinc-cms-202208.1:latest
- &BUILD_RUNNER saas-linux-small-amd64
stages:
- prebuild_firebase
- build_firebase
- deploy_cloud_run
- deploy_firebase
pre_review_build:
stage: prebuild_firebase
except:
- master
- schedules
image: *NODE_IMAGE
before_script:
- npm install -g firebase-tools@11.13.0
- cp $GCP_SERVICE_ACCOUNT_CREDENTIALS ~/gcp.json
- export GOOGLE_APPLICATION_CREDENTIALS=~/gcp.json
script:
- cd services/firebase
- firebase use staging
- node ./prebuild_staging.mjs
after_script:
- rm -rf ~/gcp.json
artifacts:
reports:
dotenv: services/firebase/build.env
environment:
name: review/$CI_COMMIT_REF_SLUG
build:review:
stage: build_firebase
except:
- master
- schedules
variables:
<<: *staging
image: *BUILD_IMAGE
tags:
- *BUILD_RUNNER
dependencies:
- pre_review_build
before_script:
- python3 -m pip install -q crudini
script:
- crudini --set settings.ini general siteurl "$REVIEW_URL"
- python3 -m cms.bin.generate_static_pages $PWD services/firebase/public
- python services/firebase/utils/html_extender.py services/firebase/public
# copy contents of default locale to base of public root (for firebase),
# this addresses getting canonical page if no language translation available
- cp -a services/firebase/public/$DEFAULT_LOCALE/. services/firebase/public/.
artifacts:
name: $CI_COMMIT_REF_SLUG
paths:
- services/firebase/public
build:review:staging:
stage: build_firebase
except:
- schedules
variables:
<<: *staging
image: *BUILD_IMAGE
tags:
- *BUILD_RUNNER
before_script:
- python3 -m pip install -q crudini
script:
- crudini --set settings.ini general siteurl "$FIREBASE_DOMAIN"
- python3 -m cms.bin.generate_static_pages $PWD services/firebase/public
- python services/firebase/utils/html_extender.py services/firebase/public
# copy contents of default locale to base of public root (for firebase),
# this addresses getting canonical page if no language translation available
- cp -a services/firebase/public/$DEFAULT_LOCALE/. services/firebase/public/.
artifacts:
name: $CI_COMMIT_REF_SLUG
paths:
- services/firebase/public
only:
- master
build:production:
stage: build_firebase
except:
- schedules
variables:
<<: *production
image: *BUILD_IMAGE
tags:
- *BUILD_RUNNER
before_script:
- python3 -m pip install -q crudini
script:
- crudini --set settings.ini general siteurl https://$DOMAIN
- python3 -m cms.bin.generate_static_pages $PWD services/firebase/public
- python services/firebase/utils/html_extender.py services/firebase/public
# copy contents of default locale to base of public root (for firebase),
# this addresses getting canonical page if no language translation available
- cp -a services/firebase/public/$DEFAULT_LOCALE/. services/firebase/public/.
artifacts:
name: $CI_COMMIT_REF_SLUG
paths:
- services/firebase/public
only:
- master
deploy_cloud_run:review:
stage: deploy_cloud_run
except:
- master
- schedules
image: *GOOGLE_CLOUD_SDK_IMAGE
before_script:
- gcloud auth activate-service-account --key-file $GCP_SERVICE_ACCOUNT_CREDENTIALS
- gcloud config set project $GCP_PROJECT_ID
script:
- cd services/cloudrun
- gcloud builds submit --tag europe-west1-docker.pkg.dev/$GCP_PROJECT_ID/$GCP_PROJECT_ID/$CI_COMMIT_REF_SLUG
- gcloud run deploy b-$CI_COMMIT_REF_SLUG --image europe-west1-docker.pkg.dev/$GCP_PROJECT_ID/$GCP_PROJECT_ID/$CI_COMMIT_REF_SLUG:latest --region europe-west1 --allow-unauthenticated
environment:
name: review/$CI_COMMIT_REF_SLUG
on_stop: teardown_cloud_run:review
teardown_cloud_run:review:
stage: deploy_cloud_run
except:
- master
- schedules
image: *GOOGLE_CLOUD_SDK_IMAGE
before_script:
- gcloud auth activate-service-account --key-file $GCP_SERVICE_ACCOUNT_CREDENTIALS
- gcloud config set project $GCP_PROJECT_ID
script:
- gcloud run services delete b-$CI_COMMIT_REF_SLUG --region europe-west1 --quiet
environment:
name: review/$CI_COMMIT_REF_SLUG
action: stop
when: manual
deploy_cloud_run:review:staging:
stage: deploy_cloud_run
except:
- schedules
image: *GOOGLE_CLOUD_SDK_IMAGE
before_script:
- gcloud auth activate-service-account --key-file $GCP_SERVICE_ACCOUNT_CREDENTIALS
- gcloud config set project $GCP_PROJECT_ID
script:
- cd services/cloudrun
- gcloud builds submit --tag europe-west1-docker.pkg.dev/$GCP_PROJECT_ID/$GCP_PROJECT_ID/$CI_COMMIT_REF_SLUG
- gcloud run deploy $CI_COMMIT_REF_SLUG --image europe-west1-docker.pkg.dev/$GCP_PROJECT_ID/$GCP_PROJECT_ID/$CI_COMMIT_REF_SLUG:latest --region europe-west1 --allow-unauthenticated
environment:
name: review/staging/$CI_COMMIT_REF_SLUG
only:
- master
deploy_cloud_run:production:
stage: deploy_cloud_run
except:
- schedules
image: *GOOGLE_CLOUD_SDK_IMAGE
before_script:
- gcloud auth activate-service-account --key-file $GCP_SERVICE_ACCOUNT_CREDENTIALS
- gcloud config set project $GCP_PROJECT_ID
script:
- cd services/cloudrun
- gcloud builds submit --tag europe-west1-docker.pkg.dev/$GCP_PROJECT_ID/$GCP_PROJECT_ID/$CI_COMMIT_REF_SLUG
- gcloud run deploy $CI_COMMIT_REF_SLUG --image europe-west1-docker.pkg.dev/$GCP_PROJECT_ID/$GCP_PROJECT_ID/$CI_COMMIT_REF_SLUG:latest --region europe-west1 --allow-unauthenticated
environment:
name: production/$CI_COMMIT_REF_SLUG
only:
- master
deploy_firebase_hosting:review:
stage: deploy_firebase
except:
- master
- schedules
image: *NODE_IMAGE
variables:
<<: *staging
dependencies:
- pre_review_build
- build:review
before_script:
- npm install -g firebase-tools@11.13.0
- npm install commander@"~9.4.0"
- npm install json5@"~2.2.1"
- cp $GCP_SERVICE_ACCOUNT_CREDENTIALS ~/gcp.json
- export GOOGLE_APPLICATION_CREDENTIALS=~/gcp.json
script:
- npm run rename-service-ids -- --input ./services/firebase/firebase.json --name b-$CI_COMMIT_REF_SLUG
- cd services/firebase
- firebase use staging
- firebase hosting:channel:deploy $CI_COMMIT_REF_SLUG --expires $PREVIEW_CHANNEL_EXPIRATION
after_script:
- rm -rf ~/gcp.json
environment:
name: review/$CI_COMMIT_REF_SLUG
url: $REVIEW_URL
on_stop: teardown_firebase_hosting:review
teardown_firebase_hosting:review:
stage: deploy_firebase
except:
- master
- schedules
image: *NODE_IMAGE
before_script:
- npm install -g firebase-tools@11.13.0
- cp $GCP_SERVICE_ACCOUNT_CREDENTIALS ~/gcp.json
- export GOOGLE_APPLICATION_CREDENTIALS=~/gcp.json
script:
- cd services/firebase
- firebase use staging
- firebase hosting:channel:delete $CI_COMMIT_REF_SLUG -f
environment:
name: review/$CI_COMMIT_REF_SLUG
action: stop
when: manual
deploy_firebase_hosting:review:staging:
stage: deploy_firebase
except:
- schedules
image:
*NODE_IMAGE
variables:
<<: *staging
dependencies:
- build:review:staging
before_script:
- npm install -g firebase-tools@11.13.0
- npm install commander@"~9.4.0"
- npm install json5@"~2.2.1"
- cp $GCP_SERVICE_ACCOUNT_CREDENTIALS ~/gcp.json
- export GOOGLE_APPLICATION_CREDENTIALS=~/gcp.json
script:
- npm run rename-service-ids -- --input ./services/firebase/firebase.json --name $CI_COMMIT_REF_SLUG
- cd services/firebase
- firebase use staging
- firebase deploy --only hosting
after_script:
- rm -rf ~/gcp.json
environment:
name: review/staging/$CI_COMMIT_REF_SLUG
url: $FIREBASE_DOMAIN
only:
- master
deploy_firebase_hosting:production:
stage: deploy_firebase
except:
- schedules
image: *NODE_IMAGE
variables:
<<: *production
dependencies:
- build:production
before_script:
- npm install -g firebase-tools@11.13.0
- npm install commander@"~9.4.0"
- npm install json5@"~2.2.1"
- cp $GCP_SERVICE_ACCOUNT_CREDENTIALS ~/gcp.json
- export GOOGLE_APPLICATION_CREDENTIALS=~/gcp.json
script:
- npm run rename-service-ids -- --input ./services/firebase/firebase.json --name $CI_COMMIT_REF_SLUG
- cd services/firebase
- firebase use production
- firebase deploy --only hosting
after_script:
- rm -rf ~/gcp.json
environment:
name: production/$CI_COMMIT_REF_SLUG
url: $FIREBASE_DOMAIN
only:
- master