forked from django-tenants/django-tenants
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
99 lines (77 loc) · 2.61 KB
/
fabfile.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 fabric.decorators import task, hosts
from fabric.api import env, run, sudo
from fabtools.postgres import drop_database
from fabtools.vagrant import vagrant
from fabtools.deb import update_index
import fabtools
from fabric.context_managers import cd
@task
def vagrant():
env.user = 'vagrant'
env.hosts = ['127.0.0.1:2020']
env.passwords = {'[email protected]:2020': 'vagrant'}
env.psql_db = 'tenant_tutorial'
env.psql_user = 'tenant_tutorial'
env.psql_password = 'qwerty'
env.backup_path = '/vagrant/database_backup/'
env.user = 'vagrant'
env.deploy_user = 'vagrant'
env.passwords = {'[email protected]:2020': 'vagrant'}
env.vagrant = True
return env.hosts
@task
def provision_vagrant():
vagrant()
update_index()
# fabtools.require.postfix.server('example.com')
create_pg_database()
update_requirements()
django_manage("migrate")
django_migrate()
@task
def create_superuser():
django_manage("createsuperuser")
@task
def django_manage(command):
with cd("/vagrant/examples/tenant_tutorial/"):
run("python manage.py %s" % command)
def update_requirements():
fabtools.require.deb.packages(['python3',
'python-virtualenv',
'python3-dev',
'python3-setuptools',
'libffi-dev',
'libxslt1-dev',
'python3-pip',
'git',
'libboost-python1.58.0',
'pkg-config',
'postgresql-server-dev-9.5',
'postgresql-contrib',
])
sudo("pip3 install django==2.0")
@task
def create_pg_database():
# fabtools.require.postgres.server()
fabtools.require.postgres.user(env.psql_user, env.psql_password, createdb=True)
# fabtools.require.postgres.database(env.psql_db, env.psql_user)
sudo("sed -i 's/all peer/all"
" md5/g' /etc/postgresql/9.5/main/pg_hba.conf")
sudo('service postgresql restart')
@task
def reset_database():
sudo('service postgresql restart')
try:
drop_database(env.psql_db)
except:
pass
create_pg_database()
django_migrate()
def django_migrate():
django_manage("migrate_schemas")
@task
def create_tenant():
django_manage("create_tenant")
@task
def runserver():
django_manage("runserver 0.0.0.0:8088")