我正在寻找一种自动化部署脚本的方法。 我选择使用面料。
我无法弄清楚是否有办法将本地更改的文件复制到服务器。 我见过很多例子,但他们都使用github或者在服务器上安装了一个源git。
我想做点什么:
get changed files from local and add them in server
答案 0 :(得分:0)
使用类似
的内容import subprocess
subprocess.call(["git","pull","fromlocalmachine"])
答案 1 :(得分:0)
除了Synthetica的回答,是一个简单的部署脚本,从sametmax.com抓取:
from fabric.api import local, run, cd, env, prefix
REMOTE_WORKING_DIR = '/path/to/project'
env.hosts = ['siteweb.com']
env.user = 'username'
def push(branch='master', remote='origin', runlocal=True):
if runlocal:
# run command locally
local("git push %s %s" % (remote, branch))
else:
# run command on remote hosts
run("git push %s %s" % (remote, branch))
def pull(branch='master', remote='origin', runlocal=True):
if runlocal:
local("git pull %s %s" % (remote, branch))
else:
run("git pull %s %s" % (remote, branch))
def sync(branch='master', remote='origin', runlocal=True):
pull(branch, remote, runlocal)
push(branch, remote, runlocal)
def deploy(branch='master', remote='origin'):
with cd(REMOTE_WORKING_DIR):
with prefix('workon virtualenv'): # replace by your virtual env name
pull(branch, remote, False)
run("./manage.py collectstatic --noinput")
现在,您可以运行fab sync
将您的git存储库与您的git服务器同步,并fab deploy
来部署它。
(或fab sync deploy
同时做两件事。)