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

Upgrade while https enabled #347

Merged
merged 2 commits into from
May 28, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
'pluggy>0.7<1.0',
'passlib',
'backoff',
'requests',
'jupyterhub-traefik-proxy==0.1.*'
],
entry_points={
Expand Down
5 changes: 3 additions & 2 deletions tljh/conda.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import hashlib
import contextlib
import tempfile
import urllib.request
import requests
from distutils.version import LooseVersion as V


Expand Down Expand Up @@ -50,7 +50,8 @@ def download_miniconda_installer(version, md5sum):
"""
with tempfile.NamedTemporaryFile() as f:
installer_url = "https://repo.continuum.io/miniconda/Miniconda3-{}-Linux-x86_64.sh".format(version)
urllib.request.urlretrieve(installer_url, f.name)
with open(f.name, 'wb') as f:
f.write(requests.get(installer_url).content)

if md5_file(f.name) != md5sum:
raise Exception('md5 hash mismatch! Downloaded file corrupted')
Expand Down
14 changes: 7 additions & 7 deletions tljh/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
import subprocess
import sys
import time
from urllib.error import HTTPError
from urllib.request import urlopen, URLError

import pluggy
import requests

from tljh import (
apt,
Expand Down Expand Up @@ -293,20 +292,21 @@ def ensure_jupyterhub_running(times=20):
for i in range(times):
try:
logger.info('Waiting for JupyterHub to come up ({}/{} tries)'.format(i + 1, times))
urlopen('http://127.0.0.1')
# We don't care at this level that SSL is valid
requests.get('http://127.0.0.1', verify=False)
return
except HTTPError as h:
if h.code in [404, 502, 503]:
except requests.HTTPError as h:
if h.response.status_code in [404, 502, 503]:
# May be transient
time.sleep(1)
continue
# Everything else should immediately abort
raise
except URLError as e:
if isinstance(e.reason, ConnectionRefusedError):
except requests.ConnectionError:
# Hub isn't up yet, sleep & loop
time.sleep(1)
continue
except Exception:
# Everything else should immediately abort
raise

Expand Down
18 changes: 13 additions & 5 deletions tljh/traefik.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""Traefik installation and setup"""
import hashlib
import os
from urllib.request import urlretrieve, ContentTooShortError

from jinja2 import Template
from passlib.apache import HtpasswdFile
import backoff
import requests

from tljh.configurer import load_config

Expand All @@ -27,11 +27,15 @@ def checksum_file(path):
hasher.update(chunk)
return hasher.hexdigest()

def fatal_error(e):
# Retry only when connection is reset or we think we didn't download entire file
return str(e) != "ContentTooShort" and not isinstance(e, ConnectionResetError)

@backoff.on_exception(
backoff.expo,
# Retry when connection is reset or we think we didn't download entire file
(ConnectionResetError, ContentTooShortError),
max_tries=2
Exception,
max_tries=2,
giveup=fatal_error
)
def ensure_traefik_binary(prefix):
"""Download and install the traefik binary"""
Expand All @@ -53,7 +57,11 @@ def ensure_traefik_binary(prefix):
)
print(f"Downloading traefik {traefik_version}...")
# download the file
urlretrieve(traefik_url, traefik_bin)
response = requests.get(traefik_url)
if response.status_code == 206:
raise Exception("ContentTooShort")
with open(traefik_bin, 'wb') as f:
f.write(response.content)
os.chmod(traefik_bin, 0o755)

# verify that we got what we expected
Expand Down