Automated scripts for deployment

This commit is contained in:
Christoph Schranz 2019-11-13 15:45:07 +01:00
parent a1fcababc0
commit d0be1db5a3
7 changed files with 72 additions and 31 deletions

1
.gitignore vendored
View File

@ -108,3 +108,4 @@ venv.bak/
/data/* /data/*
!/data/.gitkeep !/data/.gitkeep
*.save* *.save*
*.envsubst

View File

@ -1,20 +1,47 @@
#!/usr/bin/env bash #!/usr/bin/env bash
cd $(cd -P -- "$(dirname -- "$0")" && pwd -P) cd $(cd -P -- "$(dirname -- "$0")" && pwd -P)
if [[ -n "$1" ]]; then # Fetching port and network as input
result=$(docker network ls) PORT=8888
if [[ "$result" == *" $1 "* ]]; then while [[ "$#" -gt 0 ]]; do case $1 in
echo "Adding gpu-jupyter to the swarm in the network $1." -p|--port) PORT="$2"; shift;;
export JUPYTER_NETWORK=$1 -n|--network) NETWORK="$2"; shift;;
# echo $JUPYTER_NETWORK # -u|--uglify) uglify=1;;
docker-compose -f docker-compose-swarm.yml build *) echo "Unknown parameter passed: $1"; exit 1;;
docker-compose -f docker-compose-swarm.yml push esac; shift; done
# docker stack deploy --compose-file docker-compose-swarm.yml gpu
else # Check if arguments are valid
echo "Could not find network $1. Please provide a valid docker network." if [[ $PORT != [0-9][0-9][0-9][0-9]* ]]; then
fi echo "Given port is not valid."
else echo "Usage: $0 -p [port] -n [docker-network] # port must be an integer with 4 or more digits."
echo "Usage: $0 network" exit 21
echo "Please set the network"
fi 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] # port 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
echo "Adding gpu-jupyter to the swarm in the network $NETWORK on port $PORT."
export JUPYTER_PORT=$PORT
export JUPYTER_NETWORK=$NETWORK
# echo $JUPYTER_NETWORK
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."

View File

@ -4,7 +4,7 @@ services:
image: 127.0.0.1:5001/gpu-jupyter image: 127.0.0.1:5001/gpu-jupyter
build: ./src/ build: ./src/
ports: ports:
- 8848:8888 - $JUPYTER_PORT:8888
volumes: volumes:
- ./data:/home/jovyan/work - ./data:/home/jovyan/work
environment: environment:

View File

@ -4,7 +4,7 @@ services:
image: 127.0.0.1:5001/gpu-jupyter image: 127.0.0.1:5001/gpu-jupyter
build: ./src/ build: ./src/
ports: ports:
- 8848:8888 - ${JUPYTER_PORT}:8888
volumes: volumes:
- ./data:/home/jovyan/work - ./data:/home/jovyan/work
environment: environment:
@ -13,16 +13,3 @@ services:
# enable sudo permissions # enable sudo permissions
user: user:
"root" "root"
deploy:
placement:
constraints: [node.hostname == data-science]
resources:
limits:
cpus: "4"
memory: 8G
replicas: 1
update_config:
parallelism: 2
delay: 10s
restart_policy:
condition: on-failure

View File

@ -1,4 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
cd $(cd -P -- "$(dirname -- "$0")" && pwd -P) cd $(cd -P -- "$(dirname -- "$0")" && pwd -P)
docker stack rm gpu_gpu-jupyter echo "Removing gpu-jupyter from docker swarm."
docker stack rm gpu

View File

@ -1,4 +1,27 @@
#!/usr/bin/env bash #!/usr/bin/env bash
cd $(cd -P -- "$(dirname -- "$0")" && pwd -P) cd $(cd -P -- "$(dirname -- "$0")" && pwd -P)
# Fetching port and network as input
PORT=8888
while [[ "$#" -gt 0 ]]; do case $1 in
-p|--port) PORT="$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] # port must be an integer with 4 or more digits."
exit 21
fi
# starting in docker-compose
echo "Starting gpu-jupyter via docker-compose on port $PORT."
export JUPYTER_PORT=$PORT
# echo $JUPYTER_PORT
docker-compose up --build -d docker-compose up --build -d
echo
echo "Started gpu-jupyter via docker-compose on port $JUPYTER_PORT."
echo "See docker-compose logs -f for logs."

View File

@ -1,4 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
cd $(cd -P -- "$(dirname -- "$0")" && pwd -P) cd $(cd -P -- "$(dirname -- "$0")" && pwd -P)
# Export default port to make compose file valid.
export JUPYTER_PORT=8888
docker-compose down docker-compose down