forked from alejandrozf/ominicontacto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
269 lines (253 loc) · 9.3 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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# Copyright (C) 2018 Freetech Solutions
# This file is part of OMniLeads
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
#
# Official framework image. Look for the different tagged releases at:
# https://hub.docker.com/r/library/python
stages:
- test
- build
- deploy
test:
stage: test
image: alejandrozf/docker-stuff:python-flake8
# Pick zero or more services to be used on all builds.
# Only needed when using a docker container to run your tests in.
# Check out: http://docs.gitlab.com/ce/ci/docker/using_docker_images.html#what-is-a-service
services:
- name: alejandrozf/docker-stuff:postgres-plpython-template1
alias: plpython
- redis
# This folder is cached between builds
# http://docs.gitlab.com/ce/ci/yaml/README.html#cache
cache:
paths:
- /root/.cache/pip/
before_script:
- mkdir -p /opt/omnileads/ominicontacto/
- touch /opt/omnileads/ominicontacto/django.log
- mkdir -p /opt/omnileads/static
- mkdir -p /opt/omnileads/media_root
# FIXME: what follows is a hack to simulate we have the 'sox' program, we should have the real program
# as a docker image or installed by this script
- touch sox
- chmod +x sox
- mv sox /usr/bin/
- pip install -r requirements/tests.txt
variables:
POSTGRES_DB: omnileads
POSTGRES_USER: omnileads
POSTGRES_PASSWORD: omnileadsrw
DATABASE_URL: "postgresql://postgres:postgres@postgres:5432/$POSTGRES_DB"
DJANGO_SETTINGS_MODULE: "ominicontacto.settings.gitlab"
script:
- python checks.py
- bash check-js.sh
- flake8
- python manage.py test --failfast
- python manage.py compilemessages
only:
- merge_requests
- /^pre-release-.*$/
- schedules
- web
docker-prodenv-build-push:
stage: build
script:
- bash /home/ftsinfra/git_cleanup.sh
- cd /home/ftsinfra/ominicontacto/deploy/vagrant
- python edit_ansible.py -tag=$CI_COMMIT_REF_NAME -dlu=$DOCKER_LOGIN_USER -dle=$DOCKER_LOGIN_EMAIL -dlp=$DOCKER_LOGIN_PASSWORD
- cd /home/ftsinfra/ominicontacto/deploy/ansible
- echo "$FTSINFRA_PASS" | sudo -S ./deploy.sh --docker-build
tags:
- build-docker
only:
- /.*docker-build.*$/
- /^pre-release-.*$/
- /^release-.*$/
- schedules
- web
staging-centos:
stage: build
script:
- export CI_COMMIT_REF_NAME=$CI_COMMIT_REF_NAME
- bash /home/ftsinfra/git_cleanup.sh
- cd /home/ftsinfra/ominicontacto/deploy/vagrant/host_node/
- vagrant halt centos
- vagrant destroy centos -f
- ./vagrantup.sh centos
- python ../edit_ansible.py --internal_ip=$STAGING_IP_CENTOS --self_hosted=no --admin_pass=$DJANGO_PASS --databases_pass=$DATABASES_PASS
- cd ../../ansible
- echo "$FTSINFRA_PASS" | sudo -S IS_CICD=$IS_CICD ./deploy.sh --integration-tests
- cd /home/ftsinfra/ominicontacto/deploy/vagrant/host_node/
- vagrant halt centos
tags:
- build-aio
only:
- /.*ansible-hostnode.*$/
- /^pre-release-.*$/
- schedules
- web
staging-ubuntu:
stage: build
script:
- export CI_COMMIT_REF_NAME=$CI_COMMIT_REF_NAME
- bash /home/ftsinfra/git_cleanup.sh
- cd /home/ftsinfra/ominicontacto/deploy/vagrant/host_node/
- vagrant halt ubuntu
- vagrant destroy ubuntu -f
- ./vagrantup.sh ubuntu
- python ../edit_ansible.py --internal_ip=$STAGING_IP_UBUNTU --self_hosted=no --admin_pass=$DJANGO_PASS --databases_pass=$DATABASES_PASS
- cd ../../ansible
- echo "$FTSINFRA_PASS" | sudo -S IS_CICD=$IS_CICD ./deploy.sh --integration-tests
- cd /home/ftsinfra/ominicontacto/deploy/vagrant/host_node/
- vagrant halt ubuntu
tags:
- build-aio
only:
- /.*ansible-hostnode.*$/
- /^pre-release-.*$/
- schedules
- web
staging-debian:
stage: build
script:
- export CI_COMMIT_REF_NAME=$CI_COMMIT_REF_NAME
- bash /home/ftsinfra/git_cleanup.sh
- cd /home/ftsinfra/ominicontacto/deploy/vagrant/host_node/
- vagrant halt debian
- vagrant destroy debian -f
- ./vagrantup.sh debian
- python ../edit_ansible.py --internal_ip=$STAGING_IP_DEBIAN --self_hosted=no --admin_pass=$DJANGO_PASS --databases_pass=$DATABASES_PASS
- cd ../../ansible
- echo "$FTSINFRA_PASS" | sudo -S IS_CICD=$IS_CICD ./deploy.sh --integration-tests
- cd /home/ftsinfra/ominicontacto/deploy/vagrant/host_node/
- vagrant halt debian
tags:
- build-aio
only:
- /.*ansible-hostnode.*$/
- /^pre-release-.*$/
- schedules
- web
staging-self-hosted:
stage: build
script:
- export BRANCH=$CI_COMMIT_REF_NAME
- bash /home/ftsinfra/git_cleanup.sh
- cd /home/ftsinfra/ominicontacto/deploy/vagrant/self_hosted/
- vagrant halt; RC=0
- vagrant destroy -f; RC=0
- ./vagrantsh.sh
- vagrant up --provision
- vagrant halt
- vagrant destroy -f
tags:
- build-aio
only:
- /.*ansible-selfhosted.*$/
- /^pre-release-.*$/
- schedules
- web
#TODO: dejo template de lo que sería el job de upgrade, a probar luego de que salga release-1.3.1
#upgrade-centos:
# stage: build
# script:
# - export CI_COMMIT_REF_NAME=$CI_COMMIT_REF_NAME
# - bash /home/ftsinfra/git_cleanup.sh
# - cd /home/ftsinfra/oml-boxes
# - vagrant box add centos-release-1.3.1.box –name centos-release-1.3.1
# - cd /home/ftsinfra/ominicontacto/deploy/vagrant/releases
# - vagrant halt
# - vagrant destroy -f
# - ./vagrantup.sh centos
# - python ../edit_ansible.py --internal_ip=172.16.20.63 --self_hosted=no --admin_pass=$DJANGO_PASS --databases_pass=$DATABASES_PASS
# - cd ../../ansible
# - echo "$FTSINFRA_PASS" | sudo -S IS_CICD=$IS_CICD ./deploy.sh -u
# - cd /home/ftsinfra/ominicontacto/deploy/vagrant/releases
# - vagrant halt centos
# tags:
# - build-aio
# only:
# - /.*ansible-upgrade.*$/
# - /^pre-release-.*$/
# - schedules
# - web
prod-centos:
stage: deploy
environment: FTS-CENTOS7
script:
- cd /home/ftsinfra/ominicontacto/deploy/vagrant/host_node/
- git fetch
- git checkout ../../ansible/inventory
- git checkout $CI_COMMIT_REF_NAME
- vagrant halt centos
- vagrant destroy centos -f
- ./vagrantup.sh centos
- python ../edit_ansible.py --remote_host=$STAGING_HOST_CENTOS --internal_ip=$STAGING_IP_CENTOS --self_hosted=no --admin_pass=$DJANGO_PASS --databases_pass=$DATABASES_PASS
- cd ../../ansible
- echo "$FTSINFRA_PASS" | sudo -S IS_CICD=$IS_CICD ./deploy.sh -i
- cd /home/ftsinfra/ominicontacto/deploy/vagrant/host_node/
- vagrant package --base Centos-Staging --output centos-$CI_COMMIT_REF_NAME.box
- cp centos-$CI_COMMIT_REF_NAME.box /home/ftsinfra/oml-boxes
- cp -a .vagrant/machines/centos/virtualbox/private_key /home/ftsinfra/oml-boxes/centos_private_key_$CI_COMMIT_REF_NAME
- rm -rf centos-$CI_COMMIT_REF_NAME.box
tags:
- deploy-aio
only:
- /^release-.*$/
prod-ubuntu:
stage: deploy
environment: FTS-UBUNTU_BIONIC
script:
- cd /home/ftsinfra/ominicontacto/deploy/vagrant/host_node/
- git fetch
- git checkout ../../ansible/inventory
- git checkout $CI_COMMIT_REF_NAME
- vagrant halt ubuntu
- vagrant destroy ubuntu -f
- ./vagrantup.sh ubuntu
- python ../edit_ansible.py --remote_host=$STAGING_HOST_UBUNTU --internal_ip=$STAGING_IP_UBUNTU --self_hosted=no --admin_pass=$DJANGO_PASS --databases_pass=$DATABASES_PASS
- cd ../../ansible
- echo "$FTSINFRA_PASS" | sudo -S IS_CICD=$IS_CICD ./deploy.sh -i
- cd /home/ftsinfra/ominicontacto/deploy/vagrant/host_node/
- vagrant package --base Ubuntu-Staging --output ubuntu-$CI_COMMIT_REF_NAME.box
- cp ubuntu-$CI_COMMIT_REF_NAME.box /home/ftsinfra/oml-boxes
- cp -a .vagrant/machines/ubuntu/virtualbox/private_key /home/ftsinfra/oml-boxes/ubuntu_private_key_$CI_COMMIT_REF_NAME
- rm -rf ubuntu-$CI_COMMIT_REF_NAME.box
tags:
- deploy-aio
only:
- /^release-.*$/
prod-debian:
stage: deploy
environment: FTS-DEBIAN
script:
- cd /home/ftsinfra/ominicontacto/deploy/vagrant/host_node/
- git fetch
- git checkout ../../ansible/inventory
- git checkout $CI_COMMIT_REF_NAME
- vagrant halt debian
- vagrant destroy debian -f
- ./vagrantup.sh debian
- python ../edit_ansible.py --remote_host=$STAGING_HOST_DEBIAN --internal_ip=$STAGING_IP_DEBIAN --self_hosted=no --admin_pass=$DJANGO_PASS --databases_pass=$DATABASES_PASS
- cd ../../ansible
- echo "$FTSINFRA_PASS" | sudo -S IS_CICD=$IS_CICD ./deploy.sh -i
- cd /home/ftsinfra/ominicontacto/deploy/vagrant/host_node/
- vagrant package --base Debian-Staging --output debian-$CI_COMMIT_REF_NAME.box
- cp debian-$CI_COMMIT_REF_NAME.box /home/ftsinfra/oml-boxes
- cp -a .vagrant/machines/debian/virtualbox/private_key /home/ftsinfra/oml-boxes/debian_private_key_$CI_COMMIT_REF_NAME
- rm -rf debian-$CI_COMMIT_REF_NAME.box
tags:
- deploy-aio
only:
- /^release-.*$/