forked from DSpace/dspace-angular
-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathbitbucket-pipelines.yml
More file actions
378 lines (359 loc) · 18.2 KB
/
bitbucket-pipelines.yml
File metadata and controls
378 lines (359 loc) · 18.2 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
options:
runs-on: self.hosted
definitions:
caches:
cypress-2025-02-x: ~/.cache/Cypress
node-2025-02-x: ./node_modules
steps:
- step: &preliminary-operation
name: Preliminary Operation
image: alpine/git:latest
script:
- export HASH_COMMIT=${BITBUCKET_COMMIT:0:8}
- export BRANCH_NAME=$(echo "$BITBUCKET_BRANCH" | awk -F'/' '{if(NF==1)val=$1; else if(NF==2)val=$1"--"$2; else if(NF==3)val=$2; else if(NF==4)val=$2"--"$3; print tolower(val)}')
- echo "Using commit hash $HASH_COMMIT"
- git config --global user.email "${BB_USER}"
- git config --global user.name "${BB_EMAIL}"
- git clone https://x-token-auth:${E2ERUNNERS_ACCESS_TOKEN}@${E2E_VALUES_REPO}
- cd e2erunners-values
- sed "s#HASH_COMMIT#${HASH_COMMIT}#g" TPL-cris-2025 > ${HASH_COMMIT}
- sed -i "s#BRANCH_NAME#${BRANCH_NAME}#g" TPL-cris-2025 ${HASH_COMMIT}
- git add ${HASH_COMMIT}
- git commit -m "Add configuration for e2e-${HASH_COMMIT}" || echo "No changes to commit"
- git push
- cd ..
- git clone https://x-token-auth:${HELM_CHARTS_ACCESS_TOKEN}@${HELM_CHARTS_REPO}
- cd helm-charts
- PATH_VALUE=" e2e-$HASH_COMMIT"
- printf " - name:%s\n" "$PATH_VALUE" >> ${E2E_VALUES}
- git add e2e-ingress/values.yaml
- git commit -m "Add ${HASH_COMMIT} to e2e-ingress values" || echo "No changes to commit"
- git push
- cd ..
- step: &preliminary-operation-backend
name: Preliminary Operation
image: alpine/git:latest
script:
- export HASH_COMMIT=${BITBUCKET_COMMIT:0:8}
- export BRANCH_NAME=$(echo "$BITBUCKET_BRANCH" | tr '[:upper:]' '[:lower:]' | sed 's|/|--|g')
- echo "Using commit hash $HASH_COMMIT"
- git config --global user.email "${BB_USER}"
- git config --global user.name "${BB_EMAIL}"
- git clone https://x-token-auth:${E2ERUNNERS_ACCESS_TOKEN}@${E2E_VALUES_REPO}
- cd e2erunners-values
- sed "s#HASH_COMMIT#${HASH_COMMIT}#g" TPL-cris-2025 > ${HASH_COMMIT}
- sed -i "s#BRANCH_NAME#${BRANCH_NAME}#g" TPL-cris-2025 ${HASH_COMMIT}
- git add ${HASH_COMMIT}
- git commit -m "Add configuration for e2e-${HASH_COMMIT}" || echo "No changes to commit"
- git push
- cd ..
- git clone https://x-token-auth:${HELM_CHARTS_ACCESS_TOKEN}@${HELM_CHARTS_REPO}
- cd helm-charts
- PATH_VALUE=" e2e-$HASH_COMMIT"
- printf " - name:%s\n" "$PATH_VALUE" >> ${E2E_VALUES}
- git add e2e-ingress/values.yaml
- git commit -m "Add ${HASH_COMMIT} to e2e-ingress values" || echo "No changes to commit"
- git push
- cd ..
- step: &angular-build
name: angular-build
image:
name: cypress/browsers:node-22.21.0-chrome-141.0.7390.107-1-ff-144.0-edge-141.0.3537.92-1
run-as-user: 1000
size: 4x
caches:
- node-2025-02-x
script:
- npm ci
- npm run build:prod:ci
- npm run build:mirador
artifacts:
- node_modules/**
- dist/**
- step: &unittest-code-checks
name: test-code-checks
image:
name: cypress/browsers:node-22.21.0-chrome-141.0.7390.107-1-ff-144.0-edge-141.0.3537.92-1
run-as-user: 1000
size: 4x
caches:
- node-2025-02-x
script:
- npm run build:lint
- npm run ng-high-memory -- lint --quiet
- npm run check-circ-deps
- npm run test:headless
artifacts:
- .next/**
- .cache/**
- ~/.cache/Cypress
- step: &run-e2e-tests
name: Run E2E test
image:
name: cypress/browsers:node-22.21.0-chrome-141.0.7390.107-1-ff-144.0-edge-141.0.3537.92-1
run-as-user: 0
size: 4x
services:
- docker
caches:
- node-2025-02-x
- cypress-2025-02-x
script:
- apt-get update && apt-get install -y curl
- export HASH_COMMIT=${BITBUCKET_COMMIT:0:8}
- echo "Running tests for commit $HASH_COMMIT"
- export DSPACE_REST_HOST=${E2E_RUNNER_HOST}
- export DSPACE_REST_PORT=443
- export DSPACE_REST_NAMESPACE=/e2e-${HASH_COMMIT}/server
- echo "Configured REST endpoint at https://$DSPACE_REST_HOST$DSPACE_REST_NAMESPACE"
- export DSPACE_REST_SSL=true
- export DSPACE_UI_HOST=127.0.0.1
- export DSPACE_UI_PORT=4000
- export DSPACE_CACHE_SERVERSIDE_BOTCACHE_MAX=0
- export DSPACE_CACHE_SERVERSIDE_ANONYMOUSCACHE_MAX=0
- export CYPRESS_BASE_URL=http://127.0.0.1:4000
- export CYPRESS_CACHE_FOLDER=~/.cache/Cypress
- export CHROME_FLAGS="--no-sandbox --disable-dev-shm-usage --disable-gpu"
- export NODE_OPTIONS="--max-old-space-size=4096"
- |
MAX_RETRIES=10
RETRY_COUNT=0
SUCCESS=false
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
echo "Pinging REST endpoint... (Attempt $((RETRY_COUNT+1)))"
STATUS_CODE=$(curl -s -o /dev/null -w "%{http_code}" "https://$DSPACE_REST_HOST$DSPACE_REST_NAMESPACE")
if [ "$STATUS_CODE" -lt 400 ]; then
echo "REST endpoint is up! Status code: $STATUS_CODE"
SUCCESS=true
break
else
echo "REST endpoint not ready (Status code: $STATUS_CODE). Retrying in 60 seconds..."
RETRY_COUNT=$((RETRY_COUNT+1))
sleep 60
fi
done
if [ "$SUCCESS" = "false" ]; then
echo "REST endpoint did not become available after $MAX_RETRIES attempts. Failing the build."
exit 1
fi
- npx cypress install
- npm run serve:ssr &
- echo "Waiting for server to start..."
- sleep 60
- echo "Running Cypress tests..."
- npm run cypress:run --env chromeFlags="$CHROME_FLAGS"
- echo "Test execution completed"
artifacts:
- cypress/screenshots/**
- cypress/videos/**
- step: &build-and-push
name: Build and Push Docker Image to ECR
size: 4x
image: atlassian/default-image:3
services:
- docker
script:
- echo "Copying dist to Docker context"
- mkdir -p build-context
- cp -r dist config build-context/
- cp Dockerfile.build build-context/Dockerfile
- cd build-context
- export HASH_COMMIT=${BITBUCKET_COMMIT:0:8}
- export BRANCH_NAME=$(echo "$BITBUCKET_BRANCH" | tr '[:upper:]' '[:lower:]' | sed 's|/|--|g')
- docker build -t dspace-angular:${BRANCH_NAME}-${HASH_COMMIT} -t dspace-angular:${BRANCH_NAME}-latest .
- pipe: atlassian/aws-ecr-push-image:2.5.0
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
AWS_DEFAULT_REGION: $AWS_REGION
IMAGE_NAME: dspace-angular
TAGS: "${BRANCH_NAME}-${HASH_COMMIT} ${BRANCH_NAME}-latest"
- step: &deploy-on-dev
name: Deploy on Development environment
image: alpine/git:latest
script:
- export HASH_COMMIT=${BITBUCKET_COMMIT:0:8}
- export BRANCH_NAME=$(echo "$BITBUCKET_BRANCH" | tr '[:upper:]' '[:lower:]' | sed 's|/|--|g')
- export BRANCH_FILE=$(echo "$BITBUCKET_BRANCH" | awk -F'/' '{if(NF==1)val=$1;else if(NF==2)val=$2;else if(NF==3)val=$2;else val=$3;gsub(/_/, "-", val);print tolower(val)}')
- git clone https://x-token-auth:${DSPACE_VALUES_ACCESS_TOKEN}@${DSPACE_VALUES_REPO}
- cd dspace-values
- '[ -f "dev/${BRANCH_FILE}" ] && sed -i "/^angular:/,/^[^ ]/s/\(tag: \).*/\1${BRANCH_NAME}-${HASH_COMMIT}/" "dev/${BRANCH_FILE}" && sed -i "s/^\([[:space:]]*replicaCount:\) 0/\1 1/" "dev/${BRANCH_FILE}"'
- git config --global user.email "${BB_EMAIL}"
- git config --global user.name "${BB_USER}"
- git commit -am "Update TAG with ${BRANCH_NAME}-${HASH_COMMIT}" || echo "No changes to commit"
- git push
- step: &deploy-on-staging
name: Deploy on Staging environment
image: alpine/git:latest
script:
- export HASH_COMMIT=${BITBUCKET_COMMIT:0:8}
- export BRANCH_NAME=$(echo "$BITBUCKET_BRANCH" | tr '[:upper:]' '[:lower:]' | sed 's|/|--|g')
- export BRANCH_FILE=$(echo "$BITBUCKET_BRANCH" | awk -F'/' '{if(NF==1)val=$1;else if(NF==2)val=$2;else if(NF==3)val=$2;else val=$3;gsub(/_/, "-", val);print tolower(val)}')
- git clone https://x-token-auth:${DSPACE_VALUES_ACCESS_TOKEN}@${DSPACE_VALUES_REPO}
- cd dspace-values
- '[ -f "staging/${BRANCH_FILE}" ] && sed -i "/^angular:/,/^[^ ]/s/\(tag: \).*/\1${BRANCH_NAME}-${HASH_COMMIT}/" "staging/${BRANCH_FILE}" && sed -i "s/^\([[:space:]]*replicaCount:\) 0/\1 1/" "staging/${BRANCH_FILE}"'
- git config --global user.email "${BB_EMAIL}"
- git config --global user.name "${BB_USER}"
- git commit -am "Update TAG with ${BRANCH_NAME}-${HASH_COMMIT}" || echo "No changes to commit"
- git push
- step: &deploy-on-test
name: Deploy on Test environment
image: alpine/git:latest
script:
- export HASH_COMMIT=${BITBUCKET_COMMIT:0:8}
- export BRANCH_NAME=$(echo "$BITBUCKET_BRANCH" | tr '[:upper:]' '[:lower:]' | sed 's|/|--|g')
- export BRANCH_FILE=$(echo "$BITBUCKET_BRANCH" | awk -F'/' '{if(NF==1)val=$1;else if(NF==2)val=$2;else if(NF==3)val=$2;else val=$3;gsub(/_/, "-", val);print tolower(val)}')
- git clone https://x-token-auth:${DSPACE_VALUES_ACCESS_TOKEN}@${DSPACE_VALUES_REPO}
- cd dspace-values
- '[ -f "test/${BRANCH_FILE}" ] && sed -i "/^angular:/,/^[^ ]/s/\(tag: \).*/\1${BRANCH_NAME}-${HASH_COMMIT}/" "test/${BRANCH_FILE}" && sed -i "s/^\([[:space:]]*replicaCount:\) 0/\1 1/" "test/${BRANCH_FILE}"'
- git config --global user.email "${BB_EMAIL}"
- git config --global user.name "${BB_USER}"
- git commit -am "Update TAG with ${BRANCH_NAME}-${HASH_COMMIT}" || echo "No changes to commit"
- git push
- step: &turn-on-dev
name: Turn On Dev environment
image: alpine/git:latest
script:
- export HASH_COMMIT=${BITBUCKET_COMMIT:0:8}
- export BRANCH_NAME=$(echo "$BITBUCKET_BRANCH" | tr '[:upper:]' '[:lower:]' | sed 's|/|--|g')
- export BRANCH_FILE=$(echo "$BITBUCKET_BRANCH" | awk -F'/' '{if(NF==1)val=$1;else if(NF==2)val=$2;else if(NF==3)val=$2;else val=$3;gsub(/_/, "-", val);print tolower(val)}')
- git clone https://x-token-auth:${DSPACE_VALUES_ACCESS_TOKEN}@${DSPACE_VALUES_REPO}
- cd dspace-values
- '[ -f "dev/${BRANCH_FILE}" ] && sed -i "s/^\([[:space:]]*replicaCount:\) 0/\1 1/" "dev/${BRANCH_FILE}"'
- git config --global user.email "${BB_USER}"
- git config --global user.name "${BB_EMAIL}"
- git commit -am "Enable dev environment for ${BRANCH_NAME}" || echo "No changes to commit"
- git push
- step: &turn-on-staging
name: Turn On Staging environment
image: alpine/git:latest
script:
- export HASH_COMMIT=${BITBUCKET_COMMIT:0:8}
- export BRANCH_NAME=$(echo "$BITBUCKET_BRANCH" | tr '[:upper:]' '[:lower:]' | sed 's|/|--|g')
- export BRANCH_FILE=$(echo "$BITBUCKET_BRANCH" | awk -F'/' '{if(NF==1)val=$1;else if(NF==2)val=$2;else if(NF==3)val=$2;else val=$3;gsub(/_/, "-", val);print tolower(val)}')
- git clone https://x-token-auth:${DSPACE_VALUES_ACCESS_TOKEN}@${DSPACE_VALUES_REPO}
- cd dspace-values
- '[ -f "staging/${BRANCH_FILE}" ] && sed -i "s/^\([[:space:]]*replicaCount:\) 0/\1 1/" "staging/${BRANCH_FILE}"'
- git config --global user.email "${BB_USER}"
- git config --global user.name "${BB_EMAIL}"
- git commit -am "Enable staging environment for ${BRANCH_NAME}" || echo "No changes to commit"
- git push
- step: &turn-on-test
name: Turn On Test environment
image: alpine/git:latest
script:
- export HASH_COMMIT=${BITBUCKET_COMMIT:0:8}
- export BRANCH_NAME=$(echo "$BITBUCKET_BRANCH" | tr '[:upper:]' '[:lower:]' | sed 's|/|--|g')
- export BRANCH_FILE=$(echo "$BITBUCKET_BRANCH" | awk -F'/' '{if(NF==1)val=$1;else if(NF==2)val=$2;else if(NF==3)val=$2;else val=$3;gsub(/_/, "-", val);print tolower(val)}')
- git clone https://x-token-auth:${DSPACE_VALUES_ACCESS_TOKEN}@${DSPACE_VALUES_REPO}
- cd dspace-values
- '[ -f "test/${BRANCH_FILE}" ] && sed -i "s/^\([[:space:]]*replicaCount:\) 0/\1 1/" "staging/${BRANCH_FILE}"'
- git config --global user.email "${BB_USER}"
- git config --global user.name "${BB_EMAIL}"
- git commit -am "Enable test environment for ${BRANCH_NAME}" || echo "No changes to commit"
- git push
- step: &find-and-invalidate-cloudfront-dev
name: Invalidate CloudFront Dev Cache
image: amazon/aws-cli
script:
- export AWS_ACCESS_KEY_ID=$AWS_ACCESS_CF_KEY_ID
- export AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_CF_KEY
- export AWS_DEFAULT_REGION=$AWS_REGION
- export CLOUDFRONT_NAME=$(echo "$BITBUCKET_BRANCH" | awk -F'/' '{if(NF==1)val=$1;else if(NF==2)val=$2;else if(NF==3)val=$2;else val=$3;gsub(/_/, "-", val);print tolower(val)}')
- export CLOUDFRONT_DISTRIBUTION_ID=$(aws cloudfront list-distributions --query "DistributionList.Items[?Comment=='dev--${CLOUDFRONT_NAME}'].Id" --output text)
- aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_DISTRIBUTION_ID --paths "/*" || echo "CloudFront distribution $CLOUDFRONT_DISTRIBUTION_ID not found — skipping invalidation."
- step: &find-and-invalidate-cloudfront-staging
name: Invalidate CloudFront Staging Cache
image: amazon/aws-cli
script:
- export AWS_ACCESS_KEY_ID=$AWS_ACCESS_CF_KEY_ID
- export AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_CF_KEY
- export AWS_DEFAULT_REGION=$AWS_REGION
- export CLOUDFRONT_NAME=$(echo "$BITBUCKET_BRANCH" | awk -F'/' '{if(NF==1)val=$1;else if(NF==2)val=$2;else if(NF==3)val=$2;else val=$3;gsub(/_/, "-", val);print tolower(val)}')
- export CLOUDFRONT_DISTRIBUTION_ID=$(aws cloudfront list-distributions --query "DistributionList.Items[?Comment=='staging--${CLOUDFRONT_NAME}'].Id" --output text)
- aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_DISTRIBUTION_ID --paths "/*" || echo "CloudFront distribution $CLOUDFRONT_DISTRIBUTION_ID not found — skipping invalidation."
- step: &find-and-invalidate-cloudfront-test
name: Invalidate CloudFront Test Cache
image: amazon/aws-cli
script:
- export AWS_ACCESS_KEY_ID=$AWS_ACCESS_CF_KEY_ID
- export AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_CF_KEY
- export AWS_DEFAULT_REGION=$AWS_REGION
- export CLOUDFRONT_NAME=$(echo "$BITBUCKET_BRANCH" | awk -F'/' '{if(NF==1)val=$1;else if(NF==2)val=$2;else if(NF==3)val=$2;else val=$3;gsub(/_/, "-", val);print tolower(val)}')
- export CLOUDFRONT_DISTRIBUTION_ID=$(aws cloudfront list-distributions --query "DistributionList.Items[?Comment=='test--${CLOUDFRONT_NAME}'].Id" --output text)
- aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_DISTRIBUTION_ID --paths "/*" || echo "CloudFront distribution $CLOUDFRONT_DISTRIBUTION_ID not found — skipping invalidation."
- step: &check-branch-name-allowed
name: Check allowed branch name
image: alpine:latest
script:
- |
if [[ "$BITBUCKET_BRANCH" = "main-cris" ]] || [[ "$BITBUCKET_BRANCH" == dspace-cris-20*_02_x ]] || [[ "$BITBUCKET_BRANCH" == prod/* ]] || [[ "$BITBUCKET_BRANCH" == test/* ]]; then
echo "Branch $BITBUCKET_BRANCH is allowed."
else
echo "This pipeline can only run on main-cris, dspace-cris-20*_02_x, prod/**, or test/**"
exit 1
fi
pipelines:
custom:
e2e-on-custom-backend:
- step: *preliminary-operation-backend
- step: *angular-build
- parallel: ¶llel-run-tests
- step: *unittest-code-checks
- step: *run-e2e-tests
deploy-on-dev:
- step: *angular-build
- step: *build-and-push
- step: *deploy-on-dev
- step: *find-and-invalidate-cloudfront-dev
deploy-on-staging:
- step: *check-branch-name-allowed
- step: *angular-build
- step: *build-and-push
- step: *deploy-on-staging
- step: *find-and-invalidate-cloudfront-staging
turn-on-dev:
- step: *turn-on-dev
turn-on-staging:
- step: *turn-on-staging
turn-on-test:
- step: *turn-on-test
branches:
'main-cris':
- step: *check-branch-name-allowed
- step: *preliminary-operation
- step: *angular-build
- parallel: *parallel-run-tests
'dspace-cris-20*_02_x':
- step: *check-branch-name-allowed
- step: *preliminary-operation
- step: *angular-build
- parallel: *parallel-run-tests
- step: *build-and-push
- step: *deploy-on-dev
- step: *find-and-invalidate-cloudfront-dev
- step: *deploy-on-staging
- step: *find-and-invalidate-cloudfront-staging
'prod/**':
- step: *check-branch-name-allowed
- step: *preliminary-operation
- step: *angular-build
- parallel: *parallel-run-tests
- step: *build-and-push
- step: *deploy-on-dev
- step: *find-and-invalidate-cloudfront-dev
- step: *deploy-on-staging
- step: *find-and-invalidate-cloudfront-staging
'test/**':
- step: *check-branch-name-allowed
- step: *preliminary-operation
- step: *angular-build
- parallel: *parallel-run-tests
- step: *build-and-push
- step: *deploy-on-test
- step: *find-and-invalidate-cloudfront-test
pull-requests:
'**':
- step: *preliminary-operation
- step: *angular-build
- parallel: *parallel-run-tests