Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 122 lines (105 sloc) 4.76 KB
#!/usr/bin/env python
# OpenShift Quickstarter
# Deploy a variety of applications to the cloud with a single command.
#
# Copyright (C) 2011 Red Hat, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Author: Luke Macken <lmacken@redhat.com>
import os
import sys
import subprocess
python = 'python-2.7'
perl = 'perl-5.10'
java = 'jbossas-7.0'
ruby = 'ruby-1.8'
php = 'php-5.3'
db = 'mysql-5.1'
openshift_repo = 'git://github.com/openshift/%s-example.git'
openshift_alt_repo = 'git://github.com/openshift/%s-openshift-quickstart.git'
lmacken_repo = 'git://github.com/lmacken/%s-openshift-quickstart.git'
lmacken_fork_repo = 'git://github.com/lmacken/%s-example.git'
ryansb_repo = 'git://github.com/ryansb/%s-openshift-quickstart.git'
quickstarts = {
'pyramid': {'type': python, 'db': True, 'repo': lmacken_repo},
'cornice': {'type': python, 'db': True, 'repo': ryansb_repo},
'turbogears2': {'type': python, 'db': True, 'repo': lmacken_repo},
'django': {'type': python, 'db': True, 'repo': lmacken_fork_repo},
'pyblosxom': {'type': python, 'db': False, 'repo': lmacken_repo},
'flask': {'type': python, 'db': False, 'repo': openshift_repo},
'rails': {'type': ruby, 'db': True, 'repo': openshift_repo},
'reviewboard': {'type': python, 'db': True, 'repo': openshift_repo},
'mediawiki': {'type': php, 'db': True, 'repo': openshift_repo},
'drupal': {'type': php, 'db': True, 'repo': openshift_repo},
'wordpress': {'type': php, 'db': True, 'repo': openshift_repo},
'cakephp': {'type': php, 'db': True, 'repo': openshift_repo},
'wolfcms': {'type': php, 'db': True, 'repo': openshift_repo},
'frogcms': {'type': php, 'db': True, 'repo': openshift_repo},
'seambooking': {'type': java, 'db': True, 'repo': openshift_repo},
'sqlbuddy': {'type': php, 'db': True, 'repo': openshift_alt_repo},
'dancer': {'type': perl, 'db': False, 'repo': openshift_repo},
'sinatra': {'type': ruby, 'db': False, 'repo': openshift_repo},
'piwik': {'type': php, 'db': True, 'repo': openshift_alt_repo},
'sugarcrm': {'type': php, 'db': True, 'repo': openshift_repo},
'tweetstream': {'type': java, 'db': False, 'repo': openshift_repo,
'manual_config': True},
'joomla': {'type': php, 'db': True, 'repo': openshift_repo},
'phpbb': {'type': php, 'db': True, 'repo': openshift_repo},
}
def run(cmd, **kw):
status = subprocess.call(cmd, shell=True, **kw)
if status != 0:
print "** '%s' failed. Aborting" % cmd
sys.exit(status)
if len(sys.argv) != 5:
print(file(os.path.join(os.path.dirname(__file__), 'README.md')).read())
sys.exit(1)
prog, login, domain, app_name, quickstart = sys.argv
if os.path.isdir(app_name):
print("Application '%s' already exists in current directory" % app_name)
sys.exit(1)
# Create the application & database
app = quickstarts[quickstart]
run('rhc app create -a %s -t %s -l %s' % (app_name, app['type'], login))
if app['db']:
print("Adding %s cartridge to %s" % (db, app_name))
run('rhc cartridge add -a %s -c %s -l %s' % (app_name, db, login))
# Pre-merge configuration
if quickstart == 'dancer':
run('git rm -fr perl', cwd=app_name)
run('git commit -a -m "remove stock perl dir to prepare for Dancer"',
cwd=app_name)
elif quickstart == 'piwik':
run('rm -fr php/*', cwd=app_name)
# Pull in the appropriate quickstart template
run('git remote add quickstart -m master %s' % app['repo'] % quickstart,
cwd=app_name)
run('git pull -s recursive -X theirs --no-rebase quickstart master',
cwd=app_name)
# Pre-deployment configuration
if quickstart in ('frogcms', 'wolfcms'):
run('sed -i -e "s/%s-dbvs/%s-%s/" php/config.php' % (
quickstart, app_name, domain), cwd=app_name)
run('git commit -am "Update the base URL"', cwd=app_name)
# Push our code to the cloud
run('git push', cwd=app_name)
print("\nComplete!")
print("You can view your application at http://%s-%s.rhcloud.com" % (
app_name, domain))
# Mention required manual configuration for certain apps
if app.get('manual_config'):
print("Manual configuration is required for this application.")
print("See this page for details: %s#readme" %
app['repo'].replace('.git', '').replace('git:', 'http:') % quickstart)