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-ssh
133 lines (124 loc) · 4.06 KB
/
.gitlab-ci.yml.salt-ssh
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
stages:
- build
- push
- 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_cmd:
tags:
- __PROD_RUNNER__
stage: run_1
image: $CI_REGISTRY/$CI_PROJECT_PATH:master
rules:
- if: $SALT_CMD && $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
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:
tags:
- __PROD_RUNNER__
stage: run_1
image: $CI_REGISTRY/$CI_PROJECT_PATH:master
rules:
- if: $RSNAPSHOT_BACKUP_TYPE && $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
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:
tags:
- __PROD_RUNNER__
stage: run_2
image: $CI_REGISTRY/$CI_PROJECT_PATH:master
rules:
- 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:
- |
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:
tags:
- __PROD_RUNNER__
stage: run_3
image: $CI_REGISTRY/$CI_PROJECT_PATH:master
rules:
- if: $RSNAPSHOT_BACKUP_TYPE && $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
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:
tags:
- __PROD_RUNNER__
stage: run_4
image: $CI_REGISTRY/$CI_PROJECT_PATH:master
rules:
- if: $RSNAPSHOT_BACKUP_TYPE && $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
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:
tags:
- __PROD_RUNNER__
stage: run_5
image: $CI_REGISTRY/$CI_PROJECT_PATH:master
rules:
- if: $RSNAPSHOT_BACKUP_TYPE && $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
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