-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfabfile.py
56 lines (45 loc) · 1.99 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
# from fabric import task
from invoke import Responder
from _credentials import github_username, github_password, ssh_config
from fabric.connection import Connection
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 = '~/code/HelloDjango-blog-tutorial/'
# 先停止应用
with c.cd(supervisor_conf_path):
cmd = '/home/bwg/.local/bin/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)
c.run(cmd)
# 安装依赖,迁移数据库,收集静态文件
# with c.cd(project_root_path):
# c.run('/home/bwg/.local/bin/pipenv install --deploy --ignore-pipfile')
# c.run('/home/bwg/.local/bin/pipenv run python manage.py migrate')
# c.run('/home/bwg/.local/bin/pipenv run python manage.py collectstatic --noinput')
# 重新启动应用
with c.cd(supervisor_conf_path):
cmd = '/home/bwg/.local/bin/supervisorctl start {}'.format(supervisor_program_name)
c.run(cmd)
if __name__ == '__main__':
host, user, port, password = ssh_config['host'], ssh_config['user'], ssh_config['port'], ssh_config['password']
c = Connection(host=host, user=user, port=port, connect_kwargs={"password": password})
deploy(c)