-
Notifications
You must be signed in to change notification settings - Fork 316
/
Copy pathfabfile.py
43 lines (34 loc) · 1.24 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
from fabric import task
from invoke import Responder
from _credentials import github_password, github_username
def _get_github_auth_responders():
"""
返回 GitHub 用户名密码自动填充器
"""
username_responder = Responder(
pattern="Username for 'https://github.com':",
response='{}\n'.format(github_username)
)
password_responder = Responder(
pattern="Password for 'https://{}@github.com':".format(github_username),
response='{}\n'.format(github_password)
)
return [username_responder, password_responder]
@task()
def deploy(c):
supervisor_conf_path = '~/etc/'
supervisor_program_name = 'hellodjango-blog-tutorial'
project_root_path = '~/apps/HelloDjango-blog-tutorial/'
# 先停止应用
with c.cd(supervisor_conf_path):
cmd = 'supervisorctl stop {}'.format(supervisor_program_name)
c.run(cmd)
# 进入项目根目录,从 Git 拉取最新代码
with c.cd(project_root_path):
cmd = 'git pull'
responders = _get_github_auth_responders()
c.run(cmd, watchers=responders)
# 重新启动应用
with c.cd(supervisor_conf_path):
cmd = 'supervisorctl start {}'.format(supervisor_program_name)
c.run(cmd)