Guest User

Untitled

a guest
Oct 5th, 2018
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.49 KB | None | 0 0
  1. #!/usr/bin/env bash
  2. set -e
  3.  
  4. usage() {
  5. echo "Usage: vantiq-setup -u <docker hub username> -p <docker hub password> [-o <overrides directory>]"
  6. }
  7.  
  8. abspath() {
  9. [[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
  10. }
  11.  
  12. #
  13. # Do initial bootstrapping of a Dockerized Vantiq K8s deployment client. We need the following:
  14. #
  15. # -u -- the docker hub username to use when pulling Vantiq images
  16. # -p -- the docker hub password to use when pulling Vantiq images
  17. # -o -- the directory in which deployment override files will live. Optional -- defaults to cwd.
  18.  
  19. # OS specific support (must be 'true' or 'false').
  20. msys=false
  21. darwin=false
  22. case "`uname`" in
  23. CYGWIN* )
  24. echo "Cygwin is not currently supported. Please install a MINGW based shell (e.g. Git Bash)"
  25. exit 1
  26. ;;
  27. Darwin* )
  28. darwin=true
  29. ;;
  30. MINGW* )
  31. msys=true
  32. ;;
  33. esac
  34.  
  35. username=""
  36. password=""
  37. overrides=$(pwd)
  38.  
  39. while getopts ":u:p:o:" opt; do
  40. case ${opt} in
  41. u ) # process user option
  42. username=$OPTARG
  43. ;;
  44. p ) # process password option
  45. password=$OPTARG
  46. ;;
  47. o ) # process overrides option
  48. overrides=$OPTARG
  49. ;;
  50. \? )
  51. echo "Unrecognized option: $OPTARG"
  52. usage
  53. exit 1
  54. ;;
  55. : )
  56. echo "Invalid option: $OPTARG requires an argument" 1>&2
  57. exit 1
  58. ;;
  59. esac
  60. done
  61.  
  62. # Get rid of the options processed by getopts
  63. shift $((OPTIND -1))
  64.  
  65. # Confirm we have what we want
  66.  
  67. if [ -z $username ]; then
  68. echo "Missing mandatory option -u to specify Docker Hub user name." 1>&2
  69. usage
  70. exit 1
  71. fi
  72.  
  73. if [ -z $password ]; then
  74. echo "Missing mandatory option -p to specify Docker Hub password." 1>&2
  75. usage
  76. exit 1
  77. fi
  78.  
  79. # If the given directory doesn't exist, create (unless it's a file, then bitch)
  80. if [ ! -d $overrides ]; then
  81. # Could be a file
  82. if [ -f $overrides ]; then
  83. echo "Specified overrides directory '$overrides' exists, but isn't a directory." 1>&2
  84. usage
  85. exit 1
  86. fi
  87.  
  88. # Create
  89. mkdir -p $overrides
  90. fi
  91.  
  92. # Use username and password to log in to docker hub and pull the Vantiq K8s deploy image
  93. echo $password | docker login --username $username --password-stdin
  94. docker pull vantiq/k8sdeploy
  95.  
  96. # Construct gradle properties file in the overrides dir (this gets moved to the k8sdeploy volume during bootstrap
  97. # On Linux we can access DiD via the UD
  98. dockerHost=""
  99. if $msys; then
  100. dockerHost="tcp://docker.for.win.localhost:2375"
  101. fi
  102. cat <<-EOF > $overrides/gradle.properties
  103. dockerHost=$dockerHost
  104. dockerHubUser=$username
  105. dockerHubPassword=$password
  106. EOF
  107.  
  108. # Run K8s deploy bootstrapping command to set things up for future deployments.
  109. echo "Configuring Vantiq K8s deployment using overrides directory $overrides."
  110. echo "This will create the script 'vantiq-deploy.' in this directory."
  111. overridesMount=$(abspath $overrides)
  112. if $msys; then
  113. # Add additional slash to avoid shell conversion to Windows style paths
  114. overridesMount="/$overridesMount"
  115. fi
  116. docker run --rm -it -v vantiq_gradle:/home/vantiq/.gradle -v vantiq_k8sDeploy:/home/vantiq/k8sdeploy \
  117. -v ${overridesMount}:/home/vantiq/overrides vantiq/k8sdeploy
  118.  
  119. # Generic Vantiq deploy script and make executable
  120. socketMount="-v /var/run/docker.sock:/var/run/docker.sock"
  121. if $msys; then
  122. socketMount=""
  123. fi
  124. cat <<-EOF > $overrides/vantiq-deploy
  125. docker run --rm -it -v vantiq_gradle:/home/vantiq/.gradle -v vantiq_k8sDeploy:/home/vantiq/k8sdeploy \
  126. -v ${overridesMount}:/home/vantiq/overrides $socketMount vantiq/k8sdeploy "\$@"
  127. EOF
  128. chmod +x $overrides/vantiq-deploy
Add Comment
Please, Sign In to add comment