@@ -8,6 +8,7 @@
from . import __version__
from .github_agent import *
from .metrica import MetricaIdsMixin
+from datetime import datetime
@gen.coroutine
def is_repository_changed (user ):
@@ -30,6 +31,32 @@ def is_repository_changed(user):
else :
return False
+@gen.coroutine
+def commit_container (request , spawner , log ):
+ image_tag = datetime.now().strftime(' %Y-%m-%d _%H-%M-%S' )
+ image_name = ' everware_image/' + spawner.escaped_name + ' /' + spawner.escaped_repo_url + ' _' + spawner.container_id
+ host_with_protocol = request.protocol + ' ://' + request.host
+ url_with_image = url_concat(host_with_protocol + ' /hub/spawn' ,
+ dict (repourl = ' docker:' + image_name + ' :' + image_tag))
+
+ log.info(' Will commit %s ' % url_with_image)
+
+ commit = yield spawner.docker(
+ ' commit' ,
+ container = spawner.container_id,
+ repository = image_name,
+ tag = image_tag,
+ message = ' Commit from control panel' ,
+ author = spawner.escaped_name
+ )
+
+ output_data = dict ()
+ if commit:
+ output_data[' url_with_image' ] = url_with_image
+ else :
+ output_data[' message' ] = ' Sorry, can not save container'
+
+ return output_data
class HomeHandler (BaseHandler ):
""" Render the user's home page."""
@@ -43,7 +70,9 @@ def get(self):
do_fork = self .get_argument(' do_fork' , False )
do_push = self .get_argument(' do_push' , False )
+ do_commit_container = self .get_argument(' do_commit_container' , False )
notify_message = self .get_argument(' message' , ' ' )
+ notify_url_to_image = self .get_argument(' url_with_image' , ' ' )
if repourl:
self .redirect(url_concat(
url_path_join(self .hub.server.base_url, ' spawn' ), all_arguments
@@ -58,6 +87,11 @@ def get(self):
branch_name = user.spawner.branch_name
commit_sha = user.spawner.commit_sha
repo_url = user.spawner.repo_url
+
+ if user.running and do_commit_container:
+ output_data = yield commit_container(self .request, user.spawner, self .log)
+ self .redirect(url_concat(' /hub/home' , output_data))
+
if user.running and getattr (user, ' login_service' , ' ' ) == ' github' :
if do_fork:
self .log.info(' Will fork %s ' % user.spawner.repo_url)
@@ -104,6 +138,7 @@ def get(self):
branch_name = branch_name,
commit_sha = commit_sha,
notify_message = notify_message,
+ notify_url_to_image = notify_url_to_image,
version = __version__ ,
g_analitics_id = g_id,
ya_metrica_id = ya_id