forked from microdevops-com/salt-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml.salt
351 lines (315 loc) · 9.61 KB
/
.gitlab-ci.yml.salt
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
stages:
- build
- push
- pull
- count
- refresh
- run_1
- run_2
- run_3
- run_4
- run_5
variables:
GIT_STRATEGY: none
GIT_SUBMODULE_STRATEGY: none
build:
tags:
- __DEV_RUNNER__
stage: build
variables:
GIT_STRATEGY: fetch
GIT_SUBMODULE_STRATEGY: normal
rules:
- if: $SALT_CMD || $RSNAPSHOT_BACKUP_TYPE
when: never
- if: $CI_COMMIT_TAG
when: never
- if: $CI_COMMIT_REF_NAME
script:
- echo IMAGE $CI_PROJECT_PATH:$CI_PIPELINE_ID
- docker build --pull --tag $CI_PROJECT_PATH:$CI_PIPELINE_ID --build-arg SALT_VERSION=__SALT_VERSION__ .
- docker run --rm $CI_PROJECT_PATH:$CI_PIPELINE_ID -- /.check_pillar_for_roster.sh
push:
tags:
- __DEV_RUNNER__
stage: push
rules:
- if: $SALT_CMD || $RSNAPSHOT_BACKUP_TYPE
when: never
- if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
script:
- echo IMAGE $CI_PROJECT_PATH:$CI_PIPELINE_ID "->" $CI_REGISTRY/$CI_PROJECT_PATH:$CI_COMMIT_REF_SLUG
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker tag $CI_PROJECT_PATH:$CI_PIPELINE_ID $CI_REGISTRY/$CI_PROJECT_PATH:$CI_COMMIT_REF_SLUG
- docker push $CI_REGISTRY/$CI_PROJECT_PATH:$CI_COMMIT_REF_SLUG
.salt_master_pull:
stage: pull
rules:
- if: $SALT_CMD || $RSNAPSHOT_BACKUP_TYPE
when: never
- if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
script:
- sudo /srv/scripts/ci_sudo/salt_master_pull.sh
salt_master_pull_1:
extends: .salt_master_pull
tags:
- __SALT_MASTER_1_NAME__
salt_master_pull_2:
extends: .salt_master_pull
tags:
- __SALT_MASTER_2_NAME__
.count_alive_minions:
stage: count
rules:
- if: $SALT_SSH_IN_SALT == "true"
when: never
- if: $SALT_MINION && $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
artifacts:
paths:
- alive_minions
script:
- /srv/.gitlab-server-job/count_alive_minions.sh
after_script:
- /srv/.gitlab-server-job/send_notify_devilry.sh
count_alive_minions_1:
extends: .count_alive_minions
tags:
- __SALT_MASTER_1_NAME__
count_alive_minions_2:
extends: .count_alive_minions
tags:
- __SALT_MASTER_2_NAME__
.refresh_pillar:
stage: refresh
rules:
- if: $SALT_SSH_IN_SALT == "true"
when: never
- if: $SALT_MINION && $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
script:
- /srv/.gitlab-server-job/check_alive_minions.sh
- /srv/.gitlab-server-job/refresh_pillar.sh
after_script:
- /srv/.gitlab-server-job/send_notify_devilry.sh
- rm -rf alive_minions
refresh_pillar_1:
extends: .refresh_pillar
tags:
- __SALT_MASTER_1_NAME__
refresh_pillar_2:
extends: .refresh_pillar
tags:
- __SALT_MASTER_2_NAME__
.salt_cmd:
stage: run_1
rules:
- if: $SALT_SSH_IN_SALT == "true"
when: never
- if: $SALT_CMD && $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
script:
- /srv/.gitlab-server-job/check_alive_minions.sh
- /srv/.gitlab-server-job/salt_cmd.sh
after_script:
- /srv/.gitlab-server-job/send_notify_devilry.sh
- rm -rf alive_minions
salt_cmd_1:
extends: .salt_cmd
tags:
- __SALT_MASTER_1_NAME__
salt_cmd_2:
extends: .salt_cmd
tags:
- __SALT_MASTER_2_NAME__
salt_cmd:
tags:
- salt-ssh
stage: run_1
image: $CI_REGISTRY/$CI_PROJECT_PATH:master
rules:
- if: $SALT_CMD && $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH && $SALT_SSH_IN_SALT == "true"
script:
- /srv/scripts/salt-ssh/salt_cmd.sh "${SALT_MINION}" "${SALT_CMD}"
after_script:
- /srv/scripts/salt-ssh/send_notify_devilry.sh
.rsnapshot_backup_update_config:
stage: run_1
rules:
- if: $SALT_SSH_IN_SALT == "true"
when: never
- if: $RSNAPSHOT_BACKUP_TYPE && $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
script:
- /srv/.gitlab-server-job/check_alive_minions.sh
- /srv/.gitlab-server-job/rsnapshot_backup_update_config.sh
after_script:
- /srv/.gitlab-server-job/send_notify_devilry.sh
- rm -rf alive_minions
rsnapshot_backup_update_config_1:
extends: .rsnapshot_backup_update_config
tags:
- __SALT_MASTER_1_NAME__
rsnapshot_backup_update_config_2:
extends: .rsnapshot_backup_update_config
tags:
- __SALT_MASTER_2_NAME__
rsnapshot_backup_update_config:
tags:
- salt-ssh
stage: run_1
image: $CI_REGISTRY/$CI_PROJECT_PATH:master
rules:
- if: $RSNAPSHOT_BACKUP_TYPE && $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH && $SALT_SSH_IN_SALT == "true"
script:
- /srv/scripts/salt-ssh/rsnapshot_backup_update_config.sh "${SALT_MINION}"
after_script:
- /srv/scripts/salt-ssh/send_notify_devilry.sh
.rsnapshot_backup_sync:
stage: run_2
rules:
- if: $SALT_SSH_IN_SALT == "true"
when: never
- if: $RSNAPSHOT_BACKUP_TYPE && $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
artifacts:
paths:
- rsnapshot_backup_sync_status
when: always
allow_failure: True # Even if sync fails, go to rotation, status for alerting is sent as artifact
script:
- /srv/.gitlab-server-job/check_alive_minions.sh
- /srv/.gitlab-server-job/rsnapshot_backup_sync.sh
after_script:
- /srv/.gitlab-server-job/send_notify_devilry.sh
- rm -rf alive_minions
rsnapshot_backup_sync_1:
extends: .rsnapshot_backup_sync
tags:
- __SALT_MASTER_1_NAME__
rsnapshot_backup_sync_2:
extends: .rsnapshot_backup_sync
tags:
- __SALT_MASTER_2_NAME__
rsnapshot_backup_sync:
tags:
- salt-ssh
stage: run_2
image: $CI_REGISTRY/$CI_PROJECT_PATH:master
rules:
- if: $RSNAPSHOT_BACKUP_TYPE && $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH && $SALT_SSH_IN_SALT == "true"
artifacts:
paths:
- rsnapshot_backup_sync_status
when: always
allow_failure: True # Even if sync fails, go to rotation, status for alerting is sent as artifact
script:
- |
if /srv/scripts/salt-ssh/rsnapshot_backup_sync.sh "${SALT_MINION}" "${RSNAPSHOT_BACKUP_TYPE}" "${SSH_HOST}" "${SSH_PORT}" "${SSH_JUMP}"; then
echo "export RSNAPSHOT_BACKUP_SYNC=success" > rsnapshot_backup_sync_status
else
echo "export RSNAPSHOT_BACKUP_SYNC=failed" > rsnapshot_backup_sync_status
false
fi
after_script:
- /srv/scripts/salt-ssh/send_notify_devilry.sh
.rsnapshot_backup_rotate:
stage: run_3
rules:
- if: $SALT_SSH_IN_SALT == "true"
when: never
- if: $RSNAPSHOT_BACKUP_TYPE && $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
script:
- /srv/.gitlab-server-job/check_alive_minions.sh
- /srv/.gitlab-server-job/rsnapshot_backup_rotate.sh
after_script:
- . rsnapshot_backup_sync_status
- /srv/.gitlab-server-job/send_notify_devilry.sh
- rm -rf alive_minions
- rm -f rsnapshot_backup_sync_status
rsnapshot_backup_rotate_1:
extends: .rsnapshot_backup_rotate
tags:
- __SALT_MASTER_1_NAME__
rsnapshot_backup_rotate_2:
extends: .rsnapshot_backup_rotate
tags:
- __SALT_MASTER_2_NAME__
rsnapshot_backup_rotate:
tags:
- salt-ssh
stage: run_3
image: $CI_REGISTRY/$CI_PROJECT_PATH:master
rules:
- if: $RSNAPSHOT_BACKUP_TYPE && $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH && $SALT_SSH_IN_SALT == "true"
script:
- /srv/scripts/salt-ssh/rsnapshot_backup_rotate.sh "${SALT_MINION}" "${RSNAPSHOT_BACKUP_TYPE}" "${SSH_HOST}" "${SSH_PORT}" "${SSH_JUMP}"
after_script:
- . rsnapshot_backup_sync_status
- /srv/scripts/salt-ssh/send_notify_devilry.sh
- rm -f rsnapshot_backup_sync_status
.rsnapshot_backup_check_backup:
stage: run_4
rules:
- if: $SALT_SSH_IN_SALT == "true"
when: never
- if: $RSNAPSHOT_BACKUP_TYPE && $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
script:
- /srv/.gitlab-server-job/check_alive_minions.sh
- /srv/.gitlab-server-job/rsnapshot_backup_check_backup.sh
after_script:
- . rsnapshot_backup_sync_status
- /srv/.gitlab-server-job/send_notify_devilry.sh
- rm -rf alive_minions
- rm -f rsnapshot_backup_sync_status
rsnapshot_backup_check_backup_1:
extends: .rsnapshot_backup_check_backup
tags:
- __SALT_MASTER_1_NAME__
rsnapshot_backup_check_backup_2:
extends: .rsnapshot_backup_check_backup
tags:
- __SALT_MASTER_2_NAME__
rsnapshot_backup_check_backup:
tags:
- salt-ssh
stage: run_4
image: $CI_REGISTRY/$CI_PROJECT_PATH:master
rules:
- if: $RSNAPSHOT_BACKUP_TYPE && $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH && $SALT_SSH_IN_SALT == "true"
script:
- /srv/scripts/salt-ssh/rsnapshot_backup_check_backup.sh "${SALT_MINION}" "${RSNAPSHOT_BACKUP_TYPE}" "${SSH_HOST}" "${SSH_PORT}" "${SSH_JUMP}"
after_script:
- . rsnapshot_backup_sync_status
- /srv/scripts/salt-ssh/send_notify_devilry.sh
- rm -f rsnapshot_backup_sync_status
.rsnapshot_backup_check_coverage:
stage: run_5
rules:
- if: $SALT_SSH_IN_SALT == "true"
when: never
- if: $RSNAPSHOT_BACKUP_TYPE && $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
script:
- /srv/.gitlab-server-job/check_alive_minions.sh
- /srv/.gitlab-server-job/rsnapshot_backup_check_coverage.sh
after_script:
- . rsnapshot_backup_sync_status
- /srv/.gitlab-server-job/send_notify_devilry.sh
- rm -rf alive_minions
- rm -f rsnapshot_backup_sync_status
rsnapshot_backup_check_coverage_1:
extends: .rsnapshot_backup_check_coverage
tags:
- __SALT_MASTER_1_NAME__
rsnapshot_backup_check_coverage_2:
extends: .rsnapshot_backup_check_coverage
tags:
- __SALT_MASTER_2_NAME__
rsnapshot_backup_check_coverage:
tags:
- salt-ssh
stage: run_5
image: $CI_REGISTRY/$CI_PROJECT_PATH:master
rules:
- if: $RSNAPSHOT_BACKUP_TYPE && $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH && $SALT_SSH_IN_SALT == "true"
script:
- /srv/scripts/salt-ssh/rsnapshot_backup_check_coverage.sh "${SALT_MINION}"
after_script:
- . rsnapshot_backup_sync_status
- /srv/scripts/salt-ssh/send_notify_devilry.sh
- rm -f rsnapshot_backup_sync_status