-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
executable file
·80 lines (58 loc) · 2.1 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
from fabric.api import *
import datetime, os
import private_fab
APPNAME = 'lipstr.com'
VERSION = datetime.datetime.now().strftime('%Y%m%d_%H%M')
FILENAME = '%s_%s.tar.gz' % (APPNAME, VERSION)
APPROOT = '/home/lipstr/lipstr.com'
DEVROOT = os.path.dirname(os.path.abspath(__file__))
DJANGOROOT = os.path.join(APPROOT, 'lipstr')
# the user to use for the remote commands
env.user = 'lipstr'
# the servers where the commands are executed
env.hosts = ['lipstr.com']
env.activate = 'source '+ os.path.join(APPROOT, 'bin/activate')
env.deploy_user = 'lipstr'
def up():
pack()
deploy()
#update_manifest()
collect_static()
restart()
clean()
def pack():
# create a new source distribution as tarball
with cd(DEVROOT):
local('mkdir -p dist')
local('tar -czf %s/dist/%s $(git ls-files)' % (DEVROOT, FILENAME), capture=False)
def deploy():
# upload the source tarball to the temporary folder on the server
with cd(DEVROOT):
put('%s/dist/%s' % (DEVROOT, FILENAME), '/tmp/%s' % FILENAME)
# create a place where we can unzip the tarball, then enter
# that directory and unzip it
run('rm -rf /tmp/%s && mkdir /tmp/%s' % (APPNAME, APPNAME))
with cd('/tmp/%s' % APPNAME):
run('tar xzf /tmp/%s' % FILENAME)
run('cp -r /tmp/%s/* %s' % (APPNAME, APPROOT))
def update_manifest():
run('sed -i "s/{{date}}/%s/" %s/list/static/cache.manifest' % (VERSION, APPROOT))
def collect_static():
with cd(DJANGOROOT):
with settings(warn_only=True):
virtualenv("python manage.py collectstatic --noinput")
def restart():
"""Restart gunicorn."""
with settings(warn_only=True):
run('kill -HUP $(cat %s/gunicorn.pid)' % APPROOT)
def stop():
"""Stops gunicorn."""
def clean():
# now that all is set up, delete the folder again
run('rm -rf /tmp/%s /tmp/%s' % (APPNAME, FILENAME))
def backup():
with cd(DEVROOT):
run('./backup.sh %(host)s %(user)s %(password)s' % private_fab.FTP_BACKUP)
# TOOLS
def virtualenv(command):
run(env.activate + ' && ' + command)