-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
204 lines (191 loc) · 7.08 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
stages:
- test
- sonar
- build
- sign
- release
- deploy
variables:
CONTAINER_TEST_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
lint:code:
image: node:20
stage: test
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_COMMIT_MESSAGE =~ /^chore\(release\):/
when: never
- if: $CI_COMMIT_BRANCH == "main" && $CI_COMMIT_MESSAGE =~ /^chore\(release\):/
when: never
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
- if: $CI_COMMIT_BRANCH
script:
- npm ci
- npm run lint
test:
image: node:20
stage: test
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_COMMIT_MESSAGE =~ /^chore\(release\):/
when: never
- if: $CI_COMMIT_BRANCH == "main" && $CI_COMMIT_MESSAGE =~ /^chore\(release\):/
when: never
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
- if: $CI_COMMIT_BRANCH
script:
- npm install
- npm run test:unit
coverage: /All files[^|]*\|[^|]*\s+([\d\.]+)/
artifacts:
when: on_success
reports:
coverage_report:
coverage_format: cobertura
path: coverage/unit/cobertura-coverage.xml
paths:
- coverage/unit/lcov.info
integration-test:
image: node:20
stage: test
services:
- name: docker:dind
variables:
DOCKER_HOST: tcp://docker:2375
DOCKER_TLS_CERTDIR: ""
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_COMMIT_MESSAGE =~ /^chore\(release\):/
when: never
- if: $CI_COMMIT_BRANCH == "main" && $CI_COMMIT_MESSAGE =~ /^chore\(release\):/
when: never
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
- if: $CI_COMMIT_BRANCH
before_script:
- curl -fsSLO https://download.docker.com/linux/static/stable/x86_64/docker-20.10.9.tgz && tar xvzf docker-20.10.9.tgz --strip 1 -C /usr/local/bin docker/docker
script:
- npm install
- npm run test:integration
coverage: /All files[^|]*\|[^|]*\s+([\d\.]+)/
artifacts:
when: on_success
reports:
coverage_report:
coverage_format: cobertura
path: coverage/integration/cobertura-coverage.xml
paths:
- coverage/integration/lcov.info
sonarqube-check:
stage: sonar
image:
name: sonarsource/sonar-scanner-cli:latest
entrypoint: [""]
variables:
SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar" # Defines the location of the analysis task cache
GIT_DEPTH: "0" # Tells git to fetch all the branches of the project, required by the analysis task
cache:
key: "${CI_JOB_NAME}"
paths:
- .sonar/cache
script:
- sonar-scanner
allow_failure: true
only:
- development
build:
image: docker
id_tokens:
SIGSTORE_ID_TOKEN:
aud: sigstore
variables:
COSIGN_YES: "true"
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_COMMIT_MESSAGE =~ /^chore\(release\):/
when: never
- if: $CI_COMMIT_BRANCH == "main" && $CI_COMMIT_MESSAGE =~ /^chore\(release\):/
when: never
- if: $CI_COMMIT_BRANCH
services:
- docker:dind
stage: build
before_script:
- apk update && apk add curl
- curl -O -L "https://github.com/sigstore/cosign/releases/latest/download/cosign-linux-amd64"
- mv cosign-linux-amd64 /usr/local/bin/cosign
- chmod +x /usr/local/bin/cosign
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
script:
- docker build --pull -t $CONTAINER_TEST_IMAGE --target production-build-stage .
- docker push $CONTAINER_TEST_IMAGE
- IMAGE_DIGEST=$(docker inspect --format='{{index .RepoDigests 0}}' $CONTAINER_TEST_IMAGE)
- cosign sign $IMAGE_DIGEST
deploy-on-lab:
image: ubuntu
stage: deploy
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_COMMIT_MESSAGE =~ /^chore\(release\):/
when: never
- if: $CI_COMMIT_BRANCH == "main" && $CI_COMMIT_MESSAGE =~ /^chore\(release\):/
when: never
- if: $CI_COMMIT_BRANCH == "main" || $CI_COMMIT_BRANCH == "2206-unreleased" || $CI_COMMIT_BRANCH == "development"
before_script:
- apt update && apt install -y curl
- curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
script:
- helm upgrade --install -n "$CI_COMMIT_REF_SLUG" --create-namespace gx-compliance ./k8s/gx-compliance --set "nameOverride=$CI_COMMIT_REF_SLUG,ingress.hosts[0].host=compliance.lab.gaia-x.eu,ingress.hosts[0].paths[0].path=/$CI_COMMIT_REF_SLUG,image.tag=$CI_COMMIT_REF_SLUG,ingress.hosts[0].paths[0].pathType=Prefix,privateKey=$complianceKey,X509_CERTIFICATE=$complianceCert,production=false" --kubeconfig "$GXDCH_KUBECONFIG"
make-semantic-release:
image: node:18
stage: release
rules:
- if: $CI_COMMIT_BRANCH == "main" && $CI_COMMIT_MESSAGE =~ /^chore\(release\):/
when: never
- if: $CI_COMMIT_BRANCH == "main"
before_script:
- apt-get update -y && apt-get install -yqqf openssh-client git unzip sshpass rsync --fix-missing
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client git -y )'
- eval $(ssh-agent -s)
- echo "$CI_SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan gitlab.com >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
- git config --global user.email "[email protected]"
- git config --global user.name "semantic-release-bot"
script:
- npm i
- ./node_modules/.bin/semantic-release
# Tags build & deployment
build-release-tag-image:
image: docker
services:
- docker:dind
id_tokens:
SIGSTORE_ID_TOKEN:
aud: sigstore
variables:
COSIGN_YES: "true"
stage: build
before_script:
- apk update && apk add curl
- curl -O -L "https://github.com/sigstore/cosign/releases/latest/download/cosign-linux-amd64"
- mv cosign-linux-amd64 /usr/local/bin/cosign
- chmod +x /usr/local/bin/cosign
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
script:
- docker build --pull -t $CI_REGISTRY_IMAGE:${CI_COMMIT_TAG} --target production-build-stage . #vX.Y.Z tag
- docker push $CI_REGISTRY_IMAGE:${CI_COMMIT_TAG}
- docker tag $CI_REGISTRY_IMAGE:${CI_COMMIT_TAG} $CI_REGISTRY_IMAGE:${CI_COMMIT_TAG%.*} #vX.Y tag
- docker push $CI_REGISTRY_IMAGE:${CI_COMMIT_TAG%.*}
- docker tag $CI_REGISTRY_IMAGE:${CI_COMMIT_TAG} $CI_REGISTRY_IMAGE:${CI_COMMIT_TAG%%.*} #vX tag
- docker push $CI_REGISTRY_IMAGE:${CI_COMMIT_TAG%%.*}
- IMAGE_DIGEST=$(docker inspect --format='{{index .RepoDigests 0}}' $CI_REGISTRY_IMAGE:${CI_COMMIT_TAG})
- cosign sign $IMAGE_DIGEST
only:
- tags
deploy-tag-on-lab:
image: ubuntu
stage: deploy
when: manual
before_script:
- apt update && apt install -y curl
- curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
script:
- helm upgrade --install -n "${CI_COMMIT_TAG%%.*}" --create-namespace gx-compliance ./k8s/gx-compliance --set "nameOverride=${CI_COMMIT_TAG%%.*},ingress.hosts[0].host=compliance.lab.gaia-x.eu,ingress.hosts[0].paths[0].path=/${CI_COMMIT_TAG%%.*},image.tag=${CI_COMMIT_TAG%%.*},ingress.hosts[0].paths[0].pathType=Prefix,privateKey=$complianceKey,X509_CERTIFICATE=$complianceCert" --kubeconfig "$GXDCH_KUBECONFIG"
only:
- tags