-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
231 lines (218 loc) · 8.42 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
# Copyright 2020-2022 i3-MARKET Consortium:
#
# ATHENS UNIVERSITY OF ECONOMICS AND BUSINESS - RESEARCH CENTER
# ATOS SPAIN SA
# EUROPEAN DIGITAL SME ALLIANCE
# GFT ITALIA SRL
# GUARDTIME OU
# HOP UBIQUITOUS SL
# IBM RESEARCH GMBH
# IDEMIA FRANCE
# SIEMENS AKTIENGESELLSCHAFT
# SIEMENS SRL
# TELESTO TECHNOLOGIES PLIROFORIKIS KAI EPIKOINONION EPE
# UNIVERSITAT POLITECNICA DE CATALUNYA
# UNPARALLEL INNOVATION LDA
#
# 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.
#
stages:
- gather
- integrate
- test
- publish
- deploy
- confidence-check
variables:
DOCKER_TLS_CERTDIR: "/certs"
DOCKER_BUILDKIT: 1
LOOPBACK_CLI_VERSION: "3.1.0"
SCHEMATHESIS_VERSION: "3.17.2"
INTEGRATOR_URL: "${CI_API_V4_URL}/projects/21002959/packages/generic/integrator/${INTEGRATOR_VERSION}/bulk_integrator"
OAS_REPO_URL: "https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com/i3-market/code/wp4/backplane-subsystems-oas.git"
ANSIBLE_BACKPLANE_JOB_URL: "http://${I3_MARKET_NODE_2}:19000/api/v2/job_templates/13/launch/"
ANSIBLE_SDK_JOB_URL: "http://${I3_MARKET_NODE_2}:19000/api/v2/job_templates/24/launch/"
DISABLE_TRIVY_STEP: "false"
workflow:
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event" #Don't run on detached merge requests pipelines
when: never
- when: always
get-integrator:
stage: gather
image: curlimages/curl:latest
script:
- 'curl --request GET --header "JOB-TOKEN: $CI_JOB_TOKEN" "${INTEGRATOR_URL}" --output bulk_integrator'
- chmod +x ./bulk_integrator
artifacts:
paths:
- bulk_integrator
expire_in: 10 mins
get-subsystems-oas:
stage: gather
variables:
OAS_COMMIT_REF: master
script:
- echo "get data from ${OAS_COMMIT_REF}"
- git clone -b $OAS_COMMIT_REF $OAS_REPO_URL ./specs
artifacts:
paths:
- specs/
exclude:
- specs/.gitlab-ci.yml
- specs/.git
- spect/README.md
expire_in: 10 mins
integrate-subsystems:
stage: integrate
image: node:16.14-bullseye-slim
script:
- npm i -g @loopback/cli@$LOOPBACK_CLI_VERSION
- ./bulk_integrator . ./specs
artifacts:
untracked: true
paths:
- src/controllers/index.ts
- src/datasources/index.ts
- src/models/index.ts
- src/repositories/index.ts
- src/services/index.ts
expire_in: 10 mins
publish-docker:
stage: publish
image:
name: docker:20.10.17
variables:
NEXUS_REGISTRY: $I3_MARKET_NODE_4:8123
NEXUS_BASE_IMAGE_TAG: $NEXUS_REGISTRY/backplane
GITLAB_BASE_IMAGE_TAG: $CI_REGISTRY_IMAGE
services:
- name: docker:20.10.17-dind
entrypoint: ["sh", "-c", "dockerd-entrypoint.sh --insecure-registry=$NEXUS_REGISTRY"]
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker login -u $NEXUS_USER -p $NEXUS_PASSWORD $NEXUS_REGISTRY
script:
- docker buildx build --target=base -t ${NEXUS_BASE_IMAGE_TAG}:latest -t ${NEXUS_BASE_IMAGE_TAG}:${CI_COMMIT_TAG} -t ${GITLAB_BASE_IMAGE_TAG}:latest -t ${GITLAB_BASE_IMAGE_TAG}:${CI_COMMIT_TAG} .
- docker buildx build --target=with-integrator --build-arg INTEGRATOR_VERSION=${INTEGRATOR_VERSION} --secret id=GITLAB_USER --secret id=GITLAB_TOKEN -t ${NEXUS_BASE_IMAGE_TAG}:latest-with-integrator -t ${NEXUS_BASE_IMAGE_TAG}:${CI_COMMIT_TAG}-with-integrator -t ${GITLAB_BASE_IMAGE_TAG}:latest-with-integrator -t ${GITLAB_BASE_IMAGE_TAG}:${CI_COMMIT_TAG}-with-integrator .
# Push to Gitlab
- docker push --all-tags ${GITLAB_BASE_IMAGE_TAG}
# Push to Nexus
- docker push --all-tags ${NEXUS_BASE_IMAGE_TAG}
rules: #only run on release tags and protected
- if: $CI_COMMIT_TAG =~ /[0-9]+\.[0-9]+\.[0-9]+/ && $CI_COMMIT_REF_PROTECTED
integration-test:
stage: test
image:
name: node:16.14-bullseye
before_script:
- export $(cat $ENV_FILE_TEST | xargs)
- npm install
- apt-get -y update && apt-get -y install python3 python3-pip
- python3 -m pip install schemathesis==$SCHEMATHESIS_VERSION httpx
- npm start > ./startup_log.txt &
- sleep 20
- cat startup_log.txt
script:
- |
schemathesis run http://localhost:3000/openapi.json -H "id_token:test" -H "access_token: test" \
-E ^/greeter --validate-schema=false --hypothesis-max-examples=1 --hypothesis-derandomize \
-c not_a_server_error
cache:
key: $CI_COMMIT_REF_SLUG
paths:
- .hypothesis
artifacts:
paths:
- ./startup_log.txt
allow_failure: false
image-analysis-trivy:
stage: test
needs: ['integrate-subsystems']
image: docker:20.10.17
services:
- name: docker:20.10.17-dind
entrypoint: ["sh", "-c", "dockerd-entrypoint.sh"]
variables:
IMAGE: trivy-ci-test:$CI_COMMIT_SHA
before_script:
- apk update --no-cache && apk add --no-cache curl
- export TRIVY_VERSION=$(curl --retry 10 -sL "https://api.github.com/repos/aquasecurity/trivy/releases/latest" | grep '"tag_name":' | sed -E 's/.*"v([^"]+)".*/\1/')
- echo $TRIVY_VERSION
- curl --retry 10 -sL https://github.com/aquasecurity/trivy/releases/download/v${TRIVY_VERSION}/trivy_${TRIVY_VERSION}_Linux-64bit.tar.gz | tar -zxvf -
# ignore gobinary trivy during build
- echo "trivy" > .dockerignore
allow_failure: false
script:
# Build image
- docker buildx build --target=base -t $IMAGE .
# Build report
- ./trivy --cache-dir .trivycache/ image --exit-code 0 --no-progress --format template --severity HIGH,CRITICAL --template "@contrib/gitlab-codequality.tpl" -o gl-codeclimate.json $IMAGE
# Print report
- ./trivy --cache-dir .trivycache/ image --exit-code 0 --no-progress --severity HIGH,CRITICAL $IMAGE
# Fail on critical vulnerabilities
- ./trivy --cache-dir .trivycache/ image --exit-code 1 --severity CRITICAL --ignore-unfixed --no-progress $IMAGE
rules:
- if: $DISABLE_TRIVY_STEP == "true"
when: never
allow_failure: true
- if: $DISABLE_TRIVY_STEP != "true" #always true
cache:
paths:
- .trivycache/
# Enables https://docs.gitlab.com/ee/user/application_security/container_scanning/ (Container Scanning report is available on GitLab EE Ultimate or GitLab.com Gold)
artifacts:
paths:
- gl-codeclimate.json
reports:
codequality: gl-codeclimate.json # Currently it generates an unescaped json fixed here https://github.com/aquasecurity/trivy/commit/e618d83dae653eb78b4c03d097b69ed94fd56dce
# Gitlab CI currently doesn't support adding more than one codequality report. But you can join them using jq
# jq -s 'add' prev-codeclimate.json trivy-codeclimate.json > gl-codeclimate.json
check-deployment:
stage: confidence-check
image:
name: python:3.10-bullseye
before_script:
- python3 -m pip install schemathesis==$SCHEMATHESIS_VERSION httpx
script:
- |
schemathesis run http://${I3_MARKET_NODE_1}:3000/openapi.json -H "id_token:test" -H "access_token: test" \
-E ^/greeter --validate-schema=false --hypothesis-max-examples=1 --hypothesis-derandomize \
-c not_a_server_error
cache:
key: $CI_COMMIT_REF_SLUG
paths:
- .hypothesis
rules: #only run on release tags and protected
- if: $CI_COMMIT_TAG =~ /[0-9]+\.[0-9]+\.[0-9]+/ && $CI_COMMIT_REF_PROTECTED
when: delayed
start_in: 5 minutes
deploy-ansible-backplane:
stage: deploy
script:
- 'curl --request POST --header "Authorization: Bearer $ANSIBLE_DEPLOY_TOKEN" "$ANSIBLE_BACKPLANE_JOB_URL"'
rules: #only run on release tags
- if: $CI_COMMIT_TAG =~ /[0-9]+\.[0-9]+\.[0-9]+/ && $CI_COMMIT_REF_PROTECTED
deploy-ansible-sdk:
stage: deploy
script:
- 'curl --request POST --header "Authorization: Bearer $ANSIBLE_DEPLOY_TOKEN" "$ANSIBLE_SDK_JOB_URL"'
rules: #only run on release tags
- if: $CI_COMMIT_TAG =~ /[0-9]+\.[0-9]+\.[0-9]+/ && $CI_COMMIT_REF_PROTECTED
deploy-backplane-docs:
stage: deploy
trigger:
project: i3-market/code/backplane/backplane-api-gateway/backplane-api-specification
branch: master
rules: #only run on release tags
- if: $CI_COMMIT_TAG =~ /[0-9]+\.[0-9]+\.[0-9]+/ && $CI_COMMIT_REF_PROTECTED