-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy path.gitlab-ci.yml
343 lines (306 loc) · 10.8 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
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
---
# develop branch
# yamllint disable rule:line-length
# ------------------------------------------------------------------
# Global settings
image: "adorsys/ci-build:latest"
# ------------------------------------------------------------------
# stages
# ------------------------------------------------------------------
stages:
- "Lint"
- "Compile" # build jar and provide as artifact
- "Test" # run tests and code quality checks
- "Package" # dockerize jar and push to docker registry
- "Release" # release
- "Clone to github"
# ------------------------------------------------------------------
# variables
# ------------------------------------------------------------------
variables: &variables
############################
# Private Images #
############################
DOCKER_IMAGE_NAME_LEDGERS: "ledgers"
DOCKER_IMAGE_NAME_KEYCLOAK_AND_LEDGERS_PLUGIN: "keycloak-and-ledgers-plugin"
DOCKERHUB_REGISTRY: "gitlab-registry.adorsys.de"
DOCKERHUB_NAMESPACE: "adorsys/xs2a/ledgers"
###########################
# Build variables #
###########################
BUILD_JAVA_VERSION: "[email protected]"
JAVA_TOOL_OPTIONS: "-XX:+UnlockExperimentalVMOptions -XX:MaxRAM=3G -XX:MaxRAMFraction=3"
MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"
# ------------------------------------------------------------------
# reusable yaml anchors
# ------------------------------------------------------------------
# Build Java
.build_java: &build_java
script:
- jabba use $BUILD_JAVA_VERSION
- java -XX:+PrintFlagsFinal -version | grep -Ei "maxheapsize|maxram"
- mvn -DskipTests clean install -Dci.build.number=Build\:${CI_PIPELINE_ID}
# cache:
# key: "Java_${CI_COMMIT_REF_SLUG}"
# paths:
# - /builds/adorsys/xs2a/psd2-dynamic-sandbox/.m2/repository
.build_and_push_dockerhub_images_private: &build_and_push_dockerhub_images_private
script:
- docker build -t "${DOCKERHUB_REGISTRY}/${DOCKERHUB_NAMESPACE}/${DOCKER_IMAGE_NAME_LEDGERS}:${DOCKER_TAG}" .
- docker build -t "${DOCKERHUB_REGISTRY}/${DOCKERHUB_NAMESPACE}/${DOCKER_IMAGE_NAME_KEYCLOAK_AND_LEDGERS_PLUGIN}:${DOCKER_TAG}" keycloak
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker push "${DOCKERHUB_REGISTRY}/${DOCKERHUB_NAMESPACE}/${DOCKER_IMAGE_NAME_LEDGERS}:${DOCKER_TAG}"
- docker push "${DOCKERHUB_REGISTRY}/${DOCKERHUB_NAMESPACE}/${DOCKER_IMAGE_NAME_KEYCLOAK_AND_LEDGERS_PLUGIN}:${DOCKER_TAG}"
- docker logout
# release java artifact privately
.release_java_private: &release_java_private
script:
- jabba use $BUILD_JAVA_VERSION
- java -XX:+PrintFlagsFinal -version | grep -Ei "maxheapsize|maxram"
- mvn -ntp --settings scripts/mvn-release-settings.xml -Pgitlab-maven -DskipTests -U deploy
# push changes to github
.sync_changes_github: &sync_changes_github
image: alpine/git
dependencies: []
script:
- git config --global user.name "$GITHUB_USERNAME"
- git remote add github https://[email protected]/$GITHUB_REPOSITORY.git #Token expires on Sat, 11.05.2024
- for branch in $(git branch -r | grep -E "origin/(release-${GITHUB_PROJECT_CLONE_VERSION}.*|develop).*"); do
branch=${branch#origin/};
git checkout $branch;
git push github $branch --force;
done
# ------------------------------------------------------------------
# jobs
# ------------------------------------------------------------------
#-------------------------------------------------------------------
# lint
#-------------------------------------------------------------------
Lint (Docker compose):
image: maven:3.6.3-openjdk-17-slim
stage: "Lint"
except:
- schedules
- develop
- master
tags:
- aws
script:
- apt update && apt install yamllint docker-compose make -yq
- echo "Run Docker compose lint"
- docker-compose -f docker-compose.yml config -q
Lint (Ci file):
image: debian:stable-slim
stage: "Lint"
except:
- schedules
- develop
- master
script:
- apt-get update && apt-get install yamllint python3-pkg-resources -yq
- echo "Run Gitlab ci file lint"
- yamllint -d relaxed .gitlab-ci.yml
Lint (YAML, JSON, XML):
image: debian:stable-slim
stage: "Lint"
except:
- schedules
- develop
- master
script:
- apt-get update && apt-get install jsonlint yamllint libxml2-utils make curl -yq && ln -s /usr/bin/jsonlint-php /usr/bin/jsonlint
- echo "Run Ledgers backend lint"
- find ./ -type f -name "*.json" -exec jsonlint -q {} \; # lint all json
# commented cause get many small errors for yaml with spaces empty lines and etc
# - find ./ -type f \( -name "*.yml" -o -name "*.yaml" \) -exec yamllint -d "{extends: relaxed, rules: {line-length: {max: 160}}}" {} \;
# commented cause get error Unsupported version '1.1'
# - find ./ -type f \( -iname "*.xml" ! -iname pom.xml \) -exec xmllint --noout {} \;
Lint (Dockerfiles):
image: docker
stage: "Lint"
services:
- docker:dind
tags:
- aws
variables:
DOCKER_HOST: tcp://docker:2375
DOCKER_TLS_CERTDIR: ""
DOCKER_DRIVER: overlay2
except:
- schedules
- develop
- master
script:
- echo "Run ledgers dockerfile checks"
- docker run --rm -i hadolint/hadolint < Dockerfile
Lint (PMD check):
image: maven:3.6.3-openjdk-17-slim
stage: "Lint"
except:
- schedules
- develop
- master
script:
- apt update && apt install make -yq
- echo "Test java code for PMD and CPD"
- mvn -ntp -Dmaven.test.skip=true package pmd:check pmd:cpd-check
cache: {}
artifacts:
paths:
- "qa/pmd/pmd-ruleset.xml"
- "**/**/*/pmd.html"
- "**/*/pmd.xml"
name: "${CI_PROJECT_NAME}-${CI_BUILD_REF_NAME#*v}-pmd"
expire_in: "10 day"
#-------------------------------------------------------------------
# Compile
#-------------------------------------------------------------------
Build Java (Ledgers):
stage: "Compile"
tags:
- aws
except:
- schedules
<<: *build_java
artifacts:
paths:
- "ledgers-app/target/ledgers-app*jar"
- "ledgers-deposit-account/ledgers-deposit-account-repository/target/ledgers-deposit-account-repository*jar"
- "ledgers-deposit-account/ledgers-deposit-account-service-api/target/ledgers-deposit-account-service-api*jar"
- "ledgers-deposit-account/ledgers-deposit-account-service-impl/target/ledgers-deposit-account-service-impl*jar"
- "ledgers-middleware/ledgers-middleware-rest-server/target/ledgers-middleware-rest-server*jar"
- "ledgers-middleware/ledgers-middleware-service-api/target/ledgers-middleware-service-api*jar"
- "ledgers-middleware/ledgers-middleware-service-impl/target/ledgers-middleware-service-impl*jar"
- "ledgers-mockbank/ledgers-mockbank-simple/target/ledgers-mockbank-simple*jar"
- "ledgers-mockbank/ledgers-mockbank-simple-data-test/target/ledgers-mockbank-simple-data-test*jar"
- "ledgers-postings/ledgers-postings-repository/target/ledgers-postings-repository*jar"
- "ledgers-postings/ledgers-postings-rest-server/target/ledgers-postings-rest-server*jar"
- "ledgers-postings/ledgers-postings-service-api/target/ledgers-postings-service-api*jar"
- "ledgers-postings/ledgers-postings-service-impl/target/ledgers-postings-service-impl*jar"
- "ledgers-sca/ledgers-sca-repository/target/ledgers-sca-repository*jar"
- "ledgers-sca/ledgers-sca-service-api/target/ledgers-sca-service-api*jar"
- "ledgers-sca/ledgers-sca-service-impl/target/ledgers-sca-service-impl*jar"
- "ledgers-user-management/ledgers-user-management-repository/target/ledgers-user-management-repository*jar"
- "ledgers-user-management/ledgers-user-management-rest-server/target/ledgers-user-management-rest-server*jar"
- "ledgers-user-management/ledgers-user-management-service-api/target/ledgers-user-management-service-api*jar"
- "ledgers-user-management/ledgers-user-management-service-impl/target/ledgers-user-management-service-impl*jar"
- "ledgers-utils/target/ledgers-utils*jar"
- "keycloak/keycloak-token-exchange/target/keycloak-token-exchange*.jar"
name: "$CI_PROJECT_NAME-${CI_BUILD_REF_NAME#*v}"
expire_in: "1 day"
#-------------------------------------------------------------------
# Tests
#-------------------------------------------------------------------
Test (Javadoc Check):
stage: "Test"
except:
- schedules
script:
- jabba use $BUILD_JAVA_VERSION
- java -XX:+PrintFlagsFinal -version | grep -Ei "maxheapsize|maxram"
- mvn -Dmaven.test.skip=true package javadoc:javadoc
artifacts:
paths:
- "**/target/site/*"
name: "$CI_PROJECT_NAME-${CI_BUILD_REF_NAME#*v}-javadoc"
expire_in: "10 day"
Test (Unit Tests):
stage: "Test"
tags:
- aws
except:
- schedules
script:
- jabba use $BUILD_JAVA_VERSION
- java -XX:+PrintFlagsFinal -version | grep -Ei "maxheapsize|maxram"
- mvn --fail-at-end clean install
artifacts:
paths:
- "**/target/surefire-reports/*"
name: "$CI_PROJECT_NAME-${CI_BUILD_REF_NAME#*v}-*"
expire_in: "10 day"
###########
# Package
###########
Build and push images to private repo (develop):
stage: "Package"
services:
- docker:dind
tags:
- aws
only:
- develop
except:
- schedules
variables:
DOCKER_HOST: tcp://docker:2375
DOCKER_TLS_CERTDIR: ""
DOCKER_DRIVER: overlay2
DOCKER_TAG: develop
<<: *build_and_push_dockerhub_images_private
Build and push images to private repo (tags):
stage: "Package"
services:
- docker:dind
tags:
- aws
only:
- tags
variables:
DOCKER_HOST: tcp://docker:2375
DOCKER_TLS_CERTDIR: ""
DOCKER_DRIVER: overlay2
DOCKER_TAG: $CI_COMMIT_TAG
<<: *build_and_push_dockerhub_images_private
Build and push images to private repo (master):
stage: "Package"
services:
- docker:dind
tags:
- aws
only:
- master
variables:
DOCKER_HOST: tcp://docker:2375
DOCKER_TLS_CERTDIR: ""
DOCKER_DRIVER: overlay2
DOCKER_TAG: latest
<<: *build_and_push_dockerhub_images_private
###########
# Release (tags) #
###########
Release artifacts to private repo (snapshots):
stage: "Release"
only:
- develop
except:
- schedules
cache: {}
variables:
JAVA_TOOL_OPTIONS: "-Djavax.net.ssl.trustStorePassword=changeit -XX:MaxRAM=3G"
<<: *release_java_private
Release artifacts to private repo (tags):
stage: "Release"
only:
- tags
except:
- schedules
cache: {}
variables:
JAVA_TOOL_OPTIONS: "-Djavax.net.ssl.trustStorePassword=changeit -XX:MaxRAM=3G"
<<: *release_java_private
Clone to github:
stage: "Clone to github"
<<: *sync_changes_github
image:
name: alpine/git:latest
entrypoint: [ "" ]
only:
- develop
- /^release-5\..*/
except:
- schedules
variables:
GITHUB_USERNAME: adorsys
GITHUB_REPOSITORY: adorsys/ledgers
GITHUB_PROJECT_CLONE_VERSION: "5"