I am looking for a way to automate a deployment script. I choose to use fabric.
I can't figure out if there is a way to copy the local changed files to the server. I have seen many examples, but they all using github or an origin git installed in the server.
I would like to do something like :
get changed files from local and add them in server
Use something like
import subprocess
subprocess.call(["git","pull","fromlocalmachine"])
In addition to Synthetica's answer, is is a simple deployment script that, grabbed from 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")
Now, you can run fab sync
to sync your git repository with your git server, and fab deploy
to deploy it. (or fab sync deploy
to do both).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.