0

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

我不知道是否有办法将本地更改的文件复制到服务器。我见过很多例子,但它们都使用 github 或安装在服务器中的原始 git。

我想做类似的事情:

get changed files from local and add them in server
4

2 回答 2

0

使用类似的东西

import subprocess
subprocess.call(["git","pull","fromlocalmachine"])
于 2013-10-12T15:41:55.557 回答
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两者都做)。

于 2013-10-12T17:06:31.547 回答