-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfabfile.py
120 lines (86 loc) · 2.72 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
from fabric.api import *
from fabric import operations
from fabtools import require
import fabtools
import requests
import os
PROJ_NAME = 'orl'
VENV_DIR = '~/{}_env/'.format(PROJ_NAME)
PROJ_DIR = '~/{}/'.format(PROJ_NAME)
@task
def deploy():
with prefix('source ' + VENV_DIR + 'bin/activate'):
with cd(PROJ_DIR):
run('git pull')
fabtools.python.install_requirements(PROJ_DIR + 'requirements.txt')
run('python setup.py sdist')
with cd('dist'):
run('tar xfzv openrunlog-0.1.tar.gz')
run('cp -r openrunlog-0.1/openrunlog $VIRTUAL_ENV/lib/python2.7/site-packages/')
restart()
@task
def install_upstart_conf():
with cd(PROJ_DIR):
run('sudo cp openrunlog.conf /etc/init/openrunlog.conf')
@task
def start():
run('sudo start openrunlog')
@task
def stop():
run('sudo stop openrunlog')
@task
def restart():
run('sudo restart openrunlog')
@task
def uninstall():
run('rm -rf ' + PROJ_DIR)
run('sudo rm /etc/init/openrunlog.conf')
@task
def setup():
require.python.pip()
fabtools.python.install('virtualenv', use_sudo=True)
fabtools.require.deb.package('git-core')
install_node()
# Create venv
run('virtualenv -p `which python2.7` ' + PROJ_NAME + '_env')
# activate venv
with prefix('source ' + VENV_DIR + 'bin/activate'):
# clone repo
run('git clone https://github.com/davidwilemski/openrunlog.git ' + PROJ_NAME)
# install requirements
fabtools.python.install_requirements(PROJ_DIR + 'requirements.txt')
with cd(PROJ_DIR):
run('python setup.py sdist')
with cd('dist'):
run('tar xfzv openrunlog-0.1.tar.gz')
run('cp -r openrunlog-0.1/openrunlog $VIRTUAL_ENV/lib/python2.7/site-packages/')
install_upstart_conf()
install_mongo()
start()
@task
def install_mongo():
with prefix('source ' + VENV_DIR + 'bin/activate'):
run('mongoctl install-mongodb')
@task
def install_node():
# needed for PyExecJS
fabtools.require.deb.package('nodejs')
@task
def migrate_mongoengine():
with prefix('source ' + VENV_DIR + 'bin/activate'):
with cd(PROJ_DIR):
run('python openrunlog/scripts/migrations/mongoengine07to08.py')
start()
@task
def shell():
return operations.open_shell()
@task
def recalculate_streak(user=None):
with prefix('source ' + VENV_DIR + 'bin/activate'):
with cd(PROJ_DIR):
run('python openrunlog/scripts/recalculate_streaks.py')
@task
def invalidate_cache(user=None):
with prefix('source ' + VENV_DIR + 'bin/activate'):
with cd(PROJ_DIR):
run('python openrunlog/scripts/invalidate_cache.py')