-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfabfile.py
49 lines (34 loc) · 1.17 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
# Update django-todo.org with latest "shell site" and dependencies
# (most importantly django-todo). Migrate, collecstatic, then restart
# gunicorn and nginx.
from fabric.contrib.files import exists
from fabric.api import cd, env, run, sudo
from fabric.utils import abort
REPO_URL = "https://github.com/shacker/gtd.git"
SITE_DIR = "/home/django/gtd"
env.user = "django"
env.hosts = ["django-todo.org"]
def deploy():
"""Call typical Django site deployment steps in order."""
with cd(SITE_DIR):
_update_source()
_update_virtualenv()
_update_static_files()
_update_database()
_restart_servers()
def _update_source():
if exists(".git"):
run("git checkout master")
run("git pull origin master")
else:
current_dir = run("pwd")
abort(f"{current_dir} does not appear to be a git directory. Exiting.")
def _update_virtualenv():
run('pipenv install')
def _update_static_files():
run("pipenv run ./manage.py collectstatic --noinput")
def _update_database():
run("pipenv run ./manage.py migrate")
def _restart_servers():
sudo("systemctl restart gunicorn")
sudo("service nginx restart")