Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temporary page while tljh is building #605

Merged
merged 21 commits into from
Sep 14, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 43 additions & 1 deletion bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
- Use stdlib modules only
"""
import os
from http.server import SimpleHTTPRequestHandler, HTTPServer
import multiprocessing
import subprocess
import sys
import logging
import shutil
import urllib.request

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -90,7 +93,47 @@ def validate_host():
print("For local development, see http://tljh.jupyter.org/en/latest/contributing/dev-setup.html")
sys.exit(1)

class LoaderPageRequestHandler(SimpleHTTPRequestHandler):
def do_GET(self):
if self.path == "/logs":
with open("/opt/tljh/installer.log", "rb") as log_file:
content = log_file.read()
self.wfile.write(content)
elif self.path == "/index.html" or self.path == "/favicon.ico":
return SimpleHTTPRequestHandler.do_GET(self)
elif self.path == "/":
self.send_response(302)
self.send_header('Location','/index.html')
self.end_headers()
else:
SimpleHTTPRequestHandler.send_error(self, code=403)

def serve_forever(server):
try:
server.serve_forever()
except KeyboardInterrupt:
pass

def main():
temp_page_flag = "--temporary-page"
if temp_page_flag in sys.argv:
GeorgianaElena marked this conversation as resolved.
Show resolved Hide resolved
# Serve the loading page until TLJH builds
index_url="https://raw.githubusercontent.com/GeorgianaElena/the-littlest-jupyterhub/in-progress-page/bootstrap/index.html"
GeorgianaElena marked this conversation as resolved.
Show resolved Hide resolved
favicon_url="https://raw.githubusercontent.com/jupyterhub/jupyterhub/master/share/jupyterhub/static/favicon.ico"
urllib.request.urlretrieve(index_url, "index.html")
urllib.request.urlretrieve(favicon_url, "favicon.ico")

# If the bootstrap is run to upgrade TLJH, then this will raise an "Address already in use" error
try:
loading_page_server = HTTPServer(("", 80), LoaderPageRequestHandler)
p = multiprocessing.Process(target=serve_forever, args=(loading_page_server,))
p.start()
# Put the pid after the temp page flag to be passed to the istaller
sys.argv.insert(sys.argv.index(temp_page_flag)+1, str(p.pid))
GeorgianaElena marked this conversation as resolved.
Show resolved Hide resolved
except OSError:
# Only serve the loading page when installing TLJH
pass

validate_host()
install_prefix = os.environ.get('TLJH_INSTALL_PREFIX', '/opt/tljh')
hub_prefix = os.path.join(install_prefix, 'hub')
Expand Down Expand Up @@ -178,6 +221,5 @@ def main():
] + sys.argv[1:]
)


if __name__ == '__main__':
main()
54 changes: 54 additions & 0 deletions bootstrap/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<!DOCTYPE html>
<head>
<body>
GeorgianaElena marked this conversation as resolved.
Show resolved Hide resolved
<meta http-equiv="refresh" content="30" >
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width">
<img style="width: 150px; height: auto;" src="https://raw.githubusercontent.com/jupyterhub/the-littlest-jupyterhub/master/docs/images/logo/logo.png">
<div class="loader center"></div>
<div class="center" style="font-size: 30px; font-weight: bold; color: grey; text-align:center;">Please wait while your TLJH is building...</div>
GeorgianaElena marked this conversation as resolved.
Show resolved Hide resolved
<div class="center" style="font-size: 15px; color: grey;">Click the button below to see the logs</div>
<div class="center" style="font-size: 13px; color: grey; margin-top: 10px; font-style: italic;">Tip: to update the logs, refresh the page</div>
<button class="logs-button center" onclick="window.location.href='/logs'">View logs</button>
</body>

<style>
button:hover {
background: grey;
}

.center {
margin: 0 auto;
margin-top: 50px;
text-align:center;
display: block;
}
.logs-button {
margin-top:15px;
border: 0;
color: white;
padding: 15px 32px;
font-size: 16px;
cursor: pointer;
background: #f5a252;
}
.loader {
width: 150px;
height: 150px;
border-radius: 90%;
border: 7px solid transparent;
animation: spin 2s infinite ease;
animation-direction: alternate;
}
@keyframes spin {
0% {
transform: rotateZ(0deg);
border-top-color: #f17c0e
}
100% {
transform: rotateZ(360deg);
border-top-color: #fce5cf;
}
}
</style>
</head>
16 changes: 16 additions & 0 deletions tljh/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import logging
import os
import secrets
import signal
import subprocess
import sys
import time
Expand Down Expand Up @@ -485,6 +486,10 @@ def main():
nargs='*',
help='Plugin pip-specs to install'
)
argparser.add_argument(
'--temporary-page',
GeorgianaElena marked this conversation as resolved.
Show resolved Hide resolved
help='Serve a temporary page while TLJH is building'
)

args = argparser.parse_args()

Expand All @@ -499,6 +504,17 @@ def main():
ensure_node()
ensure_jupyterhub_package(HUB_ENV_PREFIX)
ensure_jupyterlab_extensions()

# Stop the http server with the loading page before traefik starts
if args.temporary_page:
try:
os.kill(int(args.temporary_page), signal.SIGINT)
# Remove the pid file and the temporary html page
os.remove('/index.html')
GeorgianaElena marked this conversation as resolved.
Show resolved Hide resolved
os.remove('/favicon.ico')
except Exception as e:
pass
GeorgianaElena marked this conversation as resolved.
Show resolved Hide resolved

ensure_jupyterhub_service(HUB_ENV_PREFIX)
ensure_jupyterhub_running()
ensure_symlinks(HUB_ENV_PREFIX)
Expand Down