Created
August 17, 2010 18:35
-
-
Save mccutchen/531343 to your computer and use it in GitHub Desktop.
A first cut at a fabfile that meets our App Engine deployment criteria
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import with_statement | |
import functools | |
import os | |
import sys | |
from fabric.api import * | |
from google.appengine.api import appinfo | |
def with_appcfg(func): | |
"""Decorator that ensures the current Fabric env has a GAE app.yaml config | |
attached to it.""" | |
@functools.wraps(func) | |
def decorated_func(*args, **kwargs): | |
if not hasattr(env, 'app'): | |
appcfg = appinfo.LoadSingleAppInfo(open('app.yaml')) | |
env.app = appcfg | |
return func(*args, **kwargs) | |
return decorated_func | |
@with_appcfg | |
def staging(): | |
"""Sets the deployment target to staging.""" | |
env.app.application = '%s-staging' % env.app.application | |
@with_appcfg | |
def production(): | |
"""Sets the deployment target to production.""" | |
pass | |
@with_appcfg | |
def deploy(git=None): | |
"""Deploys a fresh checkout of current git HEAD, optionally tagging the | |
version with the latest git revision.""" | |
# Are we deploying a version tagged with the git revision? If so, update | |
# the app's version string accordingly. | |
if git is not None: | |
gitversion = local('git rev-parse --short HEAD') | |
env.app.version = '%s-%s' % (env.app.version, gitversion) | |
# Where are we checking out a clean copy? | |
clone = local('mktemp -d -t %s' % env.app.application) | |
local('git clone . %s' % clone) | |
with cd(clone): | |
local('git submodule init') | |
local('git submodule update') | |
local('find . -name ".git*" | xargs rm -rf') | |
print 'App:', env.app.application | |
print 'Ver:', env.app.version | |
# local('appcfg.py -A %s -V %s update .' % | |
# (env.app.application, env.app.version), capture=False) | |
local('rm -r %s' % clone) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment