This repository has been archived by the owner on Aug 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
fabfile.py
72 lines (63 loc) · 1.74 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
from fabric.api import *
from datetime import datetime
from fabric.contrib import files, console
from fabric.contrib.project import rsync_project
from fabric import utils
from fabric.api import env, require, run, sudo, cd
import os
env.hosts = ['fscons.org']
env.user = 'gdetrez'
env.root = '/srv/fscons.org'
env.project_root = os.path.join(env.root, 'myconf')
env.virtualenv_root = os.path.join(env.root, 'env')
env.activate_script = os.path.join(env.virtualenv_root, 'bin','activate')
RSYNC_EXCLUDE = (
'.DS_Store',
'.git',
'env',
'*.pyc',
'*.db',
'*~',
'local_settings.py',
'fabfile.py',
'bootstrap.py',
'_static',
)
@task(default=True)
def deploy():
if not console.confirm('Are you sure you want to deploy production?',
default=False):
utils.abort('Production deployment aborted.')
rsync()
collectstatic()
reload()
def virtualenv(command, use_sudo=False):
if use_sudo:
func = sudo
else:
func = run
func('source "%s" && %s' % (env.activate_script, command))
def manage_py(command, use_sudo=False):
with cd(env.project_root):
virtualenv('python manage.py %s' % command, use_sudo)
@task
def collectstatic():
#require('hosts', provided_by=[production])
manage_py('collectstatic -l --noinput')
@task
def rsync():
""" rsync code to remote host """
extra_opts = '--omit-dir-times'
rsync_project(
env.root,
exclude=RSYNC_EXCLUDE,
delete=True,
extra_opts=extra_opts,
)
@task
def reload():
""" touch wsgi file to trigger reload """
apache_dir = os.path.join(env.root, 'myconf', 'apache')
sudo("service apache2 restart")
with cd(apache_dir):
run('touch staging.wsgi')