-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfabfile.py
70 lines (52 loc) · 1.68 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
import getpass
from fabric.api import *
from fabric.contrib.console import confirm
import subprocess
class Site(object):
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
def run(self, cmd):
with cd(self.dir):
sudo(cmd, user=self.user_id)
def deploy(self):
self.git_pull()
self.update_packages()
self.run('venv/bin/python manage.py syncdb --migrate')
self.run('venv/bin/python manage.py collectstatic --noinput')
self.restart()
def git_pull(self):
# .pyc files can create ghost behavior when .py files are deleted...
self.run("find . -name '*.pyc' -delete")
self.run("git fetch origin && git reset --hard origin/master")
def git_tag(self):
if not confirm("Give new tag for this deployment?"):
if confirm("Are you sure?", default=False):
return
self.run("git tag | sort -g | tail -n 1 | sed s/$/+1/ | bc | xargs git tag")
self.run("git push --tags && git push")
def update_packages(self):
self.run("./venv/bin/pip install -r requirements.txt")
def restart(self):
sudo("touch /etc/uwsgi/vassals/poetenet_uwsgi.ini")
PROD = Site(
dir='/home/prods/poetenet/',
user_id='www-data'
)
env.hosts = ['poetene.net']
@task
def deploy():
"""
"""
# mac-only command, just for fun
try:
subprocess.call(['say', '"Ship! Ship! Ship!"'])
except:
pass
print "ship! ship! ship!"
env.user = prompt("Username on prod server:", default=getpass.getuser())
PROD.deploy()
# Check if we want to tag the deployment
PROD.git_tag()
@task
def restart():
PROD.restart()