-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
171 lines (155 loc) · 4.18 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
default:
image: gitlab.virtualcitysystems.de:5050/vcsuite/devops/gitlabrunner/node:20-bullseye
variables:
GIT_CLONE_PATH: $CI_BUILDS_DIR/$CI_PROJECT_PATH_SLUG/$CI_COMMIT_REF_SLUG
stages:
- build
- test
- bundle
- deploy
- version
- publish
- deployCluster
.template: &job_definition
only:
- /^(feature-.*|hotfix-.*|main|release-.*)$/
tags:
- linux-2.0
build:
<<: *job_definition
script:
- npm ci
before_script:
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo "$SSH_RUNNER_KEY" | tr -d '\r' > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
- ssh-keyscan gitlab.virtualcitysystems.de >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
- git config user.name "Gitlab Runner"
- git config user.email "[email protected]"
stage: build
.after_build_template: &after_build_definition
<<: *job_definition
variables:
GIT_STRATEGY: none
.staging_build_template: &staging_build_template
<<: *after_build_definition
except:
variables:
- $PUBLISH
lint:
<<: *after_build_definition
stage: test
script:
- npm run lint
test:
<<: *after_build_definition
stage: test
script:
- npm run coverage -- --reporter junit --outputFile test-report.xml
coverage: '/^Statements\s*:\s*([^%]+)/'
artifacts:
reports:
junit: test-report.xml
audit:
<<: *after_build_definition
stage: test
script:
- npm audit --production --audit-level=low
buildPreview:
<<: *staging_build_template
stage: bundle
script:
- npm run buildStagingApp
bundle:
<<: *after_build_definition
stage: bundle
only:
variables:
- $PUBLISH
refs:
- /^(main|release-v.*)$/
script:
- npm run build
deployStaging:
<<: *staging_build_template
stage: deploy
environment:
name: staging/$CI_COMMIT_REF_SLUG
url: http://$CI_PROJECT_PATH_SLUG-$CI_COMMIT_REF_SLUG.stagingcluster.intern.virtualcitysystems.de
on_stop: stopEnvironment
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: ['']
script:
- /kaniko/executor --context dist/ --dockerfile build/staging/Dockerfile --destination $CI_REGISTRY_IMAGE/staging:$CI_COMMIT_REF_SLUG
before_script:
- mkdir -p /kaniko/.docker
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
stopEnvironment:
stage: deploy
variables:
GIT_STRATEGY: none
image:
name: bitnami/kubectl:latest
entrypoint: ['']
tags:
- linux-2.0
script:
- echo "Stop environment staging/$CI_COMMIT_REF_NAME"
- echo "Delete namespace on k9s $CI_PROJECT_PATH_SLUG-$CI_COMMIT_REF_SLUG"
- kubectl config use-context vcsuite/cluster-management:agent
- kubectl delete namespace $CI_PROJECT_PATH_SLUG-$CI_COMMIT_REF_SLUG
when: manual
environment:
name: staging/$CI_COMMIT_REF_SLUG
action: stop
deployStagingCluster:
stage: deployCluster
except:
variables:
- $PUBLISH
inherit:
variables: false
variables:
STAGE_BRANCH: $CI_COMMIT_REF_SLUG
STAGE_PROJECT_NAME: $CI_PROJECT_PATH_SLUG
STAGE_REGISTRY_IMAGE: $CI_REGISTRY_IMAGE
STAGE_NAMESPACE: $CI_PROJECT_PATH_SLUG-$CI_COMMIT_REF_SLUG
trigger:
project: vcsuite/devops/manifests
branch: main
version:
<<: *after_build_definition
stage: version
only:
variables:
- $PUBLISH
refs:
- /^(main|release-v.*)$/
script:
- npm version patch -m "%s [skip-ci]"
- TAG=`git describe --abbrev=0`
- git push git@gitlab:"$CI_PROJECT_PATH".git $TAG
- git push git@gitlab:"$CI_PROJECT_PATH".git HEAD:$CI_COMMIT_REF_NAME
before_script:
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo "$SSH_RUNNER_KEY" | tr -d '\r' > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
- ssh-keyscan gitlab >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
- git config user.name "Gitlab Runner"
- git config user.email "[email protected]"
publish:
<<: *after_build_definition
stage: publish
only:
refs:
- /^(main|release-v.*)$/
variables:
- $PUBLISH
script:
- npm config set '//registry.npmjs.org/:_authToken' "${NPM_TOKEN}"
- npm publish --registry https://registry.npmjs.org --access public