This repository has been archived by the owner on Oct 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
57 lines (41 loc) · 1.5 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
import getpass
from fabric.api import *
from fabric.contrib.console import confirm
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('../bin/python manage.py syncdb --migrate')
self.run('../bin/python manage.py collectstatic --noinput')
self.run('touch /etc/uwsgi/vassals/blast_uwsgi.ini')
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 confirm("Give new tag for this deployment?"):
self.run("git tag |tail -n 5")
tag = prompt('Give new tag for this deployment: ')
self.run("git tag %s" % tag)
self.run("git push --tags && git push")
def update_packages(self):
self.run("../bin/pip install -r requirements.txt")
PROD = Site(
dir='/home/prods/blast/blast-server',
user_id='www-data'
)
env.hosts = ['ndv.arkt.is']
@task
def deploy():
env.user = prompt("Username on prod server:", default=getpass.getuser())
# Pull on the production branch
PROD.deploy()
# Check if we want to tag the deployment
PROD.git_tag()
def header(text):
print ("#" * 45) + "\n# %s\n" % text + ("#" * 45)