openshift integration, thanks prelegalwonder

This commit is contained in:
mdipierro
2012-07-05 22:21:18 -05:00
parent b1a4ed556f
commit 7377cef7ff
4 changed files with 132 additions and 51 deletions

View File

@@ -1 +1 @@
Version 2.00.0 (2012-07-05 22:09:10) dev
Version 2.00.0 (2012-07-05 22:21:15) dev

View File

@@ -0,0 +1,53 @@
import os
from distutils import dir_util
from git import *
def deploy():
apps = sorted(file for file in os.listdir(apath(r=request)))#if regex.match(file))
form = SQLFORM.factory(
Field('osrepo',default='/tmp',label='Path to local openshift repo root.',
requires=EXISTS(error_message=T('directory not found'))),
Field('osname',default='web2py',label='WSGI reference name'),
Field('applications','list:string',
requires=IS_IN_SET(apps,multiple=True),
label=T('web2py apps to deploy')))
cmd = output = errors= ""
if form.accepts(request,session):
try:
kill()
except:
pass
ignore_apps = [item for item in apps \
if not item in form.vars.applications]
regex = re.compile('\(applications/\(.*')
w2p_origin = os.getcwd()
osrepo = form.vars.osrepo
osname = form.vars.osname
#Git code starts here
repo = Repo(form.vars.osrepo)
index = repo.index
assert repo.bare == False
for i in form.vars.applications:
appsrc = os.path.join(os.getcwd(),'applications',i)
appdest = os.path.join(osrepo,'wsgi',osname,'applications',i)
dir_util.copy_tree(appsrc,appdest)
#shutil.copytree(appsrc,appdest)
index.add(['wsgi/'+osname+'/applications/'+i])
new_commit = index.commit("Deploy from Web2py IDE") #<--- COMMIT WORKED.. Next.. on to actual push.
origin = repo.remotes.origin
origin.push
origin.push()
#Git code ends here
return dict(form=form,command=cmd)
class EXISTS(object):
def __init__(self, error_message='file not found'):
self.error_message = error_message
def __call__(self, value):
if os.path.exists(value):
return (value,None)
return (value,self.error_message)

View File

