start 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/bin/bash
  2. set -o errexit
  3. MEM=$(docker info | grep "Total Memory" | cut -d':' -f2 | xargs | sed s/GiB//)
  4. # Docker reports RAM 0.2 less than what it is actually set to
  5. (( $(echo "$MEM < 5.8" | bc -l) )) && echo "There must be at least 6GB of RAM allocated to Docker to continue." && exit
  6. # Ref: https://stackoverflow.com/a/51789677/9821321
  7. function parseYaml {
  8. local s
  9. local w
  10. local fs
  11. s='[[:space:]]*'
  12. w='[a-zA-Z0-9_]*'
  13. fs=$(echo @|tr @ '\034')
  14. sed -ne "s|,$s\]$s\$|]|" \
  15. -e "s|^\($s\)\($w\)$s:$s\[$s\(.*\)$s\]|\1\2:\n\1 - \3|;p" "$1" | \
  16. sed -ne "s|,$s}$s\$|}|" \
  17. -e "s|^\($s\)-$s{$s\(.*\)$s}|\1-\n\1 \2|;p" | \
  18. sed -ne "s|^\($s\):|\1|" \
  19. -e "s|^\($s\)-$s{[\"']\(.*\)[\"']}$s\$|\1$fs$fs\2|p" \
  20. -e "s|^\($s\)-$s\(.*\)$s\$|\1$fs$fs\2|p" \
  21. -e "s|^\($s\)\($w\)$s:$s{[\"']\(.*\)[\"']}$s\$|\1$fs\2$fs\3|p" \
  22. -e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" | \
  23. awk -F"$fs" '{
  24. indent = length($1)/2;
  25. vname[indent] = $2;
  26. for (i in vname) {if (i > indent) {delete vname[i]; idx[i]=0}}
  27. if (length($2) == 0) {vname[indent] = ++idx[indent] };
  28. if (length($3) > 0) {
  29. vn=""; for (i=0; i<indent; i++) {vn = (vn)(vname[i])("_")}
  30. if ("'"$2"'_" == vn) {
  31. print substr($3 ,1 , match($3,":")-1)
  32. }
  33. }
  34. }'
  35. }
  36. # Check if volume files exist to avoid creating an empty folder
  37. VOLUME_LIST=$(parseYaml docker-compose.dev.yml services_app_volumes)
  38. IGNORE_LIST="./src/app/code ./src/m2-hotfixes ./src/patches ./src/var/log ./src/var/report ./src"
  39. IS_VALID=true
  40. # Loop through all files missing from the docker-compose.dev.yml file
  41. for file in $VOLUME_LIST; do
  42. if [ ! -e "$file" ] && [[ ! " $IGNORE_LIST " =~ $file ]]; then
  43. echo "$file: No such file or directory"
  44. IS_VALID=false
  45. fi
  46. done
  47. # Wait to exit until all missing files have been outputted to the user
  48. [ $IS_VALID = false ] && echo "Failed to start docker for missing volume files" && exit
  49. docker-compose -f docker-compose.yml -f docker-compose.dev.yml up -d --remove-orphans "$@"
  50. ## Blackfire support
  51. ## ------------------
  52. ## First register the blackfire agent with:
  53. #bin/root blackfire-agent --register --server-id={YOUR_SERVER_ID} --server-token={YOUR_SERVER_TOKEN}
  54. ## Then uncomment the below line (and leave uncommented) to start the agent automatically with bin/start:
  55. #bin/root /etc/init.d/blackfire-agent start
  56. bin/cache-clean --watch