diff --git a/.gitignore b/.gitignore index c511c15..c0b9672 100644 --- a/.gitignore +++ b/.gitignore @@ -113,8 +113,3 @@ venv.bak/ # Added config to hide hash of changed password src/jupyter_notebook_config.json .idea -Deployment-notes.md -add-to-swarm-with-defaults.sh -add-to-swarm.sh -remove-from-swarm.sh -docker-compose-swarm.yml diff --git a/Deployment-notes.md b/Deployment-notes.md new file mode 100644 index 0000000..a09aa71 --- /dev/null +++ b/Deployment-notes.md @@ -0,0 +1,37 @@ +# Deployment Notes + +## Push image with tag to Dockerhub + +Based on [this](https://ropenscilabs.github.io/r-docker-tutorial/04-Dockerhub.html) tutorial +with the tag `v1.0_cuda-10.1_ubuntu-18.04`: + +```bash +# on il048: +cd ~/Documents/projects/GPU-Jupyter/gpu-jupyter +git pull +bash generate_Dockerfile.sh +bash start-local -p 1234 +docker image ls +docker tag [IMAGE ID] cschranz/gpu-jupyter:v1.0_cuda-10.1_ubuntu-18.04 +docker push cschranz/gpu-jupyter:v1.0_cuda-10.1_ubuntu-18.04 +docker save cschranz/gpu-jupyter > ../gpu-jupyter_tag-v1.0_cuda-10.1_ubuntu-18.04.tar +``` + +Then, the new tag is available on [Dockerhub](https://hub.docker.com/repository/docker/cschranz/gpu-jupyter/tags). + + +## Deployment in the swarm + +The GPU-Jupyter instance for deployment, that has swarm files and changed pw is +in `/home/iotdev/Documents/projects/dtz/src/gpu-jupyter` + +```bash +# on il048: +cd /home/iotdev/Documents/projects/dtz/src/gpu-jupyter +git pull +bash generate_Dockerfile.sh +bash add-to-swarm-with-defaults.sh +``` + +Then, the service will be available with data stored in `data` +on [192.168.48.48:8848](http://192.168.48.48:8848) with our password. diff --git a/add-to-swarm-with-defaults.sh b/add-to-swarm-with-defaults.sh new file mode 100755 index 0000000..766e235 --- /dev/null +++ b/add-to-swarm-with-defaults.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +cd $(cd -P -- "$(dirname -- "$0")" && pwd -P) + +./add-to-swarm.sh -p 8848 -n elk_datastack -r 5001 diff --git a/add-to-swarm.sh b/add-to-swarm.sh new file mode 100755 index 0000000..7865a87 --- /dev/null +++ b/add-to-swarm.sh @@ -0,0 +1,58 @@ +#!/usr/bin/env bash +cd $(cd -P -- "$(dirname -- "$0")" && pwd -P) + +# Fetching port and network as input +PORT=8888 +REGISTRY=5000 +while [[ "$#" -gt 0 ]]; do case $1 in + -p|--port) PORT="$2"; shift;; + -r|--registry) REGISTRY="$2"; shift;; + -n|--network) NETWORK="$2"; shift;; +# -u|--uglify) uglify=1;; + *) echo "Unknown parameter passed: $1"; exit 1;; +esac; shift; done + +# Check if arguments are valid +if [[ $PORT != [0-9][0-9][0-9][0-9]* ]]; then + echo "Given port is not valid." + echo "Usage: $0 -p [port] -n [docker-network] -r [registry-port] # ports must be an integer with 4 or more digits." + exit 21 +fi + +if [[ $REGISTRY != [0-9][0-9][0-9][0-9]* ]]; then + echo "Given registry port is not valid." + echo "Usage: $0 -p [port] -n [docker-network] -r [registry-port] # ports must be an integer with 4 or more digits." + exit 21 +fi + +if [[ $NETWORK == "" ]]; then + echo "No docker network was provided to which this gpu-jupyter should be added to." + echo "Usage: $0 -p [port] -n [docker-network] -r [registry-port] # ports must be an integer with 4 or more digits." + exit 22 +fi +result=$(docker network ls) +if [[ "$result" != *" $NETWORK "* ]]; then + echo "Could not find network $NETWORK. Please provide a valid docker network." + echo "Please select a network:" + docker network ls + exit 23 +fi + +# starting in swarm +export HOSTNAME=$(hostname) +export JUPYTER_PORT=$PORT +export REGISTRY_PORT=$REGISTRY +export JUPYTER_NETWORK=$NETWORK +echo "Adding gpu-jupyter to the swarm on the node $HOSTNAME in the network $NETWORK on port $PORT and registry to port $REGISTRY." + +# substitute the blueprint docker-compose-swarm with the environment variables and stack deploy it. +envsubst < docker-compose-swarm.yml > .docker-compose-swarm.yml.envsubst +docker-compose -f .docker-compose-swarm.yml.envsubst build +docker-compose -f .docker-compose-swarm.yml.envsubst push +docker stack deploy --compose-file .docker-compose-swarm.yml.envsubst gpu +rm .docker-compose-swarm.yml.envsubst + +echo +echo "Added gpu-jupyter to docker swarm $NETWORK on port $JUPYTER_PORT." +echo "See 'docker service ps gpu_gpu-jupyter' for status info." +echo "See 'docker service logs -f gpu_gpu-jupyter' for logs." diff --git a/docker-compose-swarm.yml b/docker-compose-swarm.yml new file mode 100644 index 0000000..5f14297 --- /dev/null +++ b/docker-compose-swarm.yml @@ -0,0 +1,32 @@ +version: "3.4" +services: + gpu-jupyter: + image: 127.0.0.1:$REGISTRY_PORT/gpu-jupyter + build: .build + ports: + - $JUPYTER_PORT:8888 + volumes: + - ./data:/home/jovyan/work + environment: + GRANT_SUDO: "yes" + JUPYTER_ENABLE_LAB: "yes" + # enable sudo permissions + user: + "root" + networks: + - default + - $JUPYTER_NETWORK + deploy: + placement: + constraints: [node.hostname == $HOSTNAME] + replicas: 1 + update_config: + parallelism: 2 + delay: 10s + restart_policy: + condition: on-failure + +networks: + $JUPYTER_NETWORK: + external: + name: $JUPYTER_NETWORK diff --git a/remove-from-swarm.sh b/remove-from-swarm.sh new file mode 100755 index 0000000..28671fd --- /dev/null +++ b/remove-from-swarm.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +cd $(cd -P -- "$(dirname -- "$0")" && pwd -P) + +echo "Removing gpu-jupyter from docker swarm." +docker stack rm gpu