Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ In order to deploy your own `everware` instance, you have to:
everware-server -f etc/local_config.py --debug --no-ssl
```

Everware can also be deployed in a Docker container. See [Everware in Docker container](docker.md)
Everware can also be deployed in a Docker container. See [Everware in Docker container](docs/docker.md)


## Development
Expand Down
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"jquery": "components/jquery#~2.0",
"moment": "~2.7",
"requirejs": "~2.1",
"material-design-lite": "^1.1.3"
"material-design-lite": "^1.1.3",
"clipboard": "^1.6.1"
}
}
3 changes: 3 additions & 0 deletions etc/base_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
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. Default: True
# c.Spawner.share_user_images = False

# c.Authenticator.admin_users = {'anaderi', 'astiunov'}

# The docker containers need access to the Hub API, so the default
Expand Down
35 changes: 35 additions & 0 deletions everware/home_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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."""
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion everware/spawner.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
from traitlets import (
Integer,
Unicode,
Int
Int,
Bool
)
from tornado import gen
from tornado.httpclient import HTTPError
Expand Down Expand Up @@ -251,12 +252,19 @@ def wait_up(self):
yield self.notify_about_fail(message)
raise e

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):
"""download the repo and build a docker image if needed"""
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.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)

image = yield self.get_image(image_name)
if image is None:
raise Exception('Image %s doesn\'t exist' % image_name)
Expand Down
14 changes: 13 additions & 1 deletion share/static/html/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
{% else %}
<p>You don't have a repository with the same name. Do you want to <a id="push" class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--colored small-button" href="/hub/home?do_fork=1">fork</a> it?</p>
{% endif %}
<p>Also you can <a id="commit-container" class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--colored small-button" href="/hub/home?do_commit_container=1">save container</a> to easily restore your work later.</p>
{% endif %}
</div>
</div>
Expand Down Expand Up @@ -70,12 +71,23 @@
>
{{notify_message}}
</div>
{% if notify_url_to_image %}
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label" style="width: 700px">
<input class="mdl-textfield__input" type="text" id="notify-url" value="{{notify_url_to_image}}" readonly>
<label class="mdl-textfield__label" for="notify-url">Your link to restore state</label>
</div>
<button class="mdl-button mdl-js-button mdl-button--icon notify-url--button" data-clipboard-target="#notify-url" title="Copy to clipboard">
<i class="material-icons">content_copy</i>
</button>
{% endif %}
</div>

{% endblock %}

{% block script %}
<script type="text/javascript">
require(["home"]);
require(["home", "clipboard"], function (home, Clipboard) {
new Clipboard('.notify-url--button');
});
</script>
{% endblock %}
1 change: 1 addition & 0 deletions share/static/html/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ <h4 class="modal-title" id="{{key}}-label">{{title}}</h4>
jquery: '../components/jquery/jquery.min',
bootstrap: '../components/bootstrap/js/bootstrap.min',
moment: "../components/moment/moment",
clipboard: "../components/clipboard/dist/clipboard.min",
},
shim: {
bootstrap: {
Expand Down
21 changes: 19 additions & 2 deletions share/static/html/spawn.html
Original file line number Diff line number Diff line change
Expand Up @@ -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:
<ul>
<li><a href="https://github.com/everware/everware-dimuon-example">https://github.com/everware/everware-dimuon-example</a></li>
<li><a href="https://github.com/betatim/everware-demo">https://github.com/betatim/everware-demo</a></li>
<li>
<a id="clipboard-example-1" href="https://github.com/everware/everware-dimuon-example">https://github.com/everware/everware-dimuon-example</a>
<button class="mdl-button mdl-js-button mdl-button--icon clipboard-example--button" data-text-source="clipboard-example-1" title="Copy to form">
<i class="material-icons">content_copy</i>
</button>
</li>
<li>
<a id="clipboard-example-2" href="https://github.com/betatim/everware-demo">https://github.com/betatim/everware-demo</a>
<button class="mdl-button mdl-js-button mdl-button--icon clipboard-example--button" data-text-source="clipboard-example-2" title="Copy to form">
<i class="material-icons">content_copy</i>
</button>
</li>
</ul>
Read the documentation
to <a href="https://github.com/everware/everware/wiki/Being-everware-compatible">learn
Expand All @@ -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');
});
});
</script>
{% endblock %}