58 lines
1.3 KiB
Python
58 lines
1.3 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 = 'coinwind.tar.gz'
|
|
DIRS = ('app', 'config', 'resources')
|
|
UPLOAD_PATH = '~'
|
|
DEPLOY_PATH = '/www/coinwind'
|
|
|
|
|
|
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='154.82.76.95', user='root', connect_kwargs={'password': 'jkR^2!2Nr&D%lwm9'}) 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))
|
|
run(r, 'chmod 600 {}'.format(join(DEPLOY_PATH, 'config/*')))
|
|
run(r, 'chmod 600 {}'.format(join(DEPLOY_PATH, '.env')))
|