From 16583e7cbf355c5ebefbfdff3661621b400c819c Mon Sep 17 00:00:00 2001 From: Andrey U Date: Tue, 4 Apr 2017 21:38:41 +0300 Subject: [PATCH] updated configs and makefile to deploy everware as docker image --- Makefile | 36 +---------------------- docker.md => docs/docker.md | 2 -- env.docker-remote.orig | 2 ++ env.docker-swarm.orig | 2 ++ etc/container_config.py | 9 +++--- etc/container_swarm_config.py | 2 +- run.makefile | 67 +++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 77 insertions(+), 43 deletions(-) rename docker.md => docs/docker.md (94%) create mode 100644 run.makefile diff --git a/Makefile b/Makefile index 639b5e9..be7784a 100644 --- a/Makefile +++ b/Makefile @@ -9,8 +9,6 @@ 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} UPLOADDIR ?= ~/upload_screens @@ -27,14 +25,13 @@ else $(error Unable to find python) endif -EXECUTOR = everware-server - ifeq ($(shell uname -s),Linux) SPAWNER_IP = "127.0.0.1" else SPAWNER_IP = "192.168.99.100" endif +include run.makefile .PHONY: install reload clean run run-daemon stop test tail @@ -56,37 +53,6 @@ install: ## install everware if [ ! -f env.sh ] ; then cp env.sh.orig env.sh ; fi -reload: ## reload everware whitelist - PID=`pgrep '${EXECUTOR}'` ;\ - if [ -z "$${PID}" ] ; then echo "Cannot find running ${EXECUTOR}" ; exit 1 ; fi - pkill -1 '${EXECUTOR}' - -clean: ## clean user base - if [ -f ${PIDFILE} ] ; then echo "${PIDFILE} exists, cannot continute" ; exit 1; fi - rm -f jupyterhub.sqlite - -run-linux: clean ## run everware server on linux - source ./env.sh && \ - ${EXECUTOR} -f etc/local_config.py --no-ssl 2>&1 | tee ${LOG} - -run-dockermachine: clean ## run everware server on MacOS - source ./env.sh && \ - ${EXECUTOR} -f etc/local_dockermachine_config.py --no-ssl 2>&1 | tee ${LOG} - -run-daemon: clean ## run everware in daemon mode, linux only, SSL required - source ./env.sh && \ - ${EXECUTOR} -f etc/local_config.py >> ${LOG} 2>&1 & - pgrep ${EXECUTOR} > ${PIDFILE} || ( tail ${LOG} && exit 1 ) - echo "Started. Log saved to ${LOG}" - -stop: - -rm ${PIDFILE} - -pkill -9 ${EXECUTOR} - -pkill -9 node - -logs: ${LOG} ## watch log file - tail -f ${LOG} - test: ## run all tests export UPLOADDIR=${UPLOADDIR}; \ py.test everware/ ; \ diff --git a/docker.md b/docs/docker.md similarity index 94% rename from docker.md rename to docs/docker.md index 6f8fd2d..60b0548 100644 --- a/docker.md +++ b/docs/docker.md @@ -11,8 +11,6 @@ This section explains how to run Everware in a container, and the different poss docker build -t everware . ``` -JupyterHub Dockerfile needs a ["jupyterhub_config.py"](jupyterhub_config.py) file to be present at the root of the project. - ## Create user containers on same machine as the Everware one Fill the file which will contains environment variables for Everware. diff --git a/env.docker-remote.orig b/env.docker-remote.orig index 62ce772..75eef6e 100644 --- a/env.docker-remote.orig +++ b/env.docker-remote.orig @@ -3,3 +3,5 @@ GITHUB_CLIENT_SECRET= OAUTH_CALLBACK_URL=http://xxxxxxxx:8000/hub/oauth_callback EVERWARE_WHITELIST=whitelist.txt DOCKER_HOST=tcp://xxx.xxx.xxx.xxx:2376 +# most likely the same IP as DOCKER_HOST +DOCKER_PUBLIC_IP=xxx.xxx.xxx.xxx diff --git a/env.docker-swarm.orig b/env.docker-swarm.orig index 8495b76..7178d7c 100644 --- a/env.docker-swarm.orig +++ b/env.docker-swarm.orig @@ -5,3 +5,5 @@ EVERWARE_WHITELIST=whitelist.txt DOCKER_CERT_PATH=/etc/docker DOCKER_HOST=tcp://xxx.xxx.xxx.xxx:2376 DOCKER_TLS_VERIFY=1 +# most likely the same IP as DOCKER_HOST +DOCKER_PUBLIC_IP=xxx.xxx.xxx.xxx diff --git a/etc/container_config.py b/etc/container_config.py index 7730a12..06620cb 100644 --- a/etc/container_config.py +++ b/etc/container_config.py @@ -11,8 +11,7 @@ c.JupyterHub.hub_ip = '0.0.0.0' c.JupyterHub.proxy_api_ip = '0.0.0.0' -# Change these two next settings: -# IP of the machine where the Everware can be contacted -c.DockerSpawner.hub_ip_connect = 'xxx.xxx.xxx.xxx' -# IP of the machine running Docker service -c.DockerSpawner.container_ip = 'xxx.xxx.xxx.xxx' +# IP of the machine where the Everware (run as docker container) can be contacted +c.DockerSpawner.hub_ip_connect = os.environ['DOCKER_PUBLIC_IP'] +# IP of the machine running Docker service, normally the same as above +c.DockerSpawner.container_ip = c.DockerSpawner.hub_ip_connect diff --git a/etc/container_swarm_config.py b/etc/container_swarm_config.py index 8db0926..e9a7262 100644 --- a/etc/container_swarm_config.py +++ b/etc/container_swarm_config.py @@ -18,4 +18,4 @@ # Change this setting: # IP of the machine where the Everware can be contacted -c.DockerSpawner.hub_ip_connect = 'xxx.xxx.xxx.xxx' +c.DockerSpawner.hub_ip_connect = os.environ['DOCKER_PUBLIC_IP'] diff --git a/run.makefile b/run.makefile new file mode 100644 index 0000000..06bf43b --- /dev/null +++ b/run.makefile @@ -0,0 +1,67 @@ +HERE=$(shell pwd) +LOG := everware.log +PIDFILE := everware.pid +EXECUTOR = everware-server + +reload: ## reload everware whitelist + PID=`pgrep '${EXECUTOR}'` ;\ + if [ -z "$${PID}" ] ; then echo "Cannot find running ${EXECUTOR}" ; exit 1 ; fi + pkill -1 '${EXECUTOR}' + +clean: ## clean user base + if [ -f ${PIDFILE} ] ; then echo "${PIDFILE} exists, cannot continute" ; exit 1; fi + rm -f jupyterhub.sqlite + +run-linux: clean ## run everware server on linux + source ./env.sh && \ + ${EXECUTOR} -f etc/local_config.py --no-ssl 2>&1 | tee ${LOG} + +run-dockermachine: clean ## run everware server on MacOS + source ./env.sh && \ + ${EXECUTOR} -f etc/local_dockermachine_config.py --no-ssl 2>&1 | tee ${LOG} + +run-daemon: clean ## run everware in daemon mode, linux only, SSL required + source ./env.sh && \ + ${EXECUTOR} -f etc/local_config.py >> ${LOG} 2>&1 & + pgrep ${EXECUTOR} > ${PIDFILE} || ( tail ${LOG} && exit 1 ) + echo "Started. Log saved to ${LOG}" + +stop: + -rm ${PIDFILE} + -pkill -9 ${EXECUTOR} + -pkill -9 node +run-docker-local: + docker run -d --name everware \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -v ${HERE}/etc/container_config.py:/srv/everware/etc/container_config.py \ + --env-file=env.docker-local \ + -p 8000:8000 \ + -p 8081:8081 \ + everware/everware:latest /srv/everware/etc/container_config.py --no-ssl --debug + +run-docker-remote: + docker run -d --name everware \ + -v ${HERE}/etc/container_config.py:/srv/everware/etc/container_config.py \ + --env-file=env.docker-remote \ + -p 8000:8000 \ + -p 8081:8081 \ + everware/everware:latest /srv/everware/etc/container_config.py --no-ssl --debug + +run-docker-swarm: + docker run -d --name everware \ + -v ${HERE}/etc/container_swarm_config.py:/srv/everware/etc/container_swarm_config.py \ + --env-file=env.docker-swarm \ + -p 8000:8000 \ + -p 8081:8081 \ + everware/everware:latest /srv/everware/etc/container_swarm_config.py --no-ssl --debug + +stop-docker: + docker stop everware + docker rm everware + +stop-docker-swarm: + bash -c "source env.docker-swarm && docker stop everware && docker rm everware" + +logs: ${LOG} ## watch log file + tail -f ${LOG} +