sync.sh 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #!/bin/bash
  2. # This shell script is an optional tool to simplify
  3. # the installation and usage of laradock with docker-sync.
  4. # Make sure that the DOCKER_SYNC_STRATEGY is set in the .env
  5. # DOCKER_SYNC_STRATEGY=native_osx # osx
  6. # DOCKER_SYNC_STRATEGY=unison # windows
  7. # To run, make sure to add permissions to this file:
  8. # chmod 755 sync.sh
  9. # USAGE EXAMPLE:
  10. # Install docker-sync: ./sync.sh install
  11. # Start sync and services with nginx and mysql: ./sync.sh up nginx mysql
  12. # Stop containers and sync: ./sync.sh down
  13. # prints colored text
  14. print_style () {
  15. if [ "$2" == "info" ] ; then
  16. COLOR="96m"
  17. elif [ "$2" == "success" ] ; then
  18. COLOR="92m"
  19. elif [ "$2" == "warning" ] ; then
  20. COLOR="93m"
  21. elif [ "$2" == "danger" ] ; then
  22. COLOR="91m"
  23. else #default color
  24. COLOR="0m"
  25. fi
  26. STARTCOLOR="\e[$COLOR"
  27. ENDCOLOR="\e[0m"
  28. printf "$STARTCOLOR%b$ENDCOLOR" "$1"
  29. }
  30. display_options () {
  31. printf "Available options:\n";
  32. print_style " install" "info"; printf "\t\t Installs docker-sync gem on the host machine.\n"
  33. print_style " up [services]" "success"; printf "\t Starts docker-sync and runs docker compose.\n"
  34. print_style " down" "success"; printf "\t\t\t Stops containers and docker-sync.\n"
  35. print_style " bash" "success"; printf "\t\t\t Opens bash on the workspace with user laradock.\n"
  36. print_style " sync" "info"; printf "\t\t\t Manually triggers the synchronization of files.\n"
  37. print_style " clean" "danger"; printf "\t\t Removes all files from docker-sync.\n"
  38. }
  39. if [[ $# -eq 0 ]] ; then
  40. print_style "Missing arguments.\n" "danger"
  41. display_options
  42. exit 1
  43. fi
  44. if [ "$1" == "up" ] ; then
  45. print_style "Initializing Docker Sync\n" "info"
  46. print_style "May take a long time (15min+) on the first run\n" "info"
  47. docker-sync start;
  48. print_style "Initializing Docker Compose\n" "info"
  49. shift # removing first argument
  50. docker-compose up -d ${@}
  51. elif [ "$1" == "down" ]; then
  52. print_style "Stopping Docker Compose\n" "info"
  53. docker-compose stop
  54. print_style "Stopping Docker Sync\n" "info"
  55. docker-sync stop
  56. elif [ "$1" == "bash" ]; then
  57. docker-compose exec --user=laradock workspace bash
  58. elif [ "$1" == "install" ]; then
  59. print_style "Installing docker-sync\n" "info"
  60. gem install docker-sync
  61. elif [ "$1" == "sync" ]; then
  62. print_style "Manually triggering sync between host and docker-sync container.\n" "info"
  63. docker-sync sync;
  64. elif [ "$1" == "clean" ]; then
  65. print_style "Removing and cleaning up files from the docker-sync container.\n" "warning"
  66. docker-sync clean
  67. else
  68. print_style "Invalid arguments.\n" "danger"
  69. display_options
  70. exit 1
  71. fi