-
Notifications
You must be signed in to change notification settings - Fork 4
/
fabfile.py
134 lines (106 loc) · 2.88 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
from fabric.api import *
from fabtools import require
from fabtools.python import virtualenv
import time
# Config
env.user = 'fermigier'
env.group = 'fermigier'
env.hosts = ['dedibox']
env.hostname = ''
#env.user = 'owf'
#env.group = 'owf'
#env.hosts = ['openwf.nexen.net']
#env.hostname = ''
env.git_url = "https://github.com/OWF/owf2013.git"
env.app_name = local('python setup.py --name', capture=True).strip()
# figure out the release name and version
env.dist = local('python setup.py --fullname', capture=True).strip()
env.app_root = '/home/{}/websites/{}'.format(env.user, env.app_name)
env.app_env = '/home/{}/websites/envs/{}'.format(env.user, env.app_name)
UWSGI_CONFIG_TPL = """
[uwsgi]
uid = %(user)s
gid = %(group)s
chdir = %(app_root)s
virtualenv = %(app_env)s
socket = uwsgi.sock
chmod-socket = 666
pythonpath = .
wsgi-file = wsgi.py
callable = app
plugins = python
processes = 4
threads = 2
"""
# Not used yet.
NGINX_CONFIG_TPL = """
erver {
server_name owf2013.demo.abilian.com;
server_name www.openworldforum.org openworldforum.org;
access_log /var/log/nginx/owf2013-access.log;
location /static/ {
root /home/fermigier/websites/owf2013/website;
}
location / { try_files $uri @owf2013; }
location @owf2013 {
include uwsgi_params;
uwsgi_pass unix:/home/fermigier/websites/owf2013/uwsgi.sock;
}
}
"""
@task
def setup():
require.python.virtualenv(env.app_env)
require.files.directory(env.app_root)
@task
def install_deps():
with cd(env.app_root):
put("deps.txt", "deps.txt")
with virtualenv(env.app_env):
require.python.install_requirements("deps.txt")
@task
def refresh_uwsgi():
require.file("/etc/uwsgi/apps-available/%s.ini" % env.app_name,
contents=UWSGI_CONFIG_TPL % {
'user': env.user,
'group': env.group,
'app_root': env.app_root,
'app_env': env.app_env,
}, use_sudo=True)
sudo("ln -sf /etc/uwsgi/apps-available/%s.ini "
"/etc/uwsgi/apps-enabled/%s.ini" % (env.app_name, env.app_name))
require.service.restarted('uwsgi')
@task
def backup():
with cd(env.app_root):
now = time.strftime("%Y%m%d-%H%M%S")
run("cp data/abilian.db ~/backup/owf2013-{}.db".format(now))
@task
def stage():
# create a place where we can unzip the tarball, then enter
# that directory and unzip it
try:
with cd("/tmp/{}".format(env.dist)):
run("git pull")
except:
run("git clone {} /tmp/{}".format(env.git_url, env.dist))
with cd("/tmp/{}".format(env.dist)):
run("echo `which clone`")
run("tox")
@task
def deploy():
with cd(env.app_root):
run("git pull")
install_deps()
#with cd(env.app_root):
# with virtualenv(env.app_env):
# run("py.test")
with cd(env.app_root):
with virtualenv(env.app_env):
run("make index")
refresh_uwsgi()
@task(default=True)
def default():
backup()
stage()
deploy()