Skip to content

Instantly share code, notes, and snippets.

@minrk
Last active December 20, 2017 14:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save minrk/ed7a0d81615e4f163e124e27e9b05c3d to your computer and use it in GitHub Desktop.
Save minrk/ed7a0d81615e4f163e124e27e9b05c3d to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
"""Script to check binder deployment status
checks:
- binderhub chart has latest hub chart
- mybinder has latest binderhub chart
- mybinder has latest repo2docker image
- mybinder prod is up-to-date with staging
"""
from operator import itemgetter
import requests
from ruamel.yaml import YAML
yaml = YAML(typ='safe')
# get helm-chart index (sorted by date)
r = requests.get('https://jupyterhub.github.io/helm-chart/index.yaml')
r.raise_for_status()
index = yaml.load(r.text)
# construct latest charts for each package,
# and key by version number for later lookup
latest = {}
all_charts = {}
for name, releases in index['entries'].items():
all_charts[name] = charts = {}
for chart in releases:
charts[chart['version']] = chart
ordered = sorted(releases, key=itemgetter('created'))
latest[name] = ordered[-1]
def check_requirements(requirements, name, checking):
print(f"\nChecking version of {name} in {checking} requirements")
want = latest[name]
for req in requirements['dependencies']:
if req['name'] == name:
if req['version'] == want['version']:
print(f"{checking:10} has latest {name}-{req['version']} from {want['created']}")
else:
have = all_charts[name]['v' + req['version']]
print(f"{checking:10} has {name}-{have['version']:14} from {have['created']}")
print(f" latest is {name}-{want['version']:14} from {want['created']}")
return
print(f"Didn't find requirement {name} in {requirements}")
# check if binderhub has latest jupyterhub
r = requests.get('https://rawgithub.com/jupyterhub/binderhub/master/helm-chart/binderhub/requirements.yaml')
r.raise_for_status()
binder_requirements = yaml.load(r.text)
check_requirements(binder_requirements, name='jupyterhub',
checking='binderhub')
# check if mybinder has latest binderhub
r = requests.get('https://raw.githubusercontent.com/jupyterhub/mybinder.org-deploy/staging/mybinder/requirements.yaml')
r.raise_for_status()
mybinder_requirements = yaml.load(r.text)
check_requirements(mybinder_requirements,
name='binderhub', checking='mybinder')
# check that mybinder has latest repo2docker
print("\nChecking repo2docker tag in mybinder deployment")
r = requests.get('https://raw.githubusercontent.com/jupyterhub/mybinder.org-deploy/staging/mybinder/values.yaml')
r.raise_for_status()
values = yaml.load(r.text)
r2dimage, r2dtag = values['binderhub']['repo2dockerImage'].split(':')
r = requests.get(f'https://api.github.com/repos/jupyter/repo2docker/compare/{r2dtag}...master')
r.raise_for_status()
compare = r.json()
print(f"repo2docker master is {compare['ahead_by']} commits ahead of {r2dtag}")
# check that mybinder staging has deployed to prod
print("\nChecking mybinder staging and prod")
r = requests.get('https://api.github.com/repos/jupyterhub/mybinder.org-deploy/compare/prod...staging')
r.raise_for_status()
compare = r.json()
print(f"mybinder staging is {compare['ahead_by']} commits ahead of prod")
@minrk
Copy link
Author

minrk commented Dec 20, 2017

Example output from right now, telling us that binderhub doesn't have the latest jupyterhub helm chart, but everything else is up to date


Checking version of jupyterhub in binderhub requirements
binderhub  has jupyterhub-v0.5.0         from 2017-12-12 03:04:14
    latest is  jupyterhub-v0.5.0-f963312 from 2017-12-13 18:33:39

Checking version of binderhub in mybinder requirements
mybinder   has latest binderhub-0.1.0-c146785 from 2017-12-20 05:24:49.135887

Checking repo2docker tag in mybinder deployment
repo2docker master is 0 commits ahead of 1c7bd6e

Checking mybinder staging and prod
mybinder staging is 0 commits ahead of prod

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment