-
Notifications
You must be signed in to change notification settings - Fork 28
/
fabfile.py
67 lines (47 loc) · 1.7 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
import re
from fabric.api import run, env, cd, shell_env, execute, sudo
from fabric.network import ssh
from functools import wraps
ssh.util.log_to_file("paramiko.log", 10)
env.hosts = ['linode']
env.use_ssh_config = True
ROOT='/home/david/public_html/django/django_recipes/public'
INI_FILE = '/etc/uwsgi/apps-available/django_recipes.ini'
def restart():
with cd(ROOT):
sudo('/etc/init.d/uwsgi restart')
def update():
with cd(ROOT):
run('git pull --rebase')
def schema():
with cd(ROOT), shell_env(DJANGO_SETTINGS_MODULE='django_recipes.settings.production'):
run('pipenv run ./manage.py migrate')
def backupdb():
with cd(ROOT):
run('./backupLocalDB.sh recipes_django')
def static():
with cd(ROOT):
run('pipenv run ./manage.py collectstatic --settings=django_recipes.settings.production --noinput --link --clear')
def deploy():
execute(update)
execute(env)
execute(backupdb)
execute(schema)
execute(static)
execute(restart)
ansi_escape = re.compile(r'\x1B[@-_][0-?]*[ -/]*[@-~]')
def env():
with cd(ROOT):
run('pipenv --rm')
run('pipenv --python 3.7')
run('pipenv install')
pipenv_env_dir = run('pipenv --bare --venv')
print("pipenv_env_dir=",pipenv_env_dir)
pipenv_env_dir = ansi_escape.sub("", pipenv_env_dir)
print("pipenv_env_dir=",pipenv_env_dir)
pipenv_env_dir = pipenv_env_dir.strip()
print("pipenv_env_dir=",pipenv_env_dir)
pipenv_env_dir = pipenv_env_dir.replace('/', '\\/')
print("pipenv_env_dir=",pipenv_env_dir)
sudo("sed -e 's/home=.*/home={0}/g' -i.bak {1}".format(pipenv_env_dir, INI_FILE))
run("cat " + INI_FILE)