Skip to content

Commit

Permalink
Merge pull request #48 from anaderi/master
Browse files Browse the repository at this point in the history
scripts to Makefile & web-testing
  • Loading branch information
betatim committed Mar 6, 2016
2 parents b59f465 + 32b9682 commit 2167634
Show file tree
Hide file tree
Showing 17 changed files with 349 additions and 46 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ env.sh
# ignore config file at the top-level of the repo
# but not sub-dirs
/jupyterhub_config.py
/jupyterhub_config_test.py
jupyterhub_cookie_secret
jupyterhub.sqlite
jupyterhub.log
Expand All @@ -20,3 +21,5 @@ MANIFEST
htmlcov
whitelist.txt
*.swp
*.log
*.pid
57 changes: 40 additions & 17 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,52 @@ language: python
sudo: required
services:
- docker

addons:
apt:
packages:
- build-essential

apt:
packages:
- build-essential
python:
- 3.5
- 3.4
env:
- JHUB_VERSION=master
- JHUB_VERSION=latest # latest released version
# commented out for testing speed-up sake
# - 3.4
# env:
# - JHUB_VERSION=master
# - JHUB_VERSION=latest # latest released version

before_install:
- npm install
- npm install -g configurable-http-proxy
- git clone --quiet --depth 1 https://github.com/minrk/travis-wheels travis-wheels
install: ./build_tools/travis/install.sh
- git clone --quiet --depth 1 https://github.com/minrk/travis-wheels travis-wheels
# some DEBUG information
- which python
- pip --version
- pip freeze
- npm list

script:
- nose2 -v --start-dir everware # unit tests live in everware/
- ./build_tools/travis/test_frontend.sh
install:
- npm install -g gistup
- export PIP_OPTIONS="-f ~/travis-wheels/wheelhouse"
- make install
# - ./build_tools/travis/install.sh

# Make travis quiet
script:
- FAIL=0
- nose2 -v --start-dir everware # unit tests live in everware/
# - ./build_tools/travis/test_frontend.sh
- make run-test-server
- make test-client || FAIL=1
- make stop
# will continue on it a bit later
# - make upload_screens
- cat everware.log
- test "$FAIL" == "0"
cache:
apt: true
directories:
- $HOME/.cache/pip
notifications:
email: false
webhooks:
urls:
- https://webhooks.gitter.im/e/778f542a122b7dd8c0f3
on_success: always # options: [always|never|change] default: always
on_failure: always # options: [always|never|change] default: always
on_start: always
120 changes: 120 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Makefile for building & starting rep-containers
# arguments can be supplied by -e definitions:
#
# TESTS -- list of tests to run
# M -- commit message
#
#

SHELL := /bin/bash
TEST_OPTIONS := -s tests -N 2
TESTS := test_happy_mp
LOG := everware.log
PIDFILE := everware.pid
IP = $(shell python -c 'from IPython.utils.localinterfaces import public_ips; print (public_ips()[0])' 2>/dev/null)
OPTIONS = --debug --port 8000 --no-ssl --JupyterHub.hub_ip=${IP}
IS_DOCKER_MACHINE := $(shell which docker-machine > /dev/null ; echo $$?)
UPLOADDIR = ~/upload_screens
ifeq (0, $(IS_DOCKER_MACHINE))
SPAWNER_IP = "192.168.99.100"
else
SPAWNER_IP = "127.0.0.1"
endif

.PHONY: install reload clean run run-daemon run-test stop test-client tail

help:
@echo Usage: make [-e VARIABLE=VALUE] targets
@echo "variables:"
@grep -h "#\s\+\w\+ -- " $(MAKEFILE_LIST) |sed "s/#\s//"
@echo
@echo targets and corresponding dependencies:
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' -e 's/^/ /' | sed -e 's/##//'


install: ## install everware
npm install
npm install -g configurable-http-proxy
PYTHON_MAJOR=`python -c 'import sys; print(sys.version_info[0])'` ;\
if [ $${PYTHON_MAJOR} -eq 3 ] ; then \
PYTHON=python ;\
PIP=pip ;\
elif [ -n `which python3` ] ; then \
PYTHON=python3 ;\
PIP=pip3 ;\
else \
echo "Unable to find python" ;\
exit 1 ;\
fi ;\
$${PIP} install $${PIP_OPTIONS} -r requirements.txt && \
$${PIP} install -e . && \
$${PYTHON} setup.py css && \
$${PYTHON} setup.py js

if [ ! -f env.sh ] ; then cp env.sh.orig env.sh ; fi
if [ ! -f jupyterhub_config.py ] ; then cp jupyterhub_config.py.orig jupyterhub_config.py ; fi
if [ ! -f whitelist.txt ] ; then cp whitelist.txt.orig whitelist.txt ; fi

reload: ## reload everware whitelist
PID=`pgrep -f jupyterhub` ;\
if [ -z "$${PID}" ] ; then echo "Cannot find ${PIDFILE}" ; exit 1 ; fi
pkill -1 -f jupyterhub

clean: ## clean user base
if [ -f ${PIDFILE} ] ; then echo "${PIDFILE} exists, cannot continute" ; exit 1; fi
rm -f jupyterhub.sqlite

run: clean ## run everware server
source ./env.sh && \
jupyterhub ${OPTIONS}

run-daemon: clean
source ./env.sh && \
jupyterhub ${OPTIONS} >> ${LOG} 2> /dev/null &
@sleep 1
pgrep -f jupyterhub > ${PIDFILE} || ( tail ${LOG} && exit 1 )
echo "Started. Log saved to ${LOG}"

