Skip to content

Instantly share code, notes, and snippets.

@oremj
Created May 17, 2011 19:25
Show Gist options
  • Save oremj/977179 to your computer and use it in GitHub Desktop.
Save oremj/977179 to your computer and use it in GitHub Desktop.
amo deploy using commander
import os
from commander.deploy import hostgroups, task
AMO_DIR = "/data/amo_python/src/prod/zamboni"
_amo_dir = lambda *p: os.path.join(AMO_DIR, *p)
_git_lcmd = lambda ctx, c: ctx.local("/usr/bin/git %s" % c)
def _git_checkout_tag(ctx, tag):
_git_lcmd(ctx, "fetch -t origin")
_git_lcmd(ctx, "checkout %s" % tag)
_git_lcmd(ctx, "submodule sync")
_git_lcmd(ctx, "submodule update --init")
@task
def update_code(ctx, tag, vendor_tag=None):
with ctx.lcd(AMO_DIR):
_git_checkout_tag(ctx, tag)
if vendor_tag:
with ctx.lcd("vendor"):
_git_checkout_tag(ctx, vendor_tag)
@task
def update_locales(ctx):
with ctx.lcd(_amo_dir(AMO_DIR, 'locale')):
ctx.local("svn revert -R .")
ctx.local("svn up")
@task
def disable_cron(ctx):
ctx.local("mv /etc/cron.d/addons-prod-maint /tmp/addons-prod-maint")
@task
def enable_cron(ctx):
with ctx.lcd(AMO_DIR):
ctx.local("cp scripts/crontab/prod /etc/cron.d/addons-prod-maint")
@task
def compress_assets(ctx):
with ctx.lcd(AMO_DIR):
ctx.local("python2.6 manage.py compress_assets")
@task
def schematic(ctx):
with ctx.lcd(AMO_DIR):
ctx.local("python2.6 ./vendor/src/schematic/schematic migrations")
@hostgroups(['amo', 'amo_gearman'], remote_limit=5)
def pull_code(ctx):
ctx.remote("/data/bin/libget/get-php5-www-git.sh")
ctx.remote("apachectl graceful")
@hostgroups(['amo_gearman'])
def restart_celery(ctx):
ctx.remote("service celeryd-prod restart")
ctx.remote("service celeryd-prod-devhub restart")
@task
def deploy_code(ctx):
ctx.local("/data/bin/omg_push_zamboni_live.sh")
pull_code()
@hostgroups(['amo_memcache'])
def clear_memcache(ctx):
ctx.remote('service memcached restart')
@hostgroups(['amo_redis'])
def clear_redis(ctx):
ctx.remote('pkill -9 -f "redis.*/amo.conf"; sleep 3; /etc/init.d/redis-amo start')
@task
def update_amo(ctx, tag, vendor_tag):
disable_cron()
update_code(tag, vendor_tag)
update_locales()
compress_assets()
schematic()
deploy_code()
restart_celery()
enable_cron()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment