-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfabfile.py
78 lines (57 loc) · 2.04 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
from __future__ import with_statement
from fabric.api import cd, env, prefix, run
def staging():
projectname = "bakeup"
basepath = "/srv/bakeup.org/%s"
env.hosts = ["[email protected]"]
env.path = basepath % projectname
env.virtualenv_path = basepath % "bakeupenv"
env.push_branch = "staging"
env.push_remote = "origin"
env.reload_cmd = "supervisorctl restart {0}".format(projectname)
env.after_deploy_url = "http://bakeup.org"
def production():
projectname = "bakeup"
basepath = "/home/django/%s"
env.hosts = ["[email protected]"]
env.path = basepath % projectname
env.virtualenv_path = basepath % "djangoenv"
env.push_branch = "main"
env.push_remote = "origin"
env.reload_cmd = "supervisorctl restart django"
env.after_deploy_url = "http://bakeup.org"
def reload_webserver():
run("%(reload_cmd)s" % env)
def migrate():
with prefix("source %(virtualenv_path)s/bin/activate" % env):
run("%(path)s/manage.py migrate --settings=config.settings.production" % env)
def ping():
run(
"echo %(after_deploy_url)s returned: \\>\\>\\> $(curl --write-out"
" %%{http_code} --silent --output /dev/null %(after_deploy_url)s)" % env
)
def deploy():
with cd(env.path):
run("git fetch --tags -f")
run("git pull %(push_remote)s %(push_branch)s" % env)
migrate()
collectstatic()
reload_webserver()
ping()
def collectstatic():
with prefix("source %(virtualenv_path)s/bin/activate" % env):
run(
"%(path)s/manage.py collectstatic --noinput"
" --settings=config.settings.production" % env
)
def pip():
with cd(env.path):
run("git pull %(push_remote)s %(push_branch)s" % env)
with prefix("source %(virtualenv_path)s/bin/activate" % env):
run("pip install -Ur requirements/production.txt")
reload_webserver()
def soft_deploy():
with cd(env.path):
run("git pull %(push_remote)s %(push_branch)s" % env)
reload_webserver()
ping()