-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
89 lines (64 loc) · 2.35 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
from fabric.api import cd, env, run, sudo, task, execute, local
from fabric.operations import put
from fabtools.vagrant import vagrant
from fabtools import require
import fabtools
import fabric
from StringIO import StringIO
from fabric.contrib.files import exists, append, comment, contains
from fabric.contrib.console import confirm
from fabric.colors import blue, cyan, green, red, blue
import os, sys
from gitric.api import git_seed, git_reset, allow_dirty, force_push, init_bluegreen, swap_bluegreen
@task
def default():
'''
Sets up the default env variables
'''
env.base_path = '/var/www/blooby/blooby'
env.virtualenv_path = '/var/www/blooby'
env.db_name = 'blooby'
default()
@task
def dep_test():
env.bluegreen_root = '/home/vagrant/deploy_test/'
env.bluegreen_ports = {'blue':'8888', 'green':'8000'}
init_bluegreen()
@task
def deploy(commit=None):
if not commit:
commit = local('git rev-parse HEAD', capture=True)
env.repo_path = env.next_path + '/repo'
git_seed(env.repo_path, commit)
git_reset(env.repo_path, commit)
run('kill $(cat %(pidfile)s) || true' % env)
env.pidfile = env.pidfile.replace("\\", "/")
env.virtualenv_path = env.virtualenv_path.replace("\\", "/")
env.repo_path = env.repo_path.replace("\\", "/")
env.nginx_conf = env.nginx_conf.replace("\\", "/")
run('virtualenv %(virtualenv_path)s' % env)
run('source %(virtualenv_path)s/bin/activate && pip install -r %(repo_path)s/requirements.txt' % env)
with fabtools.python.virtualenv(env.virtualenv_path), cd(env.repo_path):
run('python manage.py migrate')
run('python manage.py collectstatic --noinput')
put(StringIO('proxy_pass http://127.0.0.1:%(bluegreen_port)s/;' % env), env.nginx_conf)
sudo('cd %(repo_path)s && PYTHONPATH=. BLUEGREEN=%(color)s %(virtualenv_path)s/bin/gunicorn -D -b 0.0.0.0:%(bluegreen_port)s -p %(pidfile)s blooby.wsgi:application' % env)
@task
def staging():
'''
Sets up the staging env variables
'''
pass
@task
def live():
'''
Sets up live env variables
'''
pass
@task
def devserver(settings_file="blooby.settings"):
'''
Start the development server
'''
with fabtools.python.virtualenv(env.virtualenv_path), cd(env.base_path):
run('python manage.py runserver 0.0.0.0:8000 --settings=%(settings_file)s' % locals())