Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- set -e
- usage() {
- echo "Usage: vantiq-setup -u <docker hub username> -p <docker hub password> [-o <overrides directory>]"
- }
- abspath() {
- [[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
- }
- #
- # Do initial bootstrapping of a Dockerized Vantiq K8s deployment client. We need the following:
- #
- # -u -- the docker hub username to use when pulling Vantiq images
- # -p -- the docker hub password to use when pulling Vantiq images
- # -o -- the directory in which deployment override files will live. Optional -- defaults to cwd.
- # OS specific support (must be 'true' or 'false').
- msys=false
- darwin=false
- case "`uname`" in
- CYGWIN* )
- echo "Cygwin is not currently supported. Please install a MINGW based shell (e.g. Git Bash)"
- exit 1
- ;;
- Darwin* )
- darwin=true
- ;;
- MINGW* )
- msys=true
- ;;
- esac
- username=""
- password=""
- overrides=$(pwd)
- while getopts ":u:p:o:" opt; do
- case ${opt} in
- u ) # process user option
- username=$OPTARG
- ;;
- p ) # process password option
- password=$OPTARG
- ;;
- o ) # process overrides option
- overrides=$OPTARG
- ;;
- \? )
- echo "Unrecognized option: $OPTARG"
- usage
- exit 1
- ;;
- : )
- echo "Invalid option: $OPTARG requires an argument" 1>&2
- exit 1
- ;;
- esac
- done
- # Get rid of the options processed by getopts
- shift $((OPTIND -1))
- # Confirm we have what we want
- if [ -z $username ]; then
- echo "Missing mandatory option -u to specify Docker Hub user name." 1>&2
- usage
- exit 1
- fi
- if [ -z $password ]; then
- echo "Missing mandatory option -p to specify Docker Hub password." 1>&2
- usage
- exit 1
- fi
- # If the given directory doesn't exist, create (unless it's a file, then bitch)
- if [ ! -d $overrides ]; then
- # Could be a file
- if [ -f $overrides ]; then
- echo "Specified overrides directory '$overrides' exists, but isn't a directory." 1>&2
- usage
- exit 1
- fi
- # Create
- mkdir -p $overrides
- fi
- # Use username and password to log in to docker hub and pull the Vantiq K8s deploy image
- echo $password | docker login --username $username --password-stdin
- docker pull vantiq/k8sdeploy
- # Construct gradle properties file in the overrides dir (this gets moved to the k8sdeploy volume during bootstrap
- # On Linux we can access DiD via the UD
- dockerHost=""
- if $msys; then
- dockerHost="tcp://docker.for.win.localhost:2375"
- fi
- cat <<-EOF > $overrides/gradle.properties
- dockerHost=$dockerHost
- dockerHubUser=$username
- dockerHubPassword=$password
- EOF
- # Run K8s deploy bootstrapping command to set things up for future deployments.
- echo "Configuring Vantiq K8s deployment using overrides directory $overrides."
- echo "This will create the script 'vantiq-deploy.' in this directory."
- overridesMount=$(abspath $overrides)
- if $msys; then
- # Add additional slash to avoid shell conversion to Windows style paths
- overridesMount="/$overridesMount"
- fi
- docker run --rm -it -v vantiq_gradle:/home/vantiq/.gradle -v vantiq_k8sDeploy:/home/vantiq/k8sdeploy \
- -v ${overridesMount}:/home/vantiq/overrides vantiq/k8sdeploy
- # Generic Vantiq deploy script and make executable
- socketMount="-v /var/run/docker.sock:/var/run/docker.sock"
- if $msys; then
- socketMount=""
- fi
- cat <<-EOF > $overrides/vantiq-deploy
- docker run --rm -it -v vantiq_gradle:/home/vantiq/.gradle -v vantiq_k8sDeploy:/home/vantiq/k8sdeploy \
- -v ${overridesMount}:/home/vantiq/overrides $socketMount vantiq/k8sdeploy "\$@"
- EOF
- chmod +x $overrides/vantiq-deploy
Add Comment
Please, Sign In to add comment