-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
171 lines (155 loc) · 4.1 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
variables:
MIRROR_REPO: git@github.com:thm-projects/arsnova.click-v2-backend.git
stages:
- test
- analyze
- build
- deploy
.build_template: &build_template
stage: build
services:
- name: docker:19.03.1-dind
alias: docker
variables:
DOCKER_TLS_CERTDIR: ""
tags:
- docker-compose
artifacts:
expire_in: 2 mins
paths:
- variables
- private_key
.docker_push_template: &docker_push |
docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
docker build -t $CI_IMAGE_NAME:$VERSION .
docker push "$CI_IMAGE_NAME:$VERSION"
.staging_server_env_template: &staging_server_env |
echo "export CI_CONTAINER_INSTANCE_NAME=$CI_CONTAINER_INSTANCE_NAME" >> variables
echo "export SSH_URL=$STAGING_BACKEND_URL" >> variables
echo "export SSH_CMD=$STAGING_SSH" >> variables
echo "export VERSION=$VERSION" >> variables
echo "export SERVICE_NAME=$SERVICE_NAME" >> variables
echo "$STAGING_SSH_PRIVATE_KEY" >> private_key
.production_server_env_template: &production_server_env |
echo "export CI_CONTAINER_INSTANCE_NAME=$CI_CONTAINER_INSTANCE_NAME" >> variables
echo "export SSH_URL=$PRODUCTION_BACKEND_URL" >> variables
echo "export SSH_CMD=$PRODUCTION_SSH" >> variables
echo "export VERSION=$VERSION" >> variables
echo "export SERVICE_NAME=$SERVICE_NAME" >> variables
echo "$PRODUCTION_SSH_PRIVATE_KEY" >> private_key
.server_deploy_template: &server_deploy |
source variables
eval $(ssh-agent -s)
mkdir ~/.ssh
ssh-keyscan "$SSH_URL" >> ~/.ssh/known_hosts
ssh-add <(cat private_key)
build_master:
<<: *build_template
only:
- master
environment:
name: Master
variables:
VERSION: 2.0.0
SERVICE_NAME: master
CI_CONTAINER_INSTANCE_NAME: arsnova-click-backend-master
script:
- *production_server_env
- *docker_push
build_staging:
<<: *build_template
only:
- staging
environment:
name: Staging
variables:
VERSION: 2.0.0-staging
SERVICE_NAME: staging
CI_CONTAINER_INSTANCE_NAME: arsnova-click-backend-staging
script:
- *staging_server_env
- *docker_push
build_beta:
<<: *build_template
only:
- beta
environment:
name: Beta
variables:
VERSION: 2.0.0-beta
SERVICE_NAME: beta
CI_CONTAINER_INSTANCE_NAME: arsnova-click-backend-beta
script:
- *staging_server_env
- *docker_push
ts_lint:
stage: test
tags:
- nodejs
script:
- npm install tslint@6.0.0 typescript@3.7.5
- node_modules/tslint/bin/tslint -c tslint.json -p tsconfig.json
i18n_check:
stage: test
tags:
- meteor
script:
- node i18n-check.js
npm_test:
stage: test
tags:
- nodejs
artifacts:
paths:
- .lcov_output
script:
- npm install
- export NODE_ENV='test'
- node_modules/nyc/bin/nyc.js --reporter=text --reporter=lcov --report-dir=.lcov_output node_modules/mocha/bin/mocha
sonarqube:
stage: analyze
tags:
- sonar-cli
dependencies:
- npm_test
only:
- staging
script:
- npm i
- sonar-scanner -Dsonar.login=$SONAR_TOKEN -Dsonar.host.url=https://scm.thm.de/sonar/
deploy:
stage: deploy
only:
- staging
- beta
tags:
- ssh
script:
- *server_deploy
- ssh $SSH_CMD "docker pull $CI_IMAGE_NAME:$VERSION && docker rm -f $CI_CONTAINER_INSTANCE_NAME ; docker-compose -f /home/arsnova/arsnova-click-docker/docker-compose-backend.yml -p arsnova-click-backend up --no-deps -d $SERVICE_NAME && docker image prune -af"
deploy_master:
stage: deploy
only:
- master
tags:
- ssh
script:
- *server_deploy
- ssh $SSH_CMD "docker pull $CI_IMAGE_NAME:$VERSION && docker rm -f $CI_CONTAINER_INSTANCE_NAME ; docker-compose -f /root/docker-compose.yml up --no-deps -d backend && docker image prune -af"
sync_mirror:
stage: deploy
tags:
- git
when: always
allow_failure: true
dependencies: []
only:
- master
- staging
script:
- eval $(ssh-agent -s)
- mkdir ~/.ssh && echo "$SYNC_SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
- ssh-add <(echo "$SYNC_SSH_PRIVATE_KEY")
- git clone --bare "$CI_REPOSITORY_URL" mirror.git
- cd mirror.git
- git push --mirror "$MIRROR_REPO"