forked from ao-space/platform-base
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
280 lines (264 loc) · 12.6 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
# Copyright (c) 2022 Institute of Software Chinese Academy of Sciences (ISCAS)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
workflow:
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
when: never
- if: $CI_COMMIT_BRANCH
image: registry.eulix.xyz/collab/infra/public-service/maven:3.6.3-openjdk-11
stages:
- license_check
- license_fix
- secret
- validate
- package
- docker
- manifest
- sign
- codelint
- cloc
include:
- project: 'bp/ams-ci-template'
ref: main
file: '/sonarqube.yml'
- project: 'bp/ams-ci-template'
ref: main
file: '/license.yml'
- project: 'bp/ams-ci-template'
ref: main
file: '/cloc.yml'
- project: 'bp/ams-ci-template'
ref: main
file: '/secret-detection.yml'
variables:
MAVEN_OPTS: "-Dhttps.protocols=TLSv1.2 -Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN -Dorg.slf4j.simpleLogger.showDateTime=true -Djava.awt.headless=true"
MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version"
ENV_SONARQUBE_TYPE: maven
ENV_LICENSE_TYPE: maven
ENV_CONTAINER_NAME: platform-registry
LM_JAVA_VERSION: 11
cache:
key: ${CI_JOB_NAME}
paths:
- .m2/repository
- .sonar/cache
validate:compile:
stage: validate
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
when: never
- if: $CI_MERGE_REQUEST_ID
tags:
- x86_64
script:
- mvn $MAVEN_CLI_OPTS test-compile
validate:test:
stage: validate
allow_failure: true
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
when: never
- if: $CI_MERGE_REQUEST_ID
tags:
- x86_64
script:
- mvn $MAVEN_CLI_OPTS verify
package:x86_64:community:
stage: package
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
when: never
- if: $CI_COMMIT_BRANCH
- if: $CI_MERGE_REQUEST_ID
tags:
- x86_64
script:
- mvn -pl eulixplatform-common,eulixplatform-registry $MAVEN_CLI_OPTS clean package -Pcommunity
artifacts:
paths:
- eulixplatform-common/target/
- eulixplatform-registry/target/
package:aarch64:community:
stage: package
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
when: never
- if: $CI_COMMIT_BRANCH
- if: $CI_MERGE_REQUEST_ID
tags:
- aarch64
script:
- mvn -pl eulixplatform-common,eulixplatform-registry $MAVEN_CLI_OPTS clean package -Pcommunity
artifacts:
paths:
- eulixplatform-common/target/
- eulixplatform-registry/target/
docker:aarch64:community:
stage: docker
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
when: never
- if: $CI_COMMIT_BRANCH
- if: $CI_MERGE_REQUEST_ID
tags:
- docker_build-aarch64
dependencies:
- package:aarch64:community
script:
- docker login -u $DOCKER_AUTH_USERNAME -p $DOCKER_AUTH_PASSWORD $DOCKER_REGISTRY_HOST
- export DOCKER_BUILD_IMAGE=$DOCKER_REGISTRY_IMAGE/$ENV_CONTAINER_NAME:`head -n 1 VERSION`-alpha.$CI_PIPELINE_ID
- docker build --build-arg CI_PIPELINE_ID=$CI_PIPELINE_ID --build-arg CI_COMMIT_SHA=$CI_COMMIT_SHA -t $DOCKER_BUILD_IMAGE-aarch64 -f eulixplatform-registry/src/main/docker/Dockerfile.jvm eulixplatform-registry
- docker push $DOCKER_BUILD_IMAGE-aarch64
docker:x86_64:community:
stage: docker
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
when: never
- if: $CI_COMMIT_BRANCH
- if: $CI_MERGE_REQUEST_ID
tags:
- docker_build-x86_64
dependencies:
- package:x86_64:community
script:
- docker login -u $DOCKER_AUTH_USERNAME -p $DOCKER_AUTH_PASSWORD $DOCKER_REGISTRY_HOST
- export DOCKER_BUILD_IMAGE=$DOCKER_REGISTRY_IMAGE/$ENV_CONTAINER_NAME:`head -n 1 VERSION`-alpha.$CI_PIPELINE_ID
- docker build --build-arg CI_PIPELINE_ID=$CI_PIPELINE_ID --build-arg CI_COMMIT_SHA=$CI_COMMIT_SHA -t $DOCKER_BUILD_IMAGE-x86_64 -f eulixplatform-registry/src/main/docker/Dockerfile.jvm eulixplatform-registry
- docker push $DOCKER_BUILD_IMAGE-x86_64
manifest:push:community:
stage: manifest
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
when: never
- if: $CI_COMMIT_BRANCH
tags:
- docker_build
retry: 2
script:
- docker login -u $GITLAB_DOCKER_AUTH_USERNAME -p $GITLAB_DOCKER_AUTH_PASSWORD $GITLAB_DOCKER_REGISTRY_HOST
- docker login -u $DOCKER_AUTH_USERNAME -p $DOCKER_AUTH_PASSWORD $DOCKER_REGISTRY_HOST
- export DOCKER_BUILD_IMAGE=$DOCKER_REGISTRY_IMAGE/$ENV_CONTAINER_NAME:`head -n 1 VERSION`-alpha.$CI_PIPELINE_ID
- export DOCKER_LATEST_IMAGE=$DOCKER_REGISTRY_IMAGE/$ENV_CONTAINER_NAME:$CI_COMMIT_BRANCH
- export DOCKER_BUILD_IMAGE_GITLAB=$GITLAB_DOCKER_REGISTRY_IMAGE/$ENV_CONTAINER_NAME:`head -n 1 VERSION`-alpha.$CI_PIPELINE_ID
- export DOCKER_LATEST_IMAGE_GITLAB=$GITLAB_DOCKER_REGISTRY_IMAGE/$ENV_CONTAINER_NAME:$CI_COMMIT_BRANCH
- sleep 10
- export DOCKER_CLI_EXPERIMENTAL=enabled
- docker pull $DOCKER_BUILD_IMAGE-x86_64
- docker pull $DOCKER_BUILD_IMAGE-aarch64
- docker tag $DOCKER_BUILD_IMAGE-x86_64 $DOCKER_BUILD_IMAGE_GITLAB-x86_64
- docker push $DOCKER_BUILD_IMAGE_GITLAB-x86_64
- docker tag $DOCKER_BUILD_IMAGE-aarch64 $DOCKER_BUILD_IMAGE_GITLAB-aarch64
- docker push $DOCKER_BUILD_IMAGE_GITLAB-aarch64
- docker manifest create --amend $DOCKER_BUILD_IMAGE $DOCKER_BUILD_IMAGE-aarch64 $DOCKER_BUILD_IMAGE-x86_64
- docker manifest annotate --os linux --arch amd64 $DOCKER_BUILD_IMAGE $DOCKER_BUILD_IMAGE-x86_64
- docker manifest annotate --os linux --arch arm64 $DOCKER_BUILD_IMAGE $DOCKER_BUILD_IMAGE-aarch64
- docker manifest push -p $DOCKER_BUILD_IMAGE
- docker manifest create --amend $DOCKER_LATEST_IMAGE $DOCKER_BUILD_IMAGE-aarch64 $DOCKER_BUILD_IMAGE-x86_64
- docker manifest annotate --os linux --arch amd64 $DOCKER_LATEST_IMAGE $DOCKER_BUILD_IMAGE-x86_64
- docker manifest annotate --os linux --arch arm64 $DOCKER_LATEST_IMAGE $DOCKER_BUILD_IMAGE-aarch64
- docker manifest push -p $DOCKER_LATEST_IMAGE
- docker manifest create --amend $DOCKER_BUILD_IMAGE_GITLAB $DOCKER_BUILD_IMAGE_GITLAB-aarch64 $DOCKER_BUILD_IMAGE_GITLAB-x86_64
- docker manifest annotate --os linux --arch amd64 $DOCKER_BUILD_IMAGE_GITLAB $DOCKER_BUILD_IMAGE_GITLAB-x86_64
- docker manifest annotate --os linux --arch arm64 $DOCKER_BUILD_IMAGE_GITLAB $DOCKER_BUILD_IMAGE_GITLAB-aarch64
- docker manifest push -p $DOCKER_BUILD_IMAGE_GITLAB
- docker manifest create --amend $DOCKER_LATEST_IMAGE_GITLAB $DOCKER_BUILD_IMAGE_GITLAB-aarch64 $DOCKER_BUILD_IMAGE_GITLAB-x86_64
- docker manifest annotate --os linux --arch amd64 $DOCKER_LATEST_IMAGE_GITLAB $DOCKER_BUILD_IMAGE_GITLAB-x86_64
- docker manifest annotate --os linux --arch arm64 $DOCKER_LATEST_IMAGE_GITLAB $DOCKER_BUILD_IMAGE_GITLAB-aarch64
- docker manifest push -p $DOCKER_LATEST_IMAGE_GITLAB
manifest:merge_request:community:
stage: manifest
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
when: never
- if: $CI_MERGE_REQUEST_ID
tags:
- docker_build
retry: 2
script:
- docker login -u $GITLAB_DOCKER_AUTH_USERNAME -p $GITLAB_DOCKER_AUTH_PASSWORD $GITLAB_DOCKER_REGISTRY_HOST
- docker login -u $DOCKER_AUTH_USERNAME -p $DOCKER_AUTH_PASSWORD $DOCKER_REGISTRY_HOST
- export DOCKER_BUILD_IMAGE=$DOCKER_REGISTRY_IMAGE/$ENV_CONTAINER_NAME:`head -n 1 VERSION`-alpha.$CI_PIPELINE_ID
- export DOCKER_LATEST_IMAGE=$DOCKER_REGISTRY_IMAGE/$ENV_CONTAINER_NAME:$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME
- export DOCKER_BUILD_IMAGE_GITLAB=$GITLAB_DOCKER_REGISTRY_IMAGE/$ENV_CONTAINER_NAME:`head -n 1 VERSION`-alpha.$CI_PIPELINE_ID
- export DOCKER_LATEST_IMAGE_GITLAB=$GITLAB_DOCKER_REGISTRY_IMAGE/$ENV_CONTAINER_NAME:$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME
- sleep 10
- export DOCKER_CLI_EXPERIMENTAL=enabled
- docker pull $DOCKER_BUILD_IMAGE-x86_64
- docker pull $DOCKER_BUILD_IMAGE-aarch64
- docker tag $DOCKER_BUILD_IMAGE-x86_64 $DOCKER_BUILD_IMAGE_GITLAB-x86_64
- docker push $DOCKER_BUILD_IMAGE_GITLAB-x86_64
- docker tag $DOCKER_BUILD_IMAGE-aarch64 $DOCKER_BUILD_IMAGE_GITLAB-aarch64
- docker push $DOCKER_BUILD_IMAGE_GITLAB-aarch64
- docker manifest create --amend $DOCKER_BUILD_IMAGE $DOCKER_BUILD_IMAGE-aarch64 $DOCKER_BUILD_IMAGE-x86_64
- docker manifest annotate --os linux --arch amd64 $DOCKER_BUILD_IMAGE $DOCKER_BUILD_IMAGE-x86_64
- docker manifest annotate --os linux --arch arm64 $DOCKER_BUILD_IMAGE $DOCKER_BUILD_IMAGE-aarch64
- docker manifest push -p $DOCKER_BUILD_IMAGE
- docker manifest create --amend $DOCKER_LATEST_IMAGE $DOCKER_BUILD_IMAGE-aarch64 $DOCKER_BUILD_IMAGE-x86_64
- docker manifest annotate --os linux --arch amd64 $DOCKER_LATEST_IMAGE $DOCKER_BUILD_IMAGE-x86_64
- docker manifest annotate --os linux --arch arm64 $DOCKER_LATEST_IMAGE $DOCKER_BUILD_IMAGE-aarch64
- docker manifest push -p $DOCKER_LATEST_IMAGE
- docker manifest create --amend $DOCKER_BUILD_IMAGE_GITLAB $DOCKER_BUILD_IMAGE_GITLAB-aarch64 $DOCKER_BUILD_IMAGE_GITLAB-x86_64
- docker manifest annotate --os linux --arch amd64 $DOCKER_BUILD_IMAGE_GITLAB $DOCKER_BUILD_IMAGE_GITLAB-x86_64
- docker manifest annotate --os linux --arch arm64 $DOCKER_BUILD_IMAGE_GITLAB $DOCKER_BUILD_IMAGE_GITLAB-aarch64
- docker manifest push -p $DOCKER_BUILD_IMAGE_GITLAB
- docker manifest create --amend $DOCKER_LATEST_IMAGE_GITLAB $DOCKER_BUILD_IMAGE_GITLAB-aarch64 $DOCKER_BUILD_IMAGE_GITLAB-x86_64
- docker manifest annotate --os linux --arch amd64 $DOCKER_LATEST_IMAGE_GITLAB $DOCKER_BUILD_IMAGE_GITLAB-x86_64
- docker manifest annotate --os linux --arch arm64 $DOCKER_LATEST_IMAGE_GITLAB $DOCKER_BUILD_IMAGE_GITLAB-aarch64
- docker manifest push -p $DOCKER_LATEST_IMAGE_GITLAB
artifacts-sign:push:community:
stage: sign
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
when: never
- if: $CI_COMMIT_BRANCH
image:
name: registry.eulix.xyz/collab/infra/infrastructure/sigstore/cosign:v1.10.1
entrypoint: ['']
before_script:
- cosign login -u $GITLAB_DOCKER_AUTH_USERNAME -p $GITLAB_DOCKER_AUTH_PASSWORD $GITLAB_DOCKER_REGISTRY_HOST
- cosign login -u $DOCKER_AUTH_USERNAME -p $DOCKER_AUTH_PASSWORD $DOCKER_REGISTRY_HOST
- export DOCKER_BUILD_IMAGE=$DOCKER_REGISTRY_IMAGE/$ENV_CONTAINER_NAME:`head -1 VERSION`-alpha.$CI_PIPELINE_ID
- export DOCKER_LATEST_IMAGE=$DOCKER_REGISTRY_IMAGE/$ENV_CONTAINER_NAME:$CI_COMMIT_BRANCH
- export DOCKER_BUILD_IMAGE_GITLAB=$GITLAB_DOCKER_REGISTRY_IMAGE/$ENV_CONTAINER_NAME:`head -1 VERSION`-alpha.$CI_PIPELINE_ID
- export DOCKER_LATEST_IMAGE_GITLAB=$GITLAB_DOCKER_REGISTRY_IMAGE/$ENV_CONTAINER_NAME:$CI_COMMIT_BRANCH
- echo $COSIGN_KEY | base64 -d > /tmp/cosign.key
script:
- cosign sign --key /tmp/cosign.key $DOCKER_BUILD_IMAGE
- cosign sign --key /tmp/cosign.key $DOCKER_LATEST_IMAGE
- cosign sign --key /tmp/cosign.key $DOCKER_BUILD_IMAGE_GITLAB
- cosign sign --key /tmp/cosign.key $DOCKER_LATEST_IMAGE_GITLAB
artifacts-sign:merge_request:community:
stage: sign
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
when: never
- if: $CI_MERGE_REQUEST_ID
image:
name: registry.eulix.xyz/collab/infra/infrastructure/sigstore/cosign:v1.10.1
entrypoint: ['']
before_script:
- cosign login -u $GITLAB_DOCKER_AUTH_USERNAME -p $GITLAB_DOCKER_AUTH_PASSWORD $GITLAB_DOCKER_REGISTRY_HOST
- cosign login -u $DOCKER_AUTH_USERNAME -p $DOCKER_AUTH_PASSWORD $DOCKER_REGISTRY_HOST
- export DOCKER_BUILD_IMAGE=$DOCKER_REGISTRY_IMAGE/$ENV_CONTAINER_NAME:`head -1 VERSION`-alpha.$CI_PIPELINE_ID
- export DOCKER_LATEST_IMAGE=$DOCKER_REGISTRY_IMAGE/$ENV_CONTAINER_NAME:$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME
- export DOCKER_BUILD_IMAGE_GITLAB=$GITLAB_DOCKER_REGISTRY_IMAGE/$ENV_CONTAINER_NAME:`head -1 VERSION`-alpha.$CI_PIPELINE_ID
- export DOCKER_LATEST_IMAGE_GITLAB=$GITLAB_DOCKER_REGISTRY_IMAGE/$ENV_CONTAINER_NAME:$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME
- echo $COSIGN_KEY | base64 -d > /tmp/cosign.key
script:
- cosign sign --key /tmp/cosign.key $DOCKER_BUILD_IMAGE
- cosign sign --key /tmp/cosign.key $DOCKER_LATEST_IMAGE
- cosign sign --key /tmp/cosign.key $DOCKER_BUILD_IMAGE_GITLAB
- cosign sign --key /tmp/cosign.key $DOCKER_LATEST_IMAGE_GITLAB