-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py.sample
76 lines (55 loc) · 1.58 KB
/
fabfile.py.sample
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
from fabric.api import env
from fabric.api import get
from fabric.api import local
from fabric.api import prefix
from fabric.api import run
from fabric.context_managers import lcd, cd
env.use_ssh_config = True
LOCAL = False
CONFIG = {
'dev': {
'host': 'user@server',
'activate': 'source /home/user/virtualenv/blog/bin/activate',
'code_folder': '/home/user/blog'
}
}
def loc():
global LOCAL
LOCAL = True
def set_host(host):
env.curconfig = CONFIG[host]
env.hosts = [env.curconfig['host']]
def dev():
set_host('dev')
def cdr(path):
if LOCAL:
return lcd(path)
return cd(path)
def runc(command):
if LOCAL:
local(command)
else:
run(command)
def deploy():
with cd(env.curconfig['code_folder']):
runc("git pull")
with prefix(env.curconfig['activate']):
runc("python manage.py makemigrations")
runc("python manage.py migrate")
runc("yarn install")
runc("yarn build_styles")
runc("python manage.py collectstatic --noinput")
restart_server()
def restart_server():
with cd(env.curconfig['code_folder']):
with prefix(env.curconfig['activate']):
runc("sudo kill -HUP `cat blog.pid`")
def dump():
with cd(env.curconfig['code_folder']):
runc("mysqldump -uroot blog > blog_dump.sql")
get("blog_dump.sql", "blog_dump.sql")
def dump_media():
with cd(env.curconfig['code_folder']):
runc("tar cvf media.tar media")
get("media.tar", 'media.tar')
local("tar xvf media.tar")