stop: ${PIDFILE}
kill -9 `cat ${PIDFILE}`
pkill -9 -f configurable-http-proxy
rm ${PIDFILE}

run-test-server: clean ## run everware instance for testing (no auth)
cat jupyterhub_config.py <(echo c.JupyterHub.authenticator_class = 'dummyauthenticator.DummyAuthenticator') \
<(echo c.Spawner.container_ip = \'${SPAWNER_IP}\') \
> jupyterhub_config_test.py
source ./env.sh && \
export EVERWARE_WHITELIST= ; \
jupyterhub ${OPTIONS} --JupyterHub.config_file=jupyterhub_config_test.py >& ${LOG} &
@sleep 1
pgrep -f jupyterhub > ${PIDFILE} || exit 1
echo "Started. Log saved to ${LOG}"

logs: ${LOG} ## watch log file
tail -f ${LOG}

test-client: ## run tests
export UPLOADDIR=${UPLOADDIR} ; \
nose2 ${TEST_OPTIONS} ${TESTS}

diff: ## git diff
git diff

cmp: ## commit -m push
git commit -am "${M}" && git push

upload_screens:
@which gistup > /dev/null || (echo "setup https://github.com/mbostock/gistup first" && exit 1 )
@if [[ ! -f ~/.gistup.json ]] ; then \
if [ -n "$${GIST_TOKEN}" ] ; then \
echo "{\"token\": \"$${GIST_TOKEN}\" }" > ~/.gistup.json ; \
else \
echo "no GIST_TOKEN specified. exit"; exit 1; \
fi ; \
fi
if [ -d ${UPLOADDIR} ] ; then \
rm -rf ${UPLOADDIR}/.git ; \
cd ${UPLOADDIR} ; \
gistup --no-open; \
fi
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions env.sh.orig
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export GITHUB_CLIENT_ID=
export GITHUB_CLIENT_SECRET=
export OAUTH_CALLBACK_URL="http://localhost:8000/hub/oauth_callback"
export EVERWARE_WHITELIST="whitelist.txt"
File renamed without changes.
File renamed without changes.
22 changes: 14 additions & 8 deletions everware/authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,25 @@ def __init__(self, filename, config, authenticator):
super().__init__()
self.filename = filename
self.authenticator = authenticator
authenticator.whitelist = set(x.rstrip() for x in open(filename))
if os.path.exists(filename):
authenticator.whitelist = set(x.rstrip() for x in open(filename))
else:
authenticator.whitelist = set()
config.Authenticator.whitelist = authenticator.whitelist
signal.signal(signal.SIGHUP, self.reload_whitelist)


def reload_whitelist(self, signal, frame):
self.authenticator.whitelist = set(
x.rstrip() for x in open(self.filename)
)
self.log.info(
'Whitelist reloaded:\n%s',
'\n'.join(self.authenticator.whitelist)
)
if os.path.exists(self.filename):
self.authenticator.whitelist = set(
x.rstrip() for x in open(self.filename)
)
self.log.info(
'Whitelist reloaded:\n%s',
'\n'.join(self.authenticator.whitelist)
)
else:
self.log.info("whitelist file (%s) not found" % self.filename)


class GitHubMixin(OAuth2Mixin):
Expand Down
Empty file removed frontend_tests/.empty
Empty file.
12 changes: 7 additions & 5 deletions jupyterhub_config.py.orig
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import os
import everware
import jupyterhub.handlers.pages
import jupyterhub.handlers.base
import dummyauthenticator

# TODO: find a way to change default handlers
# instead of this shit
Expand All @@ -18,14 +19,15 @@ c.JupyterHub.spawner_class = 'everware.CustomDockerSpawner'
#c.JupyterHub.spawner_class = 'everware.CustomSwarmSpawner'

# The docker instances need access to the Hub, so the default loopback port doesn't work:
# Find it easier to hardcode the IP of the machine it is deployed on
ip_addr = '192.168.0.39'
c.JupyterHub.hub_ip = ip_addr
c.JupyterHub.hub_api_ip = ip_addr
# (IP addrress setting is overriden by command line argument at Makefile)
# ip_addr = '192.168.0.39'
# c.JupyterHub.hub_ip = ip_addr
# c.JupyterHub.hub_api_ip = ip_addr

authenticator = everware.GitHubOAuthenticator
c.JupyterHub.authenticator_class = '%s.%s' % (authenticator.__module__, authenticator.__name__)
whitelist_file = 'whitelist.txt'
# whitelist_file = 'whitelist.txt'
whitelist_file = os.environ['EVERWARE_WHITELIST']
whitelist_handler = everware.DefaultWhitelistHandler(whitelist_file, c, authenticator)
c.GitHubOAuthenticator.oauth_callback_url = os.environ['OAUTH_CALLBACK_URL']
c.GitHubOAuthenticator.client_id = os.environ['GITHUB_CLIENT_ID']
Expand Down
4 changes: 0 additions & 4 deletions reload.sh

This file was deleted.

8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
ipython[notebook]
coveralls
nose2
selenium
jupyterhub-dummyauthenticator
jupyterhub
dockerspawner
GitPython==1.0.1
selenium
-e git+https://github.com/jupyter/jupyterhub.git#egg=jupyterhub
-e git+https://github.com/jupyter/dockerspawner.git#egg=dockerspawner
-e git+https://github.com/yuvipanda/jupyterhub-dummy-authenticator.git#egg=dummyauthenticator
8 changes: 0 additions & 8 deletions run.sh

This file was deleted.

0 comments on commit 2167634

Please sign in to comment.