如何将文件从本地git复制到服务器文件系统?

时间:2013-10-12 03:24:52

标签: python django fabric

我正在寻找一种自动化部署脚本的方法。 我选择使用面料。

我无法弄清楚是否有办法将本地更改的文件复制到服务器。 我见过很多例子,但他们都使用github或者在服务器上安装了一个源git。

我想做点什么:

get changed files from local and add them in server

2 个答案:

答案 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同时做两件事。)