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.

Revisions

  1. oremj revised this gist May 24, 2011. 1 changed file with 27 additions and 29 deletions.
    56 changes: 27 additions & 29 deletions amodeploy.py
    Original file line number Diff line number Diff line change
    @@ -1,53 +1,58 @@
    import os

    from commander.deploy import hostgroups, local_command
    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 sync update --init")
    _git_lcmd(ctx, "submodule update --init")

    @local_command
    @task
    def update_code(ctx, tag, vendor_tag=None):
    with lcd(AMO_DIR):
    with ctx.lcd(AMO_DIR):
    _git_checkout_tag(ctx, tag)

    if vendor_tag:
    with ctx.lcd("vendor"):
    _git_checkout_tag(ctx, vendor_tag)

    @local_command
    @task
    def update_locales(ctx):
    with ctx.lcd(_amo_dir(AMO_DIR, 'locale')):
    ctx.local("svn revert -R .")
    ctx.local("svn up")

    @local_command
    @task
    def disable_cron(ctx):
    ctx.local("mv /etc/cron.d/addons-prod-maint /tmp/addons-prod-maint")


    @local_command
    @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")


    @local_command
    @task
    def schematic(ctx):
    with ctx.lcd(AMO_DIR):
    ctx.local("python2.6 ./vendor/src/schematic/schematic migrations")


    @hostgroups(['amo', 'amo_gearman'])
    @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")
    @@ -59,9 +64,10 @@ def restart_celery(ctx):
    ctx.remote("service celeryd-prod-devhub restart")


    @local_command
    @task
    def deploy_code(ctx):
    ctx.local("/data/bin/omg_push_zamboni_live.sh")
    pull_code()


    @hostgroups(['amo_memcache'])
    @@ -74,21 +80,13 @@ def clear_redis(ctx):
    ctx.remote('pkill -9 -f "redis.*/amo.conf"; sleep 3; /etc/init.d/redis-amo start')


    @local_command
    def enable_cron():
    with lcd(AMO_DIR):
    local("cp scripts/crontab/prod /etc/cron.d/addons-prod-maint")


    @hostgroups(['sj_amo'])
    def test_command(ctx):
    ctx.remote("hostname")

    @local_command
    def test_local_command(ctx):
    ctx.local("hostname")
    with ctx.lcd("/tmp/test"):
    _git_checkout_tag(ctx, "2.3")


    test_local_command()
    @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()
  2. oremj created this gist May 17, 2011.
    94 changes: 94 additions & 0 deletions amodeploy.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,94 @@
    import os

    from commander.deploy import hostgroups, local_command


    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 sync update --init")

    @local_command
    def update_code(ctx, tag, vendor_tag=None):
    with lcd(AMO_DIR):
    _git_checkout_tag(ctx, tag)

    if vendor_tag:
    with ctx.lcd("vendor"):
    _git_checkout_tag(ctx, vendor_tag)

    @local_command
    def update_locales(ctx):
    with ctx.lcd(_amo_dir(AMO_DIR, 'locale')):
    ctx.local("svn revert -R .")
    ctx.local("svn up")

    @local_command
    def disable_cron(ctx):
    ctx.local("mv /etc/cron.d/addons-prod-maint /tmp/addons-prod-maint")


    @local_command
    def compress_assets(ctx):
    with ctx.lcd(AMO_DIR):
    ctx.local("python2.6 manage.py compress_assets")


    @local_command
    def schematic(ctx):
    with ctx.lcd(AMO_DIR):
    ctx.local("python2.6 ./vendor/src/schematic/schematic migrations")


    @hostgroups(['amo', 'amo_gearman'])
    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")


    @local_command
    def deploy_code(ctx):
    ctx.local("/data/bin/omg_push_zamboni_live.sh")


    @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')


    @local_command
    def enable_cron():
    with lcd(AMO_DIR):
    local("cp scripts/crontab/prod /etc/cron.d/addons-prod-maint")


    @hostgroups(['sj_amo'])
    def test_command(ctx):
    ctx.remote("hostname")

    @local_command
    def test_local_command(ctx):
    ctx.local("hostname")
    with ctx.lcd("/tmp/test"):
    _git_checkout_tag(ctx, "2.3")


    test_local_command()