-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathfabfile.py
88 lines (65 loc) · 2.61 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
81
82
83
84
85
86
87
from fabric import colors
from fabric.api import *
from fabric.contrib.project import *
from fabric.contrib.files import sed, exists
import git
env.app = '{{ project_name }}'
env.dest = "/var/www/%(app)s" % env
env.use_ssh_config = True
def label(env):
return env.host_string.replace("%(app)s-" % env, "")
def reload_processes():
sudo("kill -HUP `cat /tmp/%(app)s.pid`" % env)
def sync():
repo = git.Repo(".")
sha = repo.head.commit.hexsha
with cd(env.dest):
run("git fetch --all")
run("git checkout {} -f".format(sha))
if "production" in env.host_string:
with cd(env.dest):
run("compass compile")
# with prefix(". /home/ubuntu/environments/%(app)s/bin/activate" % env):
# run("%(dest)s/manage.py syncmedia" % env)
def deploy():
sync()
link_files()
with prefix(". /home/ubuntu/environments/%(app)s/bin/activate" % env):
run("pip install -qr %(dest)s/requirements.txt" % env)
with cd(env.dest):
run("./manage.py migrate" % env)
run("./manage.py syncmedia --ignore=img-sources/" % env)
add_commit_sha()
reload_processes()
update_system_configuration()
def update_system_configuration():
print(colors.yellow("Updating system configuration."))
env.label = label(env)
with cd(env.dest):
sudo("rm -f /etc/logrotate.conf")
sudo("cp conf/logrotate.conf /etc/")
sudo("cp conf/logrotate/* /etc/logrotate.d")
sudo("rm -f /etc/cron.d/%(app)s" % env)
sudo("cp conf/cron/%(label)s.crontab /etc/cron.d/%(app)s" % env)
sudo("sudo service cron restart")
def link_files():
print(colors.yellow("Linking settings."))
env.label = label(env)
with cd(env.dest):
sudo("rm -f local_settings.py")
sudo("ln -s conf/settings/%(label)s.py local_settings.py" % env)
sudo("rm -f conf/gunicorn/current.py")
sudo("ln -s %(label)s.py conf/gunicorn/current.py" % env)
sudo("rm -f celeryconfig.py")
sudo("ln -s conf/settings/celery/%(label)s.py celeryconfig.py" % env)
sudo("rm -f conf/supervisor/programs.ini" % env)
sudo("ln -s %(label)s.ini conf/supervisor/programs.ini" % env)
def reload_processes(reload_type="soft"):
print(colors.yellow("Reloading processes."))
env.label = label(env)
with cd(env.dest):
sudo("kill -HUP `cat /tmp/gunicorn.%(app)s.%(label)s.pid`" % env)
def add_commit_sha():
repo = git.Repo(".")
sha = repo.head.commit.hexsha
sed("{}/settings.py".format(env.dest), "^COMMIT_SHA = .*$", 'COMMIT_SHA = "{}"'.format(sha), backup="\"\"", use_sudo=True)