@@ -14,10 +14,7 @@
<p class="controls">
{{else:}}
<h3 class="editableapp">{{=A(a,_href=URL(a,'default','index'))}}</h3>
{{if MULTI_USER_MODE and db.app(name=a):}}{{owner = db.auth_user[db.app(name=a).owner]}}
(created by {{="%(first_name)s %(last_name)s" % owner}}
&lt;{{=A(owner.email, _href='mailto:%s' % owner.email)}}&gt;)
{{pass}}
{{if MULTI_USER_MODE and db.app(name=a):}}(created by {{="%(first_name)s %(last_name)s" % db.auth_user[db.app(name=a).owner]}}){{pass}}
<p class="controls">
{{if not os.path.exists('applications/%s/compiled' % a):}}
{{=sp_button(URL('design',args=a), T("Edit"))}}
@@ -39,12 +36,8 @@
{{pass}}
{{if a!=request.application:}}
{{=button(URL('uninstall',args=a), T("Uninstall"))}}
{{=button_enable(URL('enable',args=a), a)}}
{{=button_enable(URL('enable',args=a), a)}}
{{pass}}
{{if a=='admin' and MULTI_USER_MODE and is_manager():}}
{{=button(URL('default','manage_students'), T('Manage Students'))}}
{{=button(URL('default','bulk_register'), T('Bulk Register'))}}
{{pass}}
</p>
</li>
{{pass}}
@@ -65,19 +58,18 @@
<!-- VERSION -->
{{if is_manager():}}
<div class="box">
<h3>{{=T("Version %s.%s.%s (%s) %s") % myversion}}</h3>
<h3>{{="Version %s.%s.%s (%s) %s" % myversion}}</h3>
{{if session.check_version:}}
<p id="check_version">
{{=T('Checking for upgrades...')}}
<script>ajax('{{=URL('check_version')}}',[],'check_version');</script>{{session.check_version=False}}
</p>
{{else:}}
<p id="check_version">
{{=button("javascript:ajax('"+URL('check_version')+"',[],'check_version')", T('Check for upgrades'))}}
</p>
{{pass}}
</p>
<div class="formfield">
Running on {{=request.env.server_software}}
Running on {{=request.env.server_software}}
</div>
<p>{{=button(URL('default','reload_routes'), T('Reload routes'))}}</p>
</div>
@@ -105,46 +97,46 @@
<h3>{{=T("Upload and install packed application")}}</h3>
<form action="" enctype="multipart/form-data" method="post">
<div class="formfield">
<table>
<table>
<tr>
<td>
{{=LABEL(T("Application name:"), _form='upload_filename')}}
</td>
<td>
<input id="appname" name="filename" type="text" id="upload_filename" />
</td>
</tr>
<tr>
<td>
{{=LABEL(T("Upload a package:"), _for='upload_file')}}
</td>
<td>
<input id="file" name="file" type="file" id="upload_file" />
<b>OR</b>
</td>
<td>
{{=LABEL(T("Application name:"), _form='upload_filename')}}
</td>
<td>
<input id="appname" name="filename" type="text" id="upload_filename" />
</td>
</tr>
<tr>
<td>
{{=LABEL(T("Upload a package:"), _for='upload_file')}}
</td>
<td>
<input id="file" name="file" type="file" id="upload_file" />
<b>OR</b>
</td>
</tr>
<tr>
<tr>
<td>
{{=LABEL(T("Get from URL:"), _for='upload_url')}}
</td>
<td>
<input id="appurl" name="appurl" type="text" id="upload_url"/>
</td>
</tr>
<tr>
<td></td>
{{=LABEL(T("Get from URL:"), _for='upload_url')}}
</td>
<td>
<input id="appurl" name="appurl" type="text" id="upload_url"/>
</td>
</tr>
<tr>
<td></td>
<td>
<input type="checkbox" name="overwrite_check" id="upload_overwrite" />
{{=LABEL(T("Overwrite installed app"), _for='upload_overwrite')}}
</td>
</tr>
<tr>
<td></td>
<td>
<button type="submit">{{=T('Install')}}</button>
</td>
</tr>
</table>
<input type="checkbox" name="overwrite_check" id="upload_overwrite" />
{{=LABEL(T("Overwrite installed app"), _for='upload_overwrite')}}
</td>
</tr>
<tr>
<td></td>
<td>
<button type="submit">{{=T('Install')}}</button>
</td>
</tr>
</table>
</div>
</form>
</div>
@@ -153,6 +145,11 @@
<h3>{{=T("Deploy on Google App Engine")}}</h3>
<p>{{=button(URL('gae','deploy'), T('Deploy'))}}</p>
</div><br/>
<!-- DEPLOY ON OPENSHIFT -->
<div class="box">
<h3>{{=T("Deploy to OpenShift")}}</h3>
<p>{{=button(URL('openshift','deploy'),T('Deploy'))}}</p>
</div><br/>
{{if TWITTER_HASH:}}
<div class="box">
<h3>{{=T("%s Recent Tweets"%TWITTER_HASH)}}</h3>
@@ -164,4 +161,3 @@
{{pass}}
</div>
</div>

View File

@@ -0,0 +1,32 @@
{{extend 'layout.html'}}
<script>$=jQuery</script>
<link rel="stylesheet" type="text/css" href="{{=URL(r=request,c='static',f='css/jqueryMultiSelect.css')}}" />
<script src="{{=URL(r=request,c='static',f='js/jqueryMultiSelect.js')}}"></script>
<script>
function callback() {
$.get('{{=URL(r=request,f='callback')}}','',function(data,status){ if(data!='<done/>') { $('#target').html($('#target').html()+data); callback(); } });
}
$(document).ready(function() {
$('#no_table_applications').multiSelect({selectAll: false});
callback();
});
</script>
<h2>OpenShift Deployment Interface</h2>
<p class="help">{{=T("This page can commit your changes to an openshift app repo and push them to your cloud instance. This assumes that you've already created the application instance using the web2py skeleton and have that repo somewhere on a filesystem that this web2py instance can access. This functionality requires GitPython installed and on the python path of the runtime that web2py is operating in.")}}</p>
<p class="help">{{=T("Note: If you receive an error with github status code of 128, ensure the system and account you are deploying from has a cooresponding ssh key configured in the openshift account.")}}</p>
{{if command:}}
<h3>Command</h3>
<button onclick="$.get('{{=URL(r=request,f='kill')}}');">kill process</button>
{{=CODE(command)}}
<h3>OpenShift Output</h3>
<pre id="target"></pre>
{{else:}}
<h3>Deployment form</h3>
<div class="deploy_form form">
{{=form}}
</div>
{{pass}}