Skip to content

Commit 3347af0

Browse files
author
Gustavo Fonseca
committed
Adição do Fabfile
Script para deployment automático.
1 parent 33fb422 commit 3347af0

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

fabfile.py

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# coding: utf-8
2+
""" Tarefas para manutenção de instalações do SciELO Manager.
3+
4+
Exemplo:
5+
fab deploy:tag=v2016.01.18 --scielomanager_settings_file=/etc/scieloapps/scielomanager.py \
6+
--installation_path=/var/www/manager_scielo_org
7+
"""
8+
from fabric.api import *
9+
10+
11+
SCIELOMANAGER_SETTINGS_FILE = env.get('scielomanager_settings_file',
12+
'/etc/scieloapps/scielomanager.py')
13+
INSTALLATION_PATH = env.get('installation_path',
14+
'/var/www/manager_scielo_org')
15+
16+
17+
def get_version():
18+
""" Obtém a versão ativa da instalação.
19+
20+
O formato da resposta segue a máscara:
21+
22+
<tag>-<total de commits além da tag>-<hash do head>
23+
24+
25+
Veja https://www.git-scm.com/docs/git-describe
26+
"""
27+
with cd(INSTALLATION_PATH):
28+
output = run('git describe --long --dirty --abbrev=10 --tags')
29+
return output
30+
31+
32+
def list_watchers():
33+
""" `watcher` é uma entidade monitorada pelo Circus.
34+
35+
Cada `watcher` pode ser composto por 1 ou N processos.
36+
"""
37+
with settings(sudo_user='root', warn_only=True):
38+
output = sudo('circusctl status | grep scielomanager')
39+
return [line.split(':')[0] for line in output.splitlines()]
40+
41+
42+
def reload_app():
43+
""" Reinicia, com carinho, todos os `watchers` da aplicação.
44+
"""
45+
with settings(sudo_user='root', warn_only=True):
46+
for watcher in list_watchers():
47+
sudo('circusctl reload %s' % watcher)
48+
49+
50+
def kill_circus():
51+
""" Termina o Circus e todos os seus `watchers`.
52+
53+
Tendo em vista que o `circusd` é gerenciado pelo monitor do sistema operacional,
54+
essa função funciona como um `reload` do tipo força-bruta e deve ser evitado
55+
pois causa indisponibilidade da app.
56+
"""
57+
with settings(sudo_user='root', warn_only=True):
58+
sudo('circusctl quit')
59+
60+
61+
def deploy(tag):
62+
""" Instala a versão `tag` da aplicação.
63+
"""
64+
with settings(sudo_user='root', warn_only=True):
65+
with settings(warn_only=True):
66+
if run('test -d {path}'.format(path=INSTALLATION_PATH)).failed:
67+
sudo('git clone https://github.com/scieloorg/scielo_publishing_schema.git {path}'.format(
68+
path=INSTALLATION_PATH))
69+
70+
with cd(INSTALLATION_PATH):
71+
with prefix('workon scielomanager'):
72+
sudo('git fetch origin && git checkout {tag} -b {tag}'.format(
73+
tag=tag))
74+
sudo('SCIELOMANAGER_SETTINGS_FILE={path} make upgrade'.format(
75+
path=SCIELOMANAGER_SETTINGS_FILE))
76+
77+
reload_app()
78+
79+
80+
def backup_db():
81+
""" Realiza *dump* completo da base de dados da aplicação.
82+
"""
83+
pass
84+
85+
def restore_db(path_to_script):
86+
""" Realiza *restore* da base de dados, com base no script SQL disponível em
87+
`path_to_script`.
88+
"""
89+
pass
90+

0 commit comments

Comments
 (0)