diff --git a/etc/base_config.py b/etc/base_config.py index 80a8d1a..eeb540e 100644 --- a/etc/base_config.py +++ b/etc/base_config.py @@ -14,8 +14,8 @@ c.Spawner.remove_containers = True c.Spawner.tls_assert_hostname = False c.Spawner.use_docker_client_env = True -# give users an opportunity to restore any images via docker or not: -# c.Spawner.user_images_check = False +# give users an opportunity to restore any images via docker or not. Default: True +# c.Spawner.share_user_images = False # c.Authenticator.admin_users = {'anaderi', 'astiunov'} diff --git a/everware/home_handler.py b/everware/home_handler.py index 8529971..e3db85f 100755 --- a/everware/home_handler.py +++ b/everware/home_handler.py @@ -31,6 +31,33 @@ def is_repository_changed(user): else: return False +@gen.coroutine +def commit_container(request, user, log): + spawner = user.spawner + 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.""" @@ -44,7 +71,7 @@ def get(self): do_fork = self.get_argument('do_fork', False) do_push = self.get_argument('do_push', False) - do_commit = self.get_argument('do_commit', 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: @@ -62,25 +89,9 @@ def get(self): commit_sha = user.spawner.commit_sha repo_url = user.spawner.repo_url - if user.running and do_commit: - spawner = user.spawner - 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 = self.request.protocol + '://' + self.request.host - url_with_image = url_concat(host_with_protocol + '/hub/spawn', dict(repourl='docker:' + image_name + ':' + image_tag)) - - self.log.info('Will commit %s' % url_with_image) - - spawner.client.commit( - container=spawner.container_id, - repository=image_name, - tag=image_tag, - message='Commit from control panel', - author=spawner.escaped_name - ) - - self.redirect(url_concat('/hub/home', dict(url_with_image=url_with_image))) - return + if user.running and do_commit_container: + output_data = yield commit_container(self.request, user, self.log) + self.redirect(url_concat('/hub/home', output_data)) if user.running and getattr(user, 'login_service', '') == 'github': if do_fork: diff --git a/everware/spawner.py b/everware/spawner.py index 089cf61..0eb461f 100755 --- a/everware/spawner.py +++ b/everware/spawner.py @@ -252,7 +252,7 @@ def wait_up(self): yield self.notify_about_fail(message) raise e - user_images_check = Bool(default_value=True, config=True, help="If True, users will be able restore only own images") + share_user_images = Bool(default_value=True, config=True, help="If True, users will be able restore only own images") @gen.coroutine def build_image(self): @@ -260,7 +260,7 @@ def build_image(self): if self.form_repo_url.startswith('docker:'): image_name = self.form_repo_url.replace('docker:', '') - if image_name.startswith('everware_image') and not self.user.admin and self.user_images_check: + if image_name.startswith('everware_image') and not self.user.admin and self.share_user_images: images_user = image_name.split('/')[1] if self.escaped_name != images_user: raise Exception('Access denied. Image %s is not yours.' % image_name) diff --git a/share/static/html/home.html b/share/static/html/home.html index 223cf3e..9c00091 100755 --- a/share/static/html/home.html +++ b/share/static/html/home.html @@ -21,7 +21,7 @@ {% else %}

You don't have a repository with the same name. Do you want to fork it?

{% endif %} -

Also you can save current state. You will be able easily restore your work later. Just commit it!

+

Also you can save container to easily restore your work later.

{% endif %} @@ -76,7 +76,7 @@ - {% endif %} @@ -87,7 +87,7 @@ {% block script %} {% endblock %} diff --git a/share/static/html/spawn.html b/share/static/html/spawn.html index 9dabc83..1caf5c0 100755 --- a/share/static/html/spawn.html +++ b/share/static/html/spawn.html @@ -23,8 +23,18 @@ Paste the link to the git repository you want to try out. If you need some inspiration try one of the following repositories: Read the documentation to learn @@ -49,6 +59,13 @@ return false; } }); + + $('.clipboard-example--button').click(function (e) { + var input = $('#repository_input'); + var linkId = $(e.currentTarget).attr('data-text-source'); + var href = $('#' + linkId).attr('href'); + input.val(href).parent().addClass('is-focused'); + }); }); {% endblock %}