-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy path.gitlab-ci.yml
More file actions
358 lines (342 loc) · 14.7 KB
/
Copy path.gitlab-ci.yml
File metadata and controls
358 lines (342 loc) · 14.7 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
include:
- project: 'to-be-continuous/docker'
ref: '5.11.0'
file: '/templates/gitlab-ci-docker.yml'
variables:
BUILD_FOR_INSTALLER: "true"
MAVEN_DEPLOY_ARGS: deploy
MAVEN_CLI_OPTS: $MAVEN_CLI_OPTS -U -q
MAVEN_OPTS: >-
-Dhttps.protocols=TLSv1.2
-Dmaven.repo.local=${MAVEN_CFG_DIR}/repository
-Dorg.slf4j.simpleLogger.showDateTime=true
-Djava.awt.headless=true
-Dnetbeans.verify.integrity=false
# -Dmaven.test.skip=true
DOCKER_REGISTRY_MIRROR: docker.snap-ci.ovh
DOCKER_REGISTRY_USER: $NEXUS_USER
DOCKER_REGISTRY_PASSWORD: $NEXUS_PASSWORD
DOCKER_FILE: "docker/build/Dockerfile"
DOCKER_CONTEXT_PATH: "${CI_PROJECT_DIR}"
DOCKER_SNAPSHOT_IMAGE: "$NEXUS_URL/$CI_PROJECT_NAME:15.0.0-SNAPSHOT"
DOCKER_RELEASE_IMAGE: "$NEXUS_URL/$CI_PROJECT_NAME:15.0.0"
DOCKER_TRIVY_ARGS: "--ignore-unfixed --vuln-type os --debug --timeout 15m"
DOCKER_TRIVY_SECURITY_LEVEL_THRESHOLD: CRITICAL
DOCKER_TRIVY_IMAGE: "ghcr.io/aquasecurity/trivy:latest"
DOCKER_BUILD_ARGS: "--cache=true --compressed-caching=false --use-new-run --cleanup --build-arg LICENSE=${INSTALL4J_LICENSE} --build-arg=UPLOAD_URL --build-arg=NEXUS_USER --build-arg=NEXUS_PASS --target=unix"
DOCKER_HADOLINT_ARGS: --failure-threshold error
DOCKER_PROD_PUBLISH_STRATEGY: auto
DOCKER_BUILD_CACHE_DISABLED: "true"
COMPILE_BRANCH: master
# RECOMPILE: "true"
RECOMPILE:
description: When other projects should be recompiled or if artifacts are already safe to get from COMPILE_BRANCH
value: "true"
options:
- "true"
- "false"
# Trigger pipelines via API for the following projects to bypass downstream multiproject trigger limited to 5 projects
GITLAB_API_URL: "https://gitlab.com/api/v4"
PROJECT_ENGINE: '{"ID" : "42613488", "TOKEN" : "$TRIGGER_TOKEN_ENGINE"}'
PROJECT_DESKTOP: '{"ID" : "42613585", "TOKEN" : "$TRIGGER_TOKEN_DESKTOP"}'
PROJECTS: '[
{"ID" : "45963970", "TOKEN" : "$TRIGGER_TOKEN_MICROWAVE"},
{"ID" : "45964007", "TOKEN" : "$TRIGGER_TOKEN_OPTICAL"},
{"ID" : "46471532", "TOKEN" : "$TRIGGER_TOKEN_ESA_SNAPPY"},
{"ID" : "44112186", "TOKEN" : "$TRIGGER_TOKEN_SMOS_BOX"}
]'
stages:
- compile
- build
- package-build
- package-test
- publish
- gpt-tests
# Compile other projects first to get freshly built artifacts
.compile:
stage: compile
rules:
- if: $CI_COMMIT_TAG
variables:
COMPILE_BRANCH: $CI_COMMIT_TAG
# - if: $BRANCH
# variables:
# COMPILE_BRANCH: $BRANCH
- if: $RECOMPILE == "true"
when: always
- if: $RECOMPILE == "false"
when: never
compile-snap-engine:
extends: .compile
image: alpine
before_script:
- apk add --no-cache curl
- apk add --no-cache jq
- mkdir -p artifacts
script:
- |
echo "Ref is $COMPILE_BRANCH"
PROJECT_ID=$(echo "$PROJECT_ENGINE" | jq -r '.ID')
TOKEN=$(echo "$PROJECT_ENGINE" | jq -r '.TOKEN')
RESPONSE=$(curl --retry 3 --retry-delay 5 -X POST --fail -F token=$TOKEN -F variables[BUILD_FOR_INSTALLER]=$BUILD_FOR_INSTALLER -F ref=$COMPILE_BRANCH https://gitlab.com/api/v4/projects/$PROJECT_ID/trigger/pipeline)
echo "RESPONSE $RESPONSE"
PIPELINE_ID=$(echo "$RESPONSE" | jq -r '.id')
echo "Triggered pipeline $PIPELINE_ID for project $PROJECT_ID"
while true; do
echo "Checking pipeline $PIPELINE_ID for project $PROJECT_ID..."
STATUS=$(curl --retry 3 --retry-delay 5 --silent --header "PRIVATE-TOKEN: $CI_JOB_TOKEN" "$GITLAB_API_URL/projects/$PROJECT_ID/pipelines/$PIPELINE_ID" | jq -r '.status')
echo "Pipeline $PIPELINE_ID status: $STATUS"
if [[ "$STATUS" == "success" ]]; then
echo "Pipeline $PIPELINE_ID completed successfully!"
break
elif [[ "$STATUS" == "failed" || "$STATUS" == "canceled" ]]; then
echo "Pipeline $PIPELINE_ID failed or was canceled!"
exit 1
fi
sleep 30
done
echo "Fetching job list for pipeline $PIPELINE_ID in project $PROJECT_ID..."
JOB_ID=$(curl --retry 3 --retry-delay 5 --silent --header "PRIVATE-TOKEN: $CI_JOB_TOKEN" "$GITLAB_API_URL/projects/$PROJECT_ID/pipelines/$PIPELINE_ID/jobs" | jq -r '.[] | select(.name=="mvn-build" and .status=="success") | .id' | head -n 1)
echo "Downloading artifacts from job $JOB_ID in project $PROJECT_ID..."
curl --retry 3 --retry-delay 5 --silent --location --output "artifacts_$PROJECT_ID.zip" --header "PRIVATE-TOKEN: $CI_JOB_TOKEN" "$GITLAB_API_URL/projects/$PROJECT_ID/jobs/$JOB_ID/artifacts"
unzip artifacts_$PROJECT_ID.zip "etc/*" -d artifacts
unzip artifacts_$PROJECT_ID.zip "LICENSE.html" -d artifacts
rm artifacts_$PROJECT_ID.zip
artifacts:
paths:
- artifacts/**
compile-snap-desktop:
extends: .compile
image: alpine
before_script:
- apk add --no-cache curl
- apk add --no-cache jq
- mkdir -p artifacts
script:
- |
PROJECT_ID=$(echo "$PROJECT_DESKTOP" | jq -r '.ID')
TOKEN=$(echo "$PROJECT_DESKTOP" | jq -r '.TOKEN')
RESPONSE=$(curl --retry 3 --retry-delay 5 -X POST --fail -F token=$TOKEN -F variables[BUILD_FOR_INSTALLER]=$BUILD_FOR_INSTALLER -F ref=$COMPILE_BRANCH https://gitlab.com/api/v4/projects/$PROJECT_ID/trigger/pipeline)
echo "RESPONSE $RESPONSE"
PIPELINE_ID=$(echo "$RESPONSE" | jq -r '.id')
echo "Triggered pipeline $PIPELINE_ID for project $PROJECT_ID"
while true; do
echo "Checking pipeline $PIPELINE_ID for project $PROJECT_ID..."
STATUS=$(curl --retry 3 --retry-delay 5 --silent --header "PRIVATE-TOKEN: $CI_JOB_TOKEN" "$GITLAB_API_URL/projects/$PROJECT_ID/pipelines/$PIPELINE_ID" | jq -r '.status')
echo "Pipeline $PIPELINE_ID status: $STATUS"
if [[ "$STATUS" == "success" ]]; then
echo "Pipeline $PIPELINE_ID completed successfully!"
break
elif [[ "$STATUS" == "failed" || "$STATUS" == "canceled" ]]; then
echo "Pipeline $PIPELINE_ID failed or was canceled!"
exit 1
fi
sleep 30
done
echo "Fetching job list for pipeline $PIPELINE_ID in project $PROJECT_ID..."
JOB_ID=$(curl --retry 3 --retry-delay 5 --silent --header "PRIVATE-TOKEN: $CI_JOB_TOKEN" "$GITLAB_API_URL/projects/$PROJECT_ID/pipelines/$PIPELINE_ID/jobs" | jq -r '.[] | select(.name=="mvn-build" and .status=="success") | .id' | head -n 1)
echo "Downloading artifacts from job $JOB_ID in project $PROJECT_ID..."
curl --retry 3 --retry-delay 5 --silent --location --output "artifacts_$PROJECT_ID.zip" --header "PRIVATE-TOKEN: $CI_JOB_TOKEN" "$GITLAB_API_URL/projects/$PROJECT_ID/jobs/$JOB_ID/artifacts"
unzip artifacts_$PROJECT_ID.zip "snap-application/target/*" -d artifacts
unzip artifacts_$PROJECT_ID.zip "snap-main/target/*" -d artifacts
unzip artifacts_$PROJECT_ID.zip "snap-smart-configurator-ui/src/main/resources/org/esa/snap/smart/configurator/ui/Performance32.png" -d artifacts
rm artifacts_$PROJECT_ID.zip
needs:
- job: compile-snap-engine
artifacts:
paths:
- artifacts/**
compile-others-trigger-pipelines:
extends: .compile
image: alpine
before_script:
- apk add --no-cache curl
- apk add --no-cache jq
script:
- echo "Triggering pipelines for projects $PROJECT_IDS"
- |
for item in $(echo "$PROJECTS" | jq -c '.[]'); do
PROJECT_ID=$(echo "$item" | jq -r '.ID')
TOKEN=$(echo "$item" | jq -r '.TOKEN')
RESPONSE=$(curl --retry 3 --retry-delay 5 -X POST --fail -F token=$TOKEN -F variables[BUILD_FOR_INSTALLER]=$BUILD_FOR_INSTALLER -F ref=$COMPILE_BRANCH https://gitlab.com/api/v4/projects/$PROJECT_ID/trigger/pipeline)
echo "RESPONSE $RESPONSE"
PIPELINE_ID=$(echo "$RESPONSE" | jq -r '.id')
echo "Triggered pipeline $PIPELINE_ID for project $PROJECT_ID"
echo "$PROJECT_ID=$PIPELINE_ID" >> pipeline.env
done
needs:
- job: compile-snap-engine
- job: compile-snap-desktop
artifacts:
paths:
- pipeline.env
compile-others-wait-for-pipelines:
extends: .compile
image: alpine
before_script:
- apk add --no-cache curl
- apk add --no-cache jq
script:
- echo "Waiting for pipelines to finish..."
- |
while true; do
FINISHED=0
for item in $(echo "$PROJECTS" | jq -c '.[]'); do
PROJECT_ID=$(echo "$item" | jq -r '.ID')
PIPELINE_ID=$(grep "$PROJECT_ID=" pipeline.env | cut -d '=' -f2)
echo "Checking pipeline $PIPELINE_ID for project $PROJECT_ID..."
STATUS=$(curl --retry 3 --retry-delay 5 --silent --header "PRIVATE-TOKEN: $CI_JOB_TOKEN" "$GITLAB_API_URL/projects/$PROJECT_ID/pipelines/$PIPELINE_ID" | jq -r '.status')
echo "Pipeline $PIPELINE_ID status: $STATUS"
if [[ "$STATUS" == "success" ]]; then
echo "Pipeline $PIPELINE_ID completed successfully!"
FINISHED=$(($FINISHED + 1))
elif [[ "$STATUS" == "failed" || "$STATUS" == "canceled" ]]; then
echo "Pipeline $PIPELINE_ID failed or was canceled!"
exit 1
fi
done
PROJECTS_COUNT=$(echo "$PROJECTS" | jq 'length')
echo "Projects: $PROJECTS_COUNT"
echo "Finished: $FINISHED"
if [ $FINISHED -eq $PROJECTS_COUNT ]; then
break
else
sleep 30
fi
done
needs:
- job: compile-others-trigger-pipelines
artifacts:
paths:
- pipeline.env
compile-others-fetch-artifacts:
extends: .compile
image: alpine
before_script:
- apk add --no-cache curl
- apk add --no-cache jq
- mkdir -p artifacts
script:
- |
for item in $(echo "$PROJECTS" | jq -c '.[]'); do
PROJECT_ID=$(echo "$item" | jq -r '.ID')
TOKEN=$(echo "$item" | jq -r '.TOKEN')
PIPELINE_ID=$(grep "$PROJECT_ID=" pipeline.env | cut -d '=' -f2)
echo "Fetching job list for pipeline $PIPELINE_ID in project $PROJECT_ID..."
JOB_ID=$(curl --retry 3 --retry-delay 5 --silent --header "PRIVATE-TOKEN: $CI_JOB_TOKEN" "$GITLAB_API_URL/projects/$PROJECT_ID/pipelines/$PIPELINE_ID/jobs" | jq -r '.[] | select(.name=="mvn-build" and .status=="success") | .id' | head -n 1)
echo "Downloading artifacts from job $JOB_ID in project $PROJECT_ID..."
curl --retry 3 --retry-delay 5 --silent --location --output "artifacts_$PROJECT_ID.zip" --header "PRIVATE-TOKEN: $CI_JOB_TOKEN" "$GITLAB_API_URL/projects/$PROJECT_ID/jobs/$JOB_ID/artifacts"
if [[ "$TOKEN" == "$TRIGGER_TOKEN_MICROWAVE" ]]; then
unzip artifacts_$PROJECT_ID.zip "microwavetbx-kit/target/netbeans_clusters/microwavetbx/*" -d artifacts
unzip artifacts_$PROJECT_ID.zip "microwavetbx-kit/target/netbeans_clusters/rstb/*" -d artifacts
fi
if [[ "$TOKEN" == "$TRIGGER_TOKEN_OPTICAL" ]]; then
unzip artifacts_$PROJECT_ID.zip "opttbx-kit/target/netbeans_clusters/opttbx/*" -d artifacts
fi
if [[ "$TOKEN" == "$TRIGGER_TOKEN_ESA_SNAPPY" ]]; then
unzip artifacts_$PROJECT_ID.zip "esasnappy-kit/target/nbm/clusters/extra/*" -d artifacts
fi
if [[ "$TOKEN" == "$TRIGGER_TOKEN_SMOS_BOX" ]]; then
unzip artifacts_$PROJECT_ID.zip "smos-kit/target/netbeans_clusters/*" -d artifacts
fi
rm artifacts_$PROJECT_ID.zip
done
needs:
- job: compile-others-wait-for-pipelines
artifacts:
expire_in: 2 hours
paths:
- artifacts/**
# Fetch artifacts built at compile stage
build:
stage: build
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
variables:
MAVEN_CLI_OPTS: >-
--no-transfer-progress
--batch-mode
--errors
--fail-at-end
--show-version
-DdeployAtEnd=false
-Denable.long.tests=true
when: on_success
- if: $BRANCH
variables:
COMPILE_BRANCH: $BRANCH
when: on_success
- if: $RECOMPILE == "false"
when: always
- when: on_success
needs:
- job: compile-snap-engine
- job: compile-snap-desktop
- job: compile-others-fetch-artifacts
script:
- |
mv artifacts/* .
rmdir artifacts
artifacts:
expire_in: 2 hours
paths:
- LICENSE.html
- etc
- "${CI_PROJECT_DIR}/snap-application/target"
- "${CI_PROJECT_DIR}/snap-main/target"
- "${CI_PROJECT_DIR}/snap-smart-configurator-ui/src/main/resources/org/esa/snap/smart/configurator/ui/Performance32.png"
- "${CI_PROJECT_DIR}/microwavetbx-kit/target/netbeans_clusters/microwavetbx"
- "${CI_PROJECT_DIR}/microwavetbx-kit/target/netbeans_clusters/rstb"
- "${CI_PROJECT_DIR}/opttbx-kit/target/netbeans_clusters/opttbx"
- "${CI_PROJECT_DIR}/smos-kit/target/netbeans_clusters"
- "${CI_PROJECT_DIR}/esasnappy-kit/target/nbm/clusters/extra"
# Before building the image we need other projects artifacts
docker-kaniko-build:
needs:
- job: build
artifacts: true
docker-publish:
before_script:
- dnf install -y gawk
- !reference [.docker-scripts]
# Triggers 3 GPT tests pipelines (linux,windows,macos)
gpt-tests:
stage: gpt-tests
image: curlimages/curl
script:
- |-
curl --retry 3 --retry-delay 5 -X POST --fail -F token=$TRIGGER_TOKEN_GPT_TESTS -F ref=$COMPILE_BRANCH -F "variables[SCOPE]=daily" -F "variables[PLATFORM]=linux" https://gitlab.com/api/v4/projects/43939974/trigger/pipeline &
curl --retry 3 --retry-delay 5 -X POST --fail -F token=$TRIGGER_TOKEN_GPT_TESTS -F ref=$COMPILE_BRANCH -F "variables[SCOPE]=daily" -F "variables[PLATFORM]=windows" https://gitlab.com/api/v4/projects/43939974/trigger/pipeline &
curl --retry 3 --retry-delay 5 -X POST --fail -F token=$TRIGGER_TOKEN_GPT_TESTS -F ref=$COMPILE_BRANCH -F "variables[SCOPE]=daily" -F "variables[PLATFORM]=darwin" https://gitlab.com/api/v4/projects/43939974/trigger/pipeline &
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
allow_failure: true
# Report on Github cf https://ecp-ci.gitlab.io/docs/guides/build-status-gitlab.html
.report-status:
image: curlimages/curl
variables:
URL: "https://api.github.com/repos/${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME}/statuses/${CI_COMMIT_SHA}"
STATUS_NAME: snap-ci
script:
# For complete details on the GitHub API please see:
# https://docs.github.com/en/rest/commits/statuses?apiVersion=2022-11-28#create-a-commit-status
- |-
curl --retry 3 --retry-delay 5 -X POST $URL -H "Accept: application/vnd.github+json" -H "Authorization: Bearer $GITHUB_TOKEN" -H "X-GitHub-Api-Version: 2022-11-28" -d '{"state": "'$CI_JOB_NAME'", "context": "'$STATUS_NAME'", "target_url": "'$CI_PIPELINE_URL'", "description": "Build snap docker image"}'
environment:
name: reporting-github
dependencies: []
retry: 2
pending:
stage: .pre
extends:
- .report-status
success:
stage: .post
extends:
- .report-status
failure:
stage: .post
extends:
- .report-status
rules:
- when: on_failure