fabfile.py
2.12 KB
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
from fabric.operations import put
from fabric.api import run, sudo, env
from fabric.contrib.files import exists
from fabric.decorators import with_settings
from fabric.context_managers import prefix, cd
env.user = 'colab' # key depends on env
env.use_shell = False
environments = {
'dev': {
'hosts': ['127.0.0.1'],
'port': 2222,
'key_filename': '~/.vagrant.d/insecure_private_key',
},
'live': {
'hosts': [], #TODO
'key_filename': '~/.ssh/id_rsa',
},
}
SOURCE_VENV = 'source /usr/local/bin/virtualenvwrapper.sh'
WORKON_COLAB = '{} && workon colab'.format(SOURCE_VENV)
def environment(name):
env.update(environments[name])
env.environment = name
environment('dev')
def mkvirtualenv():
if not exists('~/.virtualenvs/colab'):
with prefix(SOURCE_VENV):
run('mkvirtualenv colab')
return True
def install(local_settings=None):
env_created = mkvirtualenv()
if not exists('~/colab'):
run('git clone https://github.com/TracyWebTech/colab ~/colab')
if local_settings:
put(local_settings, '~/colab/src/colab/local_settings.py')
if env_created:
update_requirements()
sudo('supervisorctl reload', shell=False)
def update_requirements():
with cd('~/colab'), prefix(WORKON_COLAB):
run('pip install -r requirements.txt')
def deploy(update=False):
if update:
update_requirements()
with cd('~/colab/src/'), prefix(WORKON_COLAB):
run('git pull')
run('python manage.py syncdb')
run('python manage.py migrate')
run('python manage.py collectstatic --noinput')
sudo('supervisorctl restart all')
@with_settings(user='vagrant')
def runserver(update_requirements=False):
env_created = mkvirtualenv()
with cd('/vagrant/src/'), prefix(WORKON_COLAB):
# If explicitly called or if it's a new environment
if update_requirements or env_created:
run('pip install -r /vagrant/requirements.txt')
run('python manage.py syncdb')
run('python manage.py migrate')
run('python manage.py runserver 0.0.0.0:7000')