readthedocs.org/fabfile.py

132 lines
4.3 KiB
Python
Raw Normal View History

2010-08-28 19:21:36 +00:00
from fabric.api import *
from fabric.decorators import runs_once
2010-08-28 19:21:36 +00:00
env.runtime = 'production'
env.hosts = ['chimera.ericholscher.com', 'ladon.ericholscher.com', 'mozbuild.ericholscher.com']
2010-08-28 19:21:36 +00:00
env.user = 'docs'
2010-11-13 15:38:20 +00:00
env.code_dir = '/home/docs/sites/readthedocs.org/checkouts/readthedocs.org'
env.virtualenv = '/home/docs/sites/readthedocs.org'
env.rundir = '/home/docs/sites/readthedocs.org/run'
2010-08-28 19:21:36 +00:00
def push():
"Push new code, but don't restart/reload."
local('git push origin master')
with cd(env.code_dir):
run('git pull origin master')
def update_requirements():
"Update requirements in the virtualenv."
run("%s/bin/pip install -r %s/deploy_requirements.txt" % (env.virtualenv, env.code_dir))
2011-09-19 00:46:51 +00:00
@hosts(['chimera.ericholscher.com'])
def migrate(project=None):
if project:
run('django-admin.py migrate %s' % project)
else:
run('django-admin.py migrate')
2011-01-08 22:36:38 +00:00
@hosts(['chimera.ericholscher.com', 'ladon.ericholscher.com'])
2010-08-28 19:21:36 +00:00
def restart():
"Restart (or just start) the server"
2010-11-13 17:08:57 +00:00
env.user = "root"
run("restart readthedocs-gunicorn")
2010-08-28 22:47:47 +00:00
@hosts(['mozbuild.ericholscher.com'])
#@hosts(['kirin.ericholscher.com'])
2011-01-10 02:36:43 +00:00
def celery():
"Restart (or just start) the server"
env.user = "root"
run("restart readthedocs-celery")
def pull():
"Pull new code"
with cd(env.code_dir):
run('git pull origin master')
@runs_once
def spider():
local('patu.py -d1 readthedocs.org')
def _aws_wrapper(f, *args, **kwargs):
"get AWS credentials if not defined"
#these are normally defined in ~/.fabricrc
2011-09-19 00:46:51 +00:00
@hosts('run_once') #so fab doesn't go crazy
def wrapped(*args, **kwargs):
from boto.cloudfront.exception import CloudFrontServerError
from boto.cloudfront import CloudFrontConnection
2011-09-19 00:46:51 +00:00
c = CloudFrontConnection(env.aws_access_key_id,
env.aws_secret_access_key)
if not hasattr(env, 'aws_access_key_id'):
prompt('AWS Access Key ID: ', key='aws_access_key_id')
if not hasattr(env, 'aws_secret_access_key'):
prompt('AWS Secret Access Key: ', key='aws_secret_access_key')
try:
return f(c, *args, **kwargs)
except CloudFrontServerError as e:
print "Error: \n", e.error_message
return wrapped
@_aws_wrapper
def to_cdn(c, slug):
"Create a new Distribution object on CloudFront"
from boto.cloudfront import CloudFrontConnection
from boto.cloudfront.origin import CustomOrigin
2011-09-19 00:46:51 +00:00
c = CloudFrontConnection(env.aws_access_key_id,
env.aws_secret_access_key)
d = c.create_distribution(
origin=CustomOrigin(slug + '.cdn.readthedocs.org',
origin_protocol_policy='http-only'),
2011-09-19 00:46:51 +00:00
enabled=True,
comment='Slug: ' + slug,
cnames=[slug + '.readthedocs.org']
)
print "Created: " + d.domain_name + " for " + slug
list_cdn()
@_aws_wrapper
def list_cdn(c):
"List Distributions on CloudFront"
distributions = c.get_all_distributions()
for d in distributions:
2011-09-19 00:46:51 +00:00
print "%3s %4s %40s %30s" % ('Ena' if d.enabled else 'Dis',
d.status[:4], d.origin.dns_name,
d.domain_name)
@_aws_wrapper
def disable_cdn(c, *args):
"Sets a Distribution entry to disabled. Required before deletion."
distributions = c.get_all_distributions()
for distro in distributions:
dist_slug = distro.origin.dns_name.split('.')[0]
if dist_slug in args:
print "Disabling:", dist_slug
#this is broken as of boto 2.0b4.
#fix is to comment out lines 347-352 in cloudfront/distribution.py
distro.get_distribution().disable()
@_aws_wrapper
def delete_cdn(c):
"Deletes all Distributions in the 'Disabled' state."
distributions = c.get_all_distributions()
for distro in distributions:
if not distro.enabled and distro.status=="Deployed":
print "Deleting", distro.origin.dns_name
distro.get_distribution().delete()
def full_deploy():
2011-09-19 00:50:01 +00:00
#HACK
#Call this again at the top-level so the hosts decorator
#effects the hosts it runs against for each command.
run('fab push update_requirements migrate restart celery')
#push()
#update_requirements()
#migrate()
#restart()
#celery()
2011-06-19 23:52:26 +00:00
@hosts(['chimera.ericholscher.com'])
def uptime():
run('uptime')