mirror of
https://github.com/DarrenOfficial/dpaste.git
synced 2024-11-15 08:02:54 +11:00
Better fabfile
This commit is contained in:
parent
9c45b92910
commit
fa920eb9cf
1 changed files with 64 additions and 34 deletions
90
fabfile.py
vendored
90
fabfile.py
vendored
|
@ -1,21 +1,37 @@
|
||||||
from fabric.api import env, local, run, require, cd
|
from fabric.api import env, local, run, require, cd
|
||||||
from fabric.operations import _prefix_commands, _prefix_env_vars
|
from fabric.operations import _prefix_commands, _prefix_env_vars
|
||||||
|
|
||||||
|
# Host
|
||||||
env.disable_known_hosts = True # always fails for me without this
|
env.disable_known_hosts = True # always fails for me without this
|
||||||
env.hosts = ['pastebin.dev.lincolnloop.com']
|
env.user = 'root'
|
||||||
env.root = '/opt/webapps/pastebin'
|
env.hosts = ['dpaste.de']
|
||||||
env.proj_root = env.root + '/src/pastebin'
|
env.proj_repo = 'git@github.com:bartTC/dpaste.de.git'
|
||||||
env.proj_repo = 'git@github.com:myuser/myrepo.git'
|
|
||||||
|
# Paths
|
||||||
|
env.root = '/opt/webapps/dpaste.de'
|
||||||
|
env.proj_root = env.root + '/src/dpastede'
|
||||||
|
env.pid_file = env.root + '/var/gunicorn.pid'
|
||||||
|
env.proj_bin = env.proj_root + '/pastebin/bin'
|
||||||
|
env.local_settings = env.proj_root + '/pastebin/conf/local/settings.py'
|
||||||
env.pip_file = env.proj_root + '/requirements.pip'
|
env.pip_file = env.proj_root + '/requirements.pip'
|
||||||
|
|
||||||
|
# ============================================================================
|
||||||
|
# Git
|
||||||
|
# ============================================================================
|
||||||
|
|
||||||
def deploy():
|
def push(remote=None, branch=None, reload=False):
|
||||||
"""Update source, update pip requirements, syncdb, restart server"""
|
"""Pushes the local git repo to the given remote and branch. Then pulls it
|
||||||
update()
|
o n the server."""
|
||||||
update_reqs()
|
remote = remote or 'origin'
|
||||||
syncdb()
|
branch = branch or 'master'
|
||||||
|
local('git push %s %s' % (remote, branch))
|
||||||
|
with cd(env.proj_root):
|
||||||
|
ve_run('git pull %s %s' % (remote, branch))
|
||||||
|
if reload:
|
||||||
restart()
|
restart()
|
||||||
|
|
||||||
|
def pushr(remote=None, branch=None, reload=True):
|
||||||
|
push(remote, branch, reload)
|
||||||
|
|
||||||
def switch(branch):
|
def switch(branch):
|
||||||
"""Switch the repo branch which the server is using"""
|
"""Switch the repo branch which the server is using"""
|
||||||
|
@ -23,44 +39,59 @@ def switch(branch):
|
||||||
ve_run('git checkout %s' % branch)
|
ve_run('git checkout %s' % branch)
|
||||||
restart()
|
restart()
|
||||||
|
|
||||||
|
|
||||||
def version():
|
def version():
|
||||||
"""Show last commit to repo on server"""
|
"""Show last commit to repo on server"""
|
||||||
with cd(env.proj_root):
|
with cd(env.proj_root):
|
||||||
sshagent_run('git log -1')
|
sshagent_run('git log -1')
|
||||||
|
|
||||||
|
# ============================================================================
|
||||||
|
# Server
|
||||||
|
# ============================================================================
|
||||||
|
|
||||||
def restart():
|
def restart():
|
||||||
"""Restart Apache process"""
|
"""Kill the gunicorn process, Cherokee will start it upon request"""
|
||||||
run('touch %s/etc/apache/django.wsgi' % env.root)
|
ve_run('kill `cat %s`' % env.pid_file)
|
||||||
|
|
||||||
|
def flush():
|
||||||
|
"""Flush memcache"""
|
||||||
|
sshagent_run('/etc/init.d/memcached restart')
|
||||||
|
|
||||||
|
# ============================================================================
|
||||||
|
# Django
|
||||||
|
# ============================================================================
|
||||||
|
|
||||||
def update_reqs():
|
def update_reqs():
|
||||||
"""Update pip requirements"""
|
"""Update pip requirements"""
|
||||||
ve_run('yes w | pip install -r %s' % env.pip_file)
|
ve_run('yes w | pip install -r %s' % env.pip_file)
|
||||||
|
|
||||||
|
def collect():
|
||||||
|
manage('collectstatic --noinput')
|
||||||
|
|
||||||
def update():
|
def update(extreme=False):
|
||||||
"""Updates project source"""
|
push()
|
||||||
with cd(env.proj_root):
|
if extreme:
|
||||||
sshagent_run('git pull')
|
update_reqs()
|
||||||
|
collect()
|
||||||
|
if extreme:
|
||||||
|
flush()
|
||||||
|
restart()
|
||||||
|
|
||||||
|
def debugon():
|
||||||
|
"""Turn debug mode on for the production server."""
|
||||||
|
run("sed -i -e 's/^DEBUG = .*/DEBUG = True/' %s" % env.local_settings)
|
||||||
|
restart()
|
||||||
|
|
||||||
def syncdb():
|
def debugoff():
|
||||||
"""Run syncdb (along with any pending south migrations)"""
|
"""Turn debug mode on for the production server."""
|
||||||
ve_run('manage.py syncdb --migrate')
|
run("sed -i -e 's/^DEBUG = .*/DEBUG = False/' %s" % env.local_settings)
|
||||||
|
restart()
|
||||||
|
|
||||||
|
# ============================================================================
|
||||||
|
# SSH funcs
|
||||||
|
# ============================================================================
|
||||||
|
|
||||||
def clone():
|
def manage(cmd):
|
||||||
"""Clone the repository for the first time"""
|
return ve_run('python %s/manage.py %s' % (env.proj_bin, cmd))
|
||||||
with cd('%s/src' % env.root):
|
|
||||||
sshagent_run('git clone %s' % env.proj_repo)
|
|
||||||
ve_run('pip install -e %s' % env.proj_root)
|
|
||||||
|
|
||||||
with cd('%s/pastebin/conf/local' % env.proj_root):
|
|
||||||
run('ln -s ../dev/__init__.py')
|
|
||||||
run('ln -s ../dev/settings.py')
|
|
||||||
|
|
||||||
|
|
||||||
def ve_run(cmd):
|
def ve_run(cmd):
|
||||||
"""
|
"""
|
||||||
|
@ -70,7 +101,6 @@ def ve_run(cmd):
|
||||||
require('root')
|
require('root')
|
||||||
return sshagent_run('source %s/bin/activate; %s' % (env.root, cmd))
|
return sshagent_run('source %s/bin/activate; %s' % (env.root, cmd))
|
||||||
|
|
||||||
|
|
||||||
def sshagent_run(cmd):
|
def sshagent_run(cmd):
|
||||||
"""
|
"""
|
||||||
Helper function.
|
Helper function.
|
||||||
|
|
Loading…
Reference in a new issue