Parametrize Registry Port, git feature request #1

This commit is contained in:
Christoph Schranz 2020-01-13 09:55:46 +01:00
parent 59a804b819
commit 47aef1cc0f
2 changed files with 15 additions and 5 deletions

View File

@ -3,8 +3,10 @@ cd $(cd -P -- "$(dirname -- "$0")" && pwd -P)
# Fetching port and network as input # Fetching port and network as input
PORT=8888 PORT=8888
REGISTRY=5000
while [[ "$#" -gt 0 ]]; do case $1 in while [[ "$#" -gt 0 ]]; do case $1 in
-p|--port) PORT="$2"; shift;; -p|--port) PORT="$2"; shift;;
-r|--registry) REGISTRY="$2"; shift;;
-n|--network) NETWORK="$2"; shift;; -n|--network) NETWORK="$2"; shift;;
# -u|--uglify) uglify=1;; # -u|--uglify) uglify=1;;
*) echo "Unknown parameter passed: $1"; exit 1;; *) echo "Unknown parameter passed: $1"; exit 1;;
@ -13,13 +15,19 @@ esac; shift; done
# Check if arguments are valid # Check if arguments are valid
if [[ $PORT != [0-9][0-9][0-9][0-9]* ]]; then if [[ $PORT != [0-9][0-9][0-9][0-9]* ]]; then
echo "Given port is not valid." echo "Given port is not valid."
echo "Usage: $0 -p [port] -n [docker-network] # port must be an integer with 4 or more digits." 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 exit 21
fi fi
if [[ $NETWORK == "" ]]; then if [[ $NETWORK == "" ]]; then
echo "No docker network was provided to which this gpu-jupyter should be added to." 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." echo "Usage: $0 -p [port] -n [docker-network] -r [registry-port] # ports must be an integer with 4 or more digits."
exit 22 exit 22
fi fi
result=$(docker network ls) result=$(docker network ls)
@ -33,9 +41,11 @@ fi
# starting in swarm # starting in swarm
export HOSTNAME=$(hostname) export HOSTNAME=$(hostname)
export JUPYTER_PORT=$PORT export JUPYTER_PORT=$PORT
export REGISTRY_PORT=$REGISTRY
export JUPYTER_NETWORK=$NETWORK export JUPYTER_NETWORK=$NETWORK
echo "Adding gpu-jupyter to the swarm on the node $HOSTNAME in the network $NETWORK on port $PORT." echo "Adding gpu-jupyter to the swarm on the node $HOSTNAME in the network $NETWORK on port $PORT and registry to port $REGISTRY."
# echo $JUPYTER_NETWORK
# substitute the blueprint docker-compose-swarm with the environment variables and stack deploy it.
envsubst < docker-compose-swarm.yml > .docker-compose-swarm.yml.envsubst 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 build
docker-compose -f .docker-compose-swarm.yml.envsubst push docker-compose -f .docker-compose-swarm.yml.envsubst push

View File

@ -1,7 +1,7 @@
version: "3.4" version: "3.4"
services: services:
gpu-jupyter: gpu-jupyter:
image: 127.0.0.1:5001/gpu-jupyter image: 127.0.0.1:$REGISTRY_PORT/gpu-jupyter
build: ./src/ build: ./src/
ports: ports:
- $JUPYTER_PORT:8888 - $JUPYTER_PORT:8888