add deploy script

This commit is contained in:
mx 2022-05-03 15:20:27 +07:00
parent 6325d0b060
commit e7a3f819de
2 changed files with 58 additions and 0 deletions

1
.gitignore vendored
View File

@ -11,3 +11,4 @@ Homestead.yaml
npm-debug.log
yarn-error.log
.env
*.tar.gz

57
fabfile.py vendored Normal file
View File

@ -0,0 +1,57 @@
"""
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')))