Advertisement
frenky666

Untitled

May 17th, 2022 (edited)
841
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.56 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. _options="v:bBfFdDsSh"
  4.  
  5. usage() {
  6. echo """
  7. Usage $0 [-v <version>] -b -B -f -F -d -D -s -S
  8.  -v - version for docker images
  9.  
  10.  -b - build backend
  11.  -B - skip backend build
  12.  -f - build frontend
  13.  -F - skip frontend build
  14.  
  15.  -d - build docker
  16.  -D - skip docker build
  17.  -s - skip docker backend
  18.  -S - skip docker frontend
  19.  
  20.  All parameters are optional, default values are provided
  21. """ >&2
  22. }
  23.  
  24. _version="local-v1"
  25. _frontend_path="../shivah-frontend"
  26. _mvn_opts="clean package -T1C -DskipTests"
  27.  
  28. _rebuild_backend="t"
  29. _rebuild_frontend="t"
  30. _rebuild_docker="t"
  31.  
  32. _skip_docker_frontend="f"
  33. _skip_docker_backend="f"
  34.  
  35. if test -t 1; then
  36.   # see if it supports colors...
  37.   ncolors=$(tput colors)
  38.  
  39.   if test -n "$ncolors" && test $ncolors -ge 8; then
  40.     bold="$(tput bold)"
  41.     underline="$(tput smul)"
  42.     standout="$(tput smso)"
  43.     normal="$(tput sgr0)"
  44.     black="$(tput setaf 0)"
  45.     red="$(tput setaf 1)"
  46.     green="$(tput setaf 2)"
  47.     yellow="$(tput setaf 3)"
  48.     blue="$(tput setaf 4)"
  49.     magenta="$(tput setaf 5)"
  50.     cyan="$(tput setaf 6)"
  51.     white="$(tput setaf 7)"
  52.   fi
  53. fi
  54.  
  55.  
  56. while getopts $_options _option; do
  57.   case $_option in
  58.     v )
  59.       _version=$OPTARG
  60.       ;;
  61.  
  62.     b )
  63.       _rebuild_backend="t"
  64.       ;;
  65.     B )
  66.       _rebuild_backend="f"
  67.       ;;
  68.  
  69.     f )
  70.       _rebuild_frontend="t"
  71.       ;;
  72.     F )
  73.       _rebuild_frontend="f"
  74.       ;;
  75.  
  76.     d )
  77.       _rebuild_docker="t"
  78.       ;;
  79.     D )
  80.       _rebuild_docker="f"
  81.       ;;
  82.  
  83.     s )
  84.       _skip_docker_backend="t"
  85.       ;;
  86.     S )
  87.       _skip_docker_frontend="t"
  88.       ;;
  89.  
  90.     h )
  91.       usage
  92.       exit
  93.       ;;
  94.     \? )
  95.       echo "${red}Error.${normal} Unknown option -$OPTARG" >&2
  96.       exit 1
  97.       ;;
  98.     : )
  99.       echo "${red}Error.${normal} Missing option argument for -$OPTARG" >&2
  100.       exit 1
  101.       ;;
  102.   esac
  103. done
  104.  
  105. if [ -z "${MINIKUBE_ACTIVE_DOCKERD}" ]; then
  106.   echo "${yellow}Minikube environment not found, attempting to set-up.${normal}"
  107.   eval $(minikube docker-env)
  108. fi
  109.  
  110. if [ -z "${MINIKUBE_ACTIVE_DOCKERD}" ]; then
  111.   echo "${red}Minikube environment not found.${normal}"
  112.   exit 1
  113. else
  114.   echo "${green}Minikube environment present.${normal}"
  115. fi
  116.  
  117.  
  118. if [ "${_rebuild_backend}" == "t" ]; then
  119.   echo "${green}Building backend.${normal}"
  120.   mvn ${_mvn_opts}
  121. else
  122.   echo "${yellow}Skipping backend.${normal}"
  123. fi
  124.  
  125. if [ "${_rebuild_frontend}" == "t" ]; then
  126.   echo "${green}Building frontend.${normal}"
  127.   _cwd=$(pwd)
  128.   cd ${_frontend_path} && quasar build
  129.   cd ${_cwd}
  130. else
  131.   echo "${yellow}Skipping frontend.${normal}"
  132. fi
  133.  
  134.  
  135. if [ "${_rebuild_docker}" == "t" ]; then
  136.   _cwd=$(pwd)
  137.   echo "${green}Building docker images.${normal}"
  138.  
  139.   if [ -d "${_frontend_path}/dist/spa" ]; then
  140.     if [ "${_skip_docker_frontend}" == "f" ]; then
  141.       echo "${green}Building${normal} ${underline}frontend:${_version}${normal}"
  142.       cd ${_frontend_path} && docker build -t shivah/frontend:${_version} .
  143.       cd ${_cwd}
  144.     else
  145.       echo "${yellow}Skipping frontend build.${normal}"
  146.     fi
  147.     else
  148.       echo "${red}Unable to build frontend, dist directory is missing.${normal}"
  149.   fi;
  150.  
  151.   if [ "${_skip_docker_backend}" == "t"]; then
  152.     find . -type f -not -path "*target" -not -path "*dev*" -name Dockerfile -exec dirname {} \; |\
  153.     while read _line; do
  154.       _name=$(basename $_line)
  155.       echo "${green}Building${normal} ${underline}${_name}:${_version}${normal}"
  156.       docker build -t shivah/${_name}:${_version} ${_line}
  157.     done
  158.   else
  159.     echo "${yellow}Skipping backend build.${normal}"
  160.   fi
  161. fi
  162.  
  163.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement