-
Notifications
You must be signed in to change notification settings - Fork 40
/
deploy.py
99 lines (77 loc) · 3.24 KB
/
deploy.py
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
from deployer.node import Node
from deployer.host import SSHHost
class PhasetyVPS(SSHHost):
slug = 'phasetyvps'
address = 'preciosdeargentina.com.ar'
username = 'root'
class Preciosa(Node):
class Hosts:
host = PhasetyVPS
# Location of the virtual env
ip = '162.243.67.151'
virtual_env_location = '/virtualenvs/preciosa'
python = virtual_env_location + '/bin/python'
pip = virtual_env_location + '/bin/pip'
preciosa_project = '/projects/preciosa'
project_logs = '/projects/preciosa/logs'
def apt(self, packages, command='install'):
self.hosts.run('sudo apt-get %s %s' % (command, packages))
def get_log(self):
with self.hosts.cd(self.project_logs):
self.hosts.run('tail preciosa.log')
def restart(self, que=None):
if que == 'pg' or que is None:
self.hosts.run('sudo service postgresql restart')
if que == 'app' or que is None:
self.hosts.run('sudo supervisorctl restart preciosa')
if que == 'nginx' or que is None:
self.hosts.run('sudo service nginx restart')
def run_in_preciosa(self, command):
with self.hosts.cd(self.preciosa_project):
self.hosts.run(command)
def shell_plus(self):
self.django_command('shell_plus')
def django_command(self, command):
with self.hosts.cd(self.preciosa_project):
self.hosts.run('%s manage.py %s' % (self.python, command))
def pip_install(self, package, upgrade=False):
command = "install --upgrade" if upgrade else "install"
self.hosts.run('%s %s %s' % (self.pip, command, package))
def pip_update(self):
"""update requirements.txt"""
with self.hosts.cd(self.preciosa_project):
self.hosts.run('%s install -r requirements/production.txt' % self.pip)
def edit_local_settings(self):
with self.hosts.cd(self.preciosa_project):
self.hosts.run('vim preciosa/local_settings.py')
self.restart()
def ngxtop(self, subcommand=''):
self.run_in_preciosa('ngxtop ' + subcommand)
def debug(self, port='8000'):
self.run_in_preciosa('git tag checkpoint_debug')
self.update('debug')
self.hosts.run('sudo supervisorctl stop preciosa')
self.hosts.run('sudo service nginx stop')
self.django_command('runserver %s:%s' % (self.ip, port))
self.run_in_preciosa('git checkout checkpoint_debug')
self.run_in_preciosa('git tag -d checkpoint_debug')
self.hosts.run('sudo service nginx start')
self.hosts.run('sudo supervisorctl start preciosa')
def dbbackup(self):
self.django_command('dbbackup -z')
def update(self, branch='develop'):
self.run_in_preciosa('git fetch')
self.run_in_preciosa('git reset --hard origin/%s' % branch)
#self.django_command('clean_pyc')
def deploy(self, dbbackup=False, branch='develop'):
self.update(branch)
self.pip_update()
if dbbackup:
self.dbbackup()
self.django_command('syncdb')
self.django_command('migrate')
self.django_command('collectstatic --noinput')
self.restart()
if __name__ == '__main__':
from deployer.client import start
start(Preciosa)