Skip to content
Browse files

Commander scripts for update and deployment

  • Loading branch information...
1 parent 7363d9e commit 11e02701e28c10a0ecc30194067fdc706be9e125 @jasonthomas jasonthomas committed
Showing with 109 additions and 0 deletions.
  1. +25 −0 scripts/update/commander_settings.py.dist
  2. +84 −0 scripts/update/update.py
View
25 scripts/update/commander_settings.py.dist
@@ -0,0 +1,25 @@
+SRC_DIR="/data/addons-dev/src/marketplace-dev.allizom.org-webpay/webpay"
+WWW_DIR="/data/addons-dev/www/marketplace-dev.allizom.org-webpay/webpay"
+
+REMOTE_APP="/data/www/marketplace-dev.allizom.org-webpay/webpay"
+REMOTE_UPDATE_SCRIPT="/data/bin/update-www.sh marketplace-dev.allizom.org-webpay"
+
+DEPLOY_SCRIPT = "/data/addons-dev/deploy -n marketplace-dev.allizom.org-webpay"
+
+UPDATE_REF = "origin/master"
+UPDATE_VENDOR_REF = "origin/master"
+
+WEB_HOSTGROUP="addons-dev"
+
+SSH_KEY="/root/keys/addons-updater"
+
+GUNICORN = [
+ 'gunicorn-webpay-marketplace',
+ ]
+
+PYPI_MIRROR = 'https://mrepo.mozilla.org/pypi/simple/'
+
+PYREPO = 'http://pyrepo1.addons.phx1.mozilla.com/'
+
+VIRTUAL_ENV = '/data/addons-dev/src/marketplace-dev.allizom.org-webpay/venv'
+PYTHON = VIRTUAL_ENV + '/bin/python'
View
84 scripts/update/update.py
@@ -0,0 +1,84 @@
+import os
+import sys
+
+sys.path.append(os.path.dirname(os.path.abspath(__file__)))
+
+from commander.deploy import BadReturnCode, hostgroups, task
+
+import commander_settings as settings
+
+
+_src_dir = lambda *p: os.path.join(settings.SRC_DIR, *p)
+
+
+@task
+def create_virtualenv(ctx):
+ venv = settings.VIRTUAL_ENV
+ ctx.local("rm -f %s/lib64" % venv)
+ try:
+ try:
+ ctx.local("virtualenv --distribute --never-download %s" % venv)
+ except BadReturnCode:
+ pass # if this is really broken, then the pip install should fail
+
+ ctx.local("rm -f %s/lib64 && ln -s ./lib %s/lib64" % (venv, venv))
+
+ ctx.local("%s/bin/pip install --exists-action=w --no-deps --no-index --download-cache=/tmp/pip-cache -f %s -r %s/requirements/prod.txt" %
+ (venv, settings.PYREPO, settings.SRC_DIR))
+ finally:
+ # make sure this always runs
+ ctx.local("rm -f %s/lib/python2.6/no-global-site-packages.txt" % venv)
+ ctx.local("%s/bin/python /usr/bin/virtualenv --relocatable %s" % (venv, venv))
+
+@task
+def update_code(ctx, ref='origin/master'):
+ with ctx.lcd(settings.SRC_DIR):
+ ctx.local("git fetch && git fetch -t")
+ ctx.local("git checkout -f %s" % ref)
+ ctx.local("git submodule sync")
+ ctx.local("git submodule update --init --recursive")
+ # Recursively run submodule sync and update to get all the right repo URLs.
+ ctx.local("git submodule foreach 'git submodule sync --quiet'")
+ ctx.local("git submodule foreach 'git submodule update --init --recursive'")
+
+@task
+def compress_assets(ctx, arg=''):
+ with ctx.lcd(settings.SRC_DIR):
+ ctx.local("%s manage.py compress_assets %s" % (settings.PYTHON, arg))
+
+@task
+def update_info(ctx, ref='origin/master'):
+ with ctx.lcd(settings.SRC_DIR):
+ ctx.local("git status")
+ ctx.local("git log -1")
+ ctx.local("/bin/bash -c 'source /etc/bash_completion.d/git && __git_ps1'")
+ ctx.local('git show -s {0} --pretty="format:%h" > media/git-rev.txt'.format(ref))
+
+@task
+def checkin_changes(ctx):
+ ctx.local(settings.DEPLOY_SCRIPT)
+
+@hostgroups(settings.WEB_HOSTGROUP, remote_kwargs={'ssh_key': settings.SSH_KEY})
+def deploy_app(ctx):
+ ctx.remote(settings.REMOTE_UPDATE_SCRIPT)
+ if getattr(settings, 'GUNICORN', False):
+ for gservice in settings.GUNICORN:
+ ctx.remote("/sbin/service %s graceful" % gservice)
+ else:
+ ctx.remote("/bin/touch %s/wsgi/playdoh.wsgi" % settings.REMOTE_APP)
+
+@task
+def deploy(ctx):
+ checkin_changes()
+ deploy_app()
+
+@task
+def pre_update(ctx, ref=settings.UPDATE_REF):
+ ctx.local('date')
+ update_code(ref)
+ update_info(ref)
+
+
+@task
+def update(ctx):
+ create_virtualenv()

0 comments on commit 11e0270

Please sign in to comment.
Something went wrong with that request. Please try again.