55 lines
1.1 KiB
Python
55 lines
1.1 KiB
Python
"""
|
|
Deploy Tool
|
|
|
|
usage:
|
|
|
|
1. `fab deploy` 上传 DIRS 中指定的目录/文件
|
|
2. `fab deploy -p=xxx` 上传 xxx
|
|
3. `fab deploy -p='xxx yyy zzz' 上传 xxx, yyy, zzz
|
|
|
|
PS. 提前配置服务器地址,密码
|
|
|
|
其他功能自行修改
|
|
|
|
"""
|
|
|
|
from os.path import exists, join
|
|
from fabric import task,Connection
|
|
|
|
FILE_TAR = 'coinwindf.tar.gz'
|
|
DIRS = ('build', )
|
|
UPLOAD_PATH = '~'
|
|
DEPLOY_PATH = '/www/coinwindf'
|
|
|
|
|
|
def run(c, cmd):
|
|
return c.run(cmd, hide=True)
|
|
|
|
|
|
@task
|
|
def tar(c):
|
|
c.run('rm -f {}'.format(FILE_TAR))
|
|
run(c, 'tar czf {} {}'.format(FILE_TAR, ' '.join(DIRS)))
|
|
# print(ret)
|
|
|
|
|
|
@task
|
|
def ptar(c, p):
|
|
# fallback
|
|
if not p:
|
|
return tar(c)
|
|
|
|
cmd = 'tar -czf {} {}'.format(FILE_TAR, p)
|
|
run(c, cmd)
|
|
|
|
|
|
@task
|
|
def deploy(c, p=''):
|
|
ptar(c, p)
|
|
|
|
with Connection(host='192.168.0.1', user='root', connect_kwargs={'password': '123456'}) as r:
|
|
with r.cd(UPLOAD_PATH):
|
|
r.put(FILE_TAR)
|
|
run(r, 'tar -xzf {} -C {}'.format(FILE_TAR, DEPLOY_PATH))
|
|
run(r, 'rm {}'.format(FILE_TAR))
|
|
run(r, 'chown -R nginx:nginx {}'.format(DEPLOY_PATH)) |