-
Notifications
You must be signed in to change notification settings - Fork 1
/
.gitlab-ci.yml
311 lines (271 loc) · 11.1 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
image: tomcat:9-jdk8-openjdk-slim-buster
variables:
MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version"
MAVEN_OPTS: "-Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository -Dhttps.protocols=TLSv1.2 -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN -Dorg.slf4j.simpleLogger.showDateTime=true -Djava.awt.headless=true"
RIESGOS_SERVICES: "assetmaster deus eve flooddamage modelprop quakeledger shakyground volcanus neptunus"
cache:
paths:
- .m2/repository/
- .local/
stages:
- test
- build
- deploy
before_script:
- env
- DEBIAN_FRONTEND=noninteractive apt update && apt upgrade -y
- DEBIAN_FRONTEND=noninteractive apt install -y maven
- which java
- java -version
- mvn --version
.install_configuration_files: &install_configuration_files
# copy configuration files of services to running docker container
- >
for service in ${RIESGOS_SERVICES}; do
if [ ! -f "conf/${service}.json" ]; then
echo "Configuration file conf/${service}.json does not exist, skipping"
else
docker cp "conf/${service}.json" ${TARGET_CONTAINER}:/usr/share/riesgos/json-configurations
fi
done
.cleanup_docker_all: &cleanup_docker_all
- docker image prune --all --force
- docker volume prune --force
.cleanup_docker_dangling: &cleanup_docker_dangling
- docker rmi $(docker images -q -f dangling=true) || true
verify_java:
stage: test
rules:
- if: '$CI_PIPELINE_SOURCE == "schedule"'
when: never
- if: '$CI_PIPELINE_SOURCE == "pipeline"'
when: never
- if: $CI_COMMIT_BRANCH
changes:
- src/**/*
- pom.xml
- checkstyle-suppressions.xml
- .gitlab-ci.yml
script:
- mvn $MAVEN_CLI_OPTS clean verify
- mvn $MAVEN_CLI_OPTS clean test-compile
checkstyle:
stage: test
rules:
- if: '$CI_PIPELINE_SOURCE == "schedule"'
when: never
- if: '$CI_PIPELINE_SOURCE == "pipeline"'
when: never
- if: $CI_COMMIT_BRANCH
changes:
- src/**/*
- pom.xml
- checkstyle-suppressions.xml
- .gitlab-ci.yml
script:
- 'mvn $MAVEN_CLI_OPTS clean checkstyle:checkstyle'
integration_test:
rules:
- if: '$CI_PIPELINE_SOURCE == "schedule"'
when: always
- if: '$CI_PIPELINE_SOURCE == "pipeline"'
when: never
before_script:
- DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y wget
tags:
- group
script:
- if [ ! -f ".local/apache-jmeter-5.1.1.tgz" ]; then mkdir .local && wget "https://archive.apache.org/dist/jmeter/binaries/apache-jmeter-5.1.1.tgz" -O .local/apache-jmeter-5.1.1.tgz; fi
- tar xf .local/apache-jmeter-5.1.1.tgz
- cd integration-tests
- bash ../apache-jmeter-5.1.1/bin/jmeter.sh -n -t RIESGOS-integration-tests.jmx -o jmeter-report -l jmeter-log.txt -e
- cat jmeter-log.txt
- if [ "$(fgrep -c 'Test failed' jmeter-log.txt)" != "0" ]; then false; else true; fi
artifacts:
name: jmeter-report
paths:
- ${CI_PROJECT_DIR}/integration-tests/jmeter-report
dockerbuild_latest:
image: docker:20.10.12
stage: build
before_script: []
cache: {}
rules:
- if: '$CI_PIPELINE_SOURCE == "schedule"'
when: never
- if: '$CI_PIPELINE_SOURCE == "pipeline"'
when: never
- if: $CI_COMMIT_BRANCH
tags:
- group
script:
- docker build -t riesgos-wps:latest -f assistance/Dockerfile .
# push latest image to Docker Hub
- docker tag riesgos-wps:latest gfzriesgos/riesgos-wps:latest
- docker login -u ${DOCKERHUB_USER} -p ${DOCKERHUB_PASSWORD}
- docker push gfzriesgos/riesgos-wps:latest
# push latest image to GitLab Container Registry
- docker tag riesgos-wps:latest git.gfz-potsdam.de:5000/id2/riesgos/gfz-riesgos-wps-repository:latest
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker push git.gfz-potsdam.de:5000/id2/riesgos/gfz-riesgos-wps-repository:latest
dockerbuild_tagged:
image: docker:20.10.12
stage: build
before_script: []
cache: {}
tags:
- group
rules:
- if: '$CI_PIPELINE_SOURCE == "schedule"'
when: never
- if: '$CI_PIPELINE_SOURCE == "pipeline"'
when: never
- if: $CI_COMMIT_TAG
script:
- docker build -t riesgos-wps:$CI_COMMIT_TAG -f assistance/Dockerfile .
# push image to Docker Hub
- docker tag riesgos-wps:$CI_COMMIT_TAG gfzriesgos/riesgos-wps:$CI_COMMIT_TAG
- docker login -u ${DOCKERHUB_USER} -p ${DOCKERHUB_PASSWORD}
- docker push gfzriesgos/riesgos-wps:$CI_COMMIT_TAG
# push image to GitLab Container Registry
- docker tag riesgos-wps:$CI_COMMIT_TAG git.gfz-potsdam.de:5000/id2/riesgos/gfz-riesgos-wps-repository:$CI_COMMIT_TAG
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker push git.gfz-potsdam.de:5000/id2/riesgos/gfz-riesgos-wps-repository:$CI_COMMIT_TAG
deploy_staging:
image: docker/compose:1.25.5
stage: deploy
before_script:
- apk update
- apk add bash wget tar gzip curl netcat-openbsd
cache: {}
allow_failure: false
when: manual
tags:
- riesgos
- deploy
variables:
TARGET_CONTAINER: "riesgos-wps-staging"
rules:
- if: '$CI_PIPELINE_SOURCE == "schedule"'
when: never
- if: '$CI_PIPELINE_SOURCE == "pipeline"'
when: never
- if: $CI_COMMIT_BRANCH
script:
- rm -rf /builds/riesgos-assistance-staging || true
- cp -vr assistance /builds/riesgos-assistance-staging
- cd /builds/riesgos-assistance-staging
# download waiting script used for checking GeoServer later
- wget "https://raw.githubusercontent.com/eficode/wait-for/v2.2.1/wait-for" -O wait-for.sh
- chmod 755 wait-for.sh
# replace placeholders in configuration files
# we need both versions (staging/production) of those files as we have both
# environments on the same server and the /builds directory is shared
- sed -i -e "s@__GEOSERVER_PASSWORD__@${GEOSERVER_PASSWORD_STAGING}@g" users-staging.xml
- sed -i -e "s@__GEOSERVER_PASSWORD__@${GEOSERVER_PLAIN_PASSWORD_STAGING}@g" SLD/add-style-to-geoserver.sh
- sed -i -e "s@__GEOSERVER_PASSWORD__@${GEOSERVER_PLAIN_PASSWORD_STAGING}@g" docker-compose-staging.yml
- sed -i -e "s@__WPS_URL__@${WPS_URL_STAGING}@g" application_properties_staging.js
- sed -i -e "s@__GEOSERVER_URL__@${GEOSERVER_URL_STAGING}@g" SLD/add-style-to-geoserver.sh
- sed -i -e "s@__GEOSERVER_URL__@${GEOSERVER_URL_STAGING}@g" geoserver-global.xml
- sed -i -e "s@__GEOSERVER_URL__@${GEOSERVER_URL_STAGING}@g" docker-compose-staging.yml
- sed -i -e "s@__MANAGER_PASSWORD__@${MANAGER_PASSWORD_STAGING}@g" tomcat-users-staging.xml
- docker-compose -f docker-compose-staging.yml pull
# get configuration files of services
- /bin/bash get-configuration-files.sh docker-compose-staging.yml
- docker-compose -p riesgos-staging -f docker-compose-staging.yml down --remove-orphans || true
- docker-compose -p riesgos-staging -f docker-compose-staging.yml up -d
# copy configuration files of services to running docker container
- *install_configuration_files
# copy configuration for GeoServer
- docker cp "geoserver-global.xml" riesgos-wps-staging:/usr/local/tomcat/webapps/geoserver/data/global.xml
# wait for GeoServer to be ready then deploy ShakeMap style to GeoServer
- ./wait-for.sh --timeout 300 "${GEOSERVER_URL_STAGING}/index.html"
- cd SLD
- /bin/bash add-style-to-geoserver.sh
# since we have both staging and production on the same server only the
# staging deployment is allowed to cleanup all the docker images afterwards
- *cleanup_docker_all
deploy_production:
image: docker/compose:1.25.5
stage: deploy
before_script:
- apk update
- apk add bash wget tar gzip curl netcat-openbsd
cache: {}
allow_failure: false
when: manual
tags:
- riesgos
- deploy
variables:
TARGET_CONTAINER: "riesgos-wps-prod"
rules:
- if: '$CI_PIPELINE_SOURCE == "schedule"'
when: never
- if: '$CI_PIPELINE_SOURCE == "pipeline"'
when: never
- if: $CI_COMMIT_TAG
script:
- rm -rf /builds/riesgos-assistance-prod || true
- cp -vr assistance /builds/riesgos-assistance-prod
- cd /builds/riesgos-assistance-prod
# download waiting script used for checking GeoServer later
- wget "https://raw.githubusercontent.com/eficode/wait-for/v2.2.1/wait-for" -O wait-for.sh
- chmod 755 wait-for.sh
# replace placeholders in configuration files
# we need both versions (staging/production) of those files as we have both
# environments on the same server and the /builds directory is shared
- sed -i -e "s@__GEOSERVER_PASSWORD__@${GEOSERVER_PASSWORD_PROD}@g" users-prod.xml
- sed -i -e "s@__GEOSERVER_PASSWORD__@${GEOSERVER_PLAIN_PASSWORD_PROD}@g" SLD/add-style-to-geoserver.sh
- sed -i -e "s@__GEOSERVER_PASSWORD__@${GEOSERVER_PLAIN_PASSWORD_PROD}@g" docker-compose-prod.yml
- sed -i -e "s@__WPS_URL__@${WPS_URL_PROD}@g" application_properties_prod.js
- sed -i -e "s@__GEOSERVER_URL__@${GEOSERVER_URL_PROD}@g" SLD/add-style-to-geoserver.sh
- sed -i -e "s@__GEOSERVER_URL__@${GEOSERVER_URL_PROD}@g" geoserver-global.xml
- sed -i -e "s@__GEOSERVER_URL__@${GEOSERVER_URL_PROD}@g" docker-compose-prod.yml
- sed -i -e "s@__MANAGER_PASSWORD__@${MANAGER_PASSWORD_PROD}@g" tomcat-users-prod.xml
- sed -i -e "s@__PROD_IMAGE_TAG__@${CI_COMMIT_TAG}@g" docker-compose-prod.yml
- docker-compose -f docker-compose-prod.yml pull
# get configuration files of services
- /bin/bash get-configuration-files.sh docker-compose-prod.yml
- docker-compose -p riesgos-prod -f docker-compose-prod.yml down --remove-orphans || true
- docker-compose -p riesgos-prod -f docker-compose-prod.yml up -d
# copy configuration files of services to running docker container
- *install_configuration_files
# copy configuration for GeoServer
- docker cp "geoserver-global.xml" riesgos-wps-prod:/usr/local/tomcat/webapps/geoserver/data/global.xml
# wait for GeoServer to be ready then deploy ShakeMap style to GeoServer
- ./wait-for.sh --timeout 300 "${GEOSERVER_URL_PROD}/index.html"
- cd SLD
- /bin/bash add-style-to-geoserver.sh
# only remove dangling images after production deployment, otherwise there
# is the possibilty to destroy the staging docker setup, since newer
# versions of the service may were installed between the deployments
# (via trigger job) and have no container belonging to the newer image
- *cleanup_docker_dangling
deploy_latest_images:
image: docker/compose:1.25.5
stage: deploy
before_script:
- apk update
- apk add bash wget tar gzip
cache: {}
allow_failure: false
when: manual
tags:
- riesgos
- deploy
variables:
TARGET_CONTAINER: "riesgos-wps-staging"
rules:
- if: '$CI_PIPELINE_SOURCE == "schedule"'
when: never
- if: '$CI_PIPELINE_SOURCE == "pipeline" && $DEPLOY_LATEST_IMAGES == "true"'
when: always
- if: $CI_COMMIT_BRANCH
script:
- cd /builds/riesgos-assistance-staging
- docker-compose -f docker-compose-staging.yml pull
# get configuration files of services
- /bin/bash get-configuration-files.sh docker-compose-staging.yml
- *install_configuration_files
- *cleanup_docker_dangling