-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
182 lines (164 loc) · 5.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
image: azul/zulu-openjdk-debian:17
# Enable Docker-in-Docker (DinD) for TestContainers and Docker image builds.
services:
- docker:dind
variables:
DOCKER_HOST: "tcp://docker:2375"
# Improve performance by using overlayfs
DOCKER_DRIVER: overlay2
# Disable Gradle daemon during build
GRADLE_OPTS: "-Dorg.gradle.daemon=false"
.gradle_build_job:
before_script:
# Tell Gradle to write its files to a separate directory within the build directory, so files do not conflict.
- export GRADLE_USER_HOME=`pwd`/.gradle-user-home
# Remove files that might be problematic (recommended by Travis CI)
- rm -f ${GRADLE_USER_HOME}/caches/modules-2/modules-2.lock
# Ideas taken from https://docs.gitlab.com/ee/ci/caching/ as well as
# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Gradle.gitlab-ci.yml and
# https://blog.jdriven.com/2021/11/reuse-gradle-build-cache-on-gitlab/
cache: &gradle_cache_settings
key:
files:
# Only have a single version of the wrapper, and invalidate the cache when the Gradle wrapper version changes.
- gradle/wrapper/gradle-wrapper.properties
prefix: wrapper
paths:
- .gradle-user-home/caches/ # Gradle Build Cache directories
- .gradle-user-home/notifications/ # Prevent welcome message to be shown every time
- .gradle-user-home/wrapper/ # Gradle Wrapper binaries
policy: pull-push
stages:
- build
- package
- verify
- deploy
build:
stage: build
extends: .gradle_build_job
cache:
<<: *gradle_cache_settings
script:
- ./gradlew --build-cache build
coverage: '/^Coverage:\s(\d+\.\d+%)/'
artifacts:
when: always
paths:
- '**/build/reports/'
- rest-api-server/build/libs/rest-api-server-*.jar
reports:
junit: rest-api-server/build/test-results/**/TEST-*.xml
needs: []
# Template job for building all documentation. These jobs rely on the Gradle build cache
# because Spring RestDoc snippets are generated from the test and we do not want re-run those.
.build-documentation:
stage: deploy
extends: .gradle_build_job
needs:
- job: build
artifacts: true
cache:
<<: *gradle_cache_settings
services: [] # Disable Docker-in-Docker
script:
- apt update && apt install --assume-yes graphviz
- ./gradlew --build-cache :documentation:asciidoctor
- mkdir -p public
- cp -r documentation/build/docs/asciidoc/* public/
artifacts:
paths:
- public
# Attempt to build the documentation although we do not deploy it to GitLab Pages.
# This ensures that everything works as expected and prevents surprises when merging.
dummy-doc-build:
extends: .build-documentation
except:
- master
# Deploy documentation to GitLab Pages.
pages:
resource_group: gitlab-pages
extends: .build-documentation
only:
- master
# Template for building Docker images.
.docker-build-instructions: &docker-build-instructions
stage: package
extends: .gradle_build_job
cache:
<<: *gradle_cache_settings
policy: pull
needs:
- build
script:
# Turn a list of whitespace-separated tags into a comma-separated list, as GitLab gets confused with commas and variable substitutions.
- docker_tags=$(echo "$IMAGE_TAGS" | sed 's/ \+/,/g')
# Build using Jib (pushed automatically)
- ./gradlew --build-cache jib -Djib.to.image=$CI_REGISTRY_IMAGE:$CI_COMMIT_SHA -Djib.to.tags=$docker_tags -Djib.to.auth.username=$REGISTRY_USER -Djib.to.auth.password=$REGISTRY_PASSWORD
docker-build-master:
variables:
IMAGE_TAGS: latest master
<<: *docker-build-instructions
only:
- master
docker-build:
extends: .docker-build-instructions
variables:
IMAGE_TAGS: $CI_COMMIT_REF_NAME release
except:
- master
# (Security) Scanning templates
include:
- template: Security/Container-Scanning.gitlab-ci.yml
- template: Security/Secret-Detection.gitlab-ci.yml
# Disabled because the scanner does not work properly with Gradle multi-project builds. Remove dot if fixed. See below.
#- template: Dependency-Scanning.gitlab-ci.yml
container_scanning:
stage: verify
variables:
CS_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
needs:
- job: docker-build
optional: true
artifacts: false
- job: docker-build-master
optional: true
artifacts: false
# Disabled because the scanner does not work properly with Gradle multi-project builds. Remove dot if fixed. See above.
.dependency_scanning:
stage: verify
needs: []
secret_detection:
stage: verify
needs: []
variables:
SECRET_DETECTION_EXCLUDED_PATHS: '.gradle'
deployment_trigger:incubating:
stage: deploy
image: buildpack-deps:buster-curl
script:
- echo "Triggering deployment for branch $CI_COMMIT_REF_NAME"
- curl --fail -X POST -F "token=$PIPELINE_TRIGGER_TOKEN" -F "ref=master" -F "variables[ORKG_COMPONENT_NAME]=orkg-rest-api" -F "variables[ORKG_COMPONENT_REF_NAME]=$CI_COMMIT_REF_NAME" https://git.tib.eu/api/v4/projects/1317/trigger/pipeline
rules:
- if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
# Disable cloning, downloading artifacts and caching
cache: []
dependencies: []
variables:
GIT_STRATEGY: none
needs:
- docker-build-master
deployment_trigger:release:
stage: deploy
image: buildpack-deps:buster-curl
script:
- echo "Triggering deployment for release version $CI_COMMIT_TAG"
- curl --fail -X POST -F "token=$PIPELINE_TRIGGER_TOKEN" -F "ref=master" -F "variables[ORKG_COMPONENT_NAME]=orkg-rest-api" -F "variables[ORKG_COMPONENT_REF_NAME]=$CI_COMMIT_REF_NAME" -F "variables[ORKG_COMPONENT_RELEASE_VERSION]=$CI_COMMIT_TAG" https://git.tib.eu/api/v4/projects/1317/trigger/pipeline
rules:
- if: $CI_COMMIT_TAG
# Disable cloning, downloading artifacts and caching
cache: []
dependencies: []
variables:
GIT_STRATEGY: none
needs:
- docker-build