我正在尋找一種自動執行部署腳本的方法。 我選擇使用面料。如何將文件從本地git複製到服務器文件系統?
我不知道是否有辦法將本地更改的文件複製到服務器。 我見過很多例子,但他們都使用github或安裝在服務器上的origin git。
我想這樣做:
get changed files from local and add them in server
我正在尋找一種自動執行部署腳本的方法。 我選擇使用面料。如何將文件從本地git複製到服務器文件系統?
我不知道是否有辦法將本地更改的文件複製到服務器。 我見過很多例子,但他們都使用github或安裝在服務器上的origin git。
我想這樣做:
get changed files from local and add them in server
使用類似
import subprocess
subprocess.call(["git","pull","fromlocalmachine"])
除了咸陽市的回答,實在是一個簡單的部署腳本,從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代表ository與你的git服務器,並且fab deploy
部署它。 (或fab sync deploy
來做)。
沒問題,因爲你的web服務器上有git,並且你的web服務器和本地機器上有一個可以訪問的git倉庫。我沒有git在我的服務器上。是否可以將更改的文件直接推送到遠程服務器? –
我在安裝在部署服務器上的Git中使用它。我想在不使用Git的情況下進行部署,我認爲您需要通過FTP傳輸文件,但我不知道任何可用的腳本。恕我直言,在部署服務器上安裝git更容易。 –
這個在本地機器上運行,我們已經有本地的。 –