-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy path.gitlab-ci.yml
252 lines (227 loc) · 5.97 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
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
stages:
- dump_db
- maintenance
- migrations
- release
- post_release
- build
- setup
- restore_db
- deploy
- deploy_provami
- cleanup
cache:
key: ${CI_MERGE_REQUEST_ID}
paths:
- .cache/pip
- venv/
variables:
GIT_CLONE_PATH: '$CI_BUILDS_DIR/$CI_PROJECT_NAME/$CI_COMMIT_BRANCH/$CI_MERGE_REQUEST_ID'
GIT_SSL_NO_VERIFY: '1'
build_containers:
stage: build
tags:
- staging
before_script:
- chown -R gitlab-runner:gitlab-runner /home/gitlab-runner
- docker-compose -f docker-compose-staging.yml ps
script:
- pwd
- docker build -t gaia:${CI_MERGE_REQUEST_ID} .
only:
- merge_requests
build_release_containers:
stage: build
tags:
- staging
script:
- pwd
- docker build -t gaia:release .
only:
- release
setup_pr:
stage: setup
tags:
- staging
script:
- echo $CI_MERGE_REQUEST_ID
- docker-compose -f docker-compose-staging.yml down -v
- sleep 30
- docker-compose -f docker-compose-staging.yml up -d db
after_script:
- docker-compose -f docker-compose-staging.yml ps
only:
- merge_requests
restore_db:
stage: restore_db
tags:
- staging
before_script:
- chown -R gitlab-runner:gitlab-runner /home/gitlab-runner
script:
- docker-compose -f docker-compose-staging.yml stop
- sleep 30
- ls -alh /opt/gaia_dumps
- docker-compose -f docker-compose-staging.yml up -d db
- docker-compose -f docker-compose-staging.yml ps
- sleep 30
- docker cp /opt/gaia_dumps/smalldump "$(docker-compose ps -q db)":/tmp/smalldump
- echo "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = 'jorvik';" | docker-compose -f docker-compose-staging.yml exec -T db psql -U postgres
- docker-compose -f docker-compose-staging.yml exec -T db pg_restore -C --clean --no-acl --no-owner -j 8 -U postgres -d postgres /tmp/smalldump
#- cat /opt/gaia_dumps/smalldump | docker-compose -f docker-compose-staging.yml exec -T db psql -U postgres -d jorvik
only:
- merge_requests
allow_failure: true
fire_pr:
stage: deploy
tags:
- staging
script:
- echo $CI_MERGE_REQUEST_ID
- env
- docker-compose -f docker-compose-staging.yml up -d
- sleep 10
- docker-compose -f docker-compose-staging.yml restart proxy
after_script:
- docker-compose -f docker-compose-staging.yml ps
environment:
name: pr$CI_MERGE_REQUEST_ID
url: https://pr$CI_MERGE_REQUEST_ID.staging.gaia.cri.it
on_stop: cleanup_pr
only:
- merge_requests
cleanup_pr:
stage: cleanup
tags:
- staging
script:
- echo $CI_MERGE_REQUEST_ID
- pwd
- export PR=$(echo $CI_MERGE_REQUEST_ID)
- docker stop ${PR}_web ${PR}_proxy ${PR}_redis_1 ${PR}_sentinel01_1 ${PR}_celery ${PR}_pdf ${PR}_db
- docker rm ${PR}_web ${PR}_proxy ${PR}_redis_1 ${PR}_sentinel01_1 ${PR}_celery ${PR}_pdf ${PR}_db
- docker network rm ${PR}_default
- docker rmi gaia:${PR} ${PR}_pdf:latest ${PR}_proxy:latest
- cd $CI_BUILDS_DIR
- rm -rf $CI_PROJECT_DIR.tmp
- rm -rf $CI_PROJECT_DIR
environment:
name: pr$CI_MERGE_REQUEST_ID
action: stop
only:
- merge_requests
when: manual
allow_failure: true
deploy_provami:
stage: deploy_provami
tags:
- staging
before_script:
- export CI_MERGE_REQUEST_ID=provami
script:
- docker-compose -f docker-compose-staging.yml -f docker-compose-provami.yml down -v
- docker-compose -f docker-compose-staging.yml -f docker-compose-provami.yml up -d
- sleep 600
- docker-compose -f docker-compose-staging.yml -f docker-compose-provami.yml exec -T web python scramble.py --dati-di-esempio
- docker-compose -f docker-compose-staging.yml -f docker-compose-provami.yml exec -T web python manage.py loaddata fixtures_data/formazione_titoli_cri_con_sigle.json
- docker-compose -f docker-compose-staging.yml -f docker-compose-provami.yml restart proxy
environment:
name: provami
url: https://provami.gaia.cri.it
only:
- "release"
dump_db:
stage: dump_db
script:
- echo "dump..."
only:
- release
when: manual
tags:
- gaia-app02,prod
.maintenance_template: &maintenance_definition
stage: maintenance
script:
- sudo service jorvik stop
- sudo service nginx stop
only:
- release
allow_failure: false
when: manual
stop_service_app02:
tags:
- gaia-app02,prod
<<: *maintenance_definition
stop_service_app03:
tags:
- gaia-app03,prod
<<: *maintenance_definition
stop_service_app04:
tags:
- gaia-app04,prod
<<: *maintenance_definition
migrate_db:
stage: migrations
before_script:
- whoami
- cd /home/appserver/jorvik
- git pull --rebase origin release
script:
- /home/appserver/venv/bin/python /home/appserver/jorvik/manage.py makemigrations
- /home/appserver/venv/bin/python /home/appserver/jorvik/manage.py migrate
- /home/appserver/venv/bin/python /home/appserver/jorvik/manage.py collectstatic --no-input
after_script:
- sudo service jorvik start
only:
- release
when: manual
tags:
- gaia-app02,prod
stop_celery:
stage: maintenance
before_script:
- cd /home/appserver/jorvik
script:
- sudo service celery stop
only:
- release
when: manual
tags:
- gaia-app02,prod
start_celery:
stage: post_release
before_script:
- cd /home/appserver/jorvik
script:
- sudo service celery start
only:
- release
when: manual
tags:
- gaia-app02,prod
.deploy_template: &deploy_definition
stage: release
before_script:
- cd /home/appserver/jorvik
- git status
script:
- git pull --rebase origin release
- /home/appserver/venv/bin/pip install -r /home/appserver/jorvik/requirements.txt
after_script:
- sudo service jorvik restart
- sudo service nginx restart
only:
- release
when: manual
release_app02:
tags:
- gaia-app02,prod
<<: *deploy_definition
release_app03:
tags:
- gaia-app03,prod
<<: *deploy_definition
release_app04:
tags:
- gaia-app04,prod
<<: *deploy_definition