sync.sh 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. # Open bash inside the workspace: ./sync.sh bash
  14. # Force sync: ./sync.sh sync
  15. # Clean synced files: ./sync.sh clean
  16. # prints colored text
  17. print_style () {
  18. if [ "$2" == "info" ] ; then
  19. COLOR="96m"
  20. elif [ "$2" == "success" ] ; then
  21. COLOR="92m"
  22. elif [ "$2" == "warning" ] ; then
  23. COLOR="93m"
  24. elif [ "$2" == "danger" ] ; then
  25. COLOR="91m"
  26. else #default color
  27. COLOR="0m"
  28. fi
  29. STARTCOLOR="\e[$COLOR"
  30. ENDCOLOR="\e[0m"
  31. printf "$STARTCOLOR%b$ENDCOLOR" "$1"
  32. }
  33. display_options () {
  34. printf "Available options:\n";
  35. print_style " install" "info"; printf "\t\t Installs docker-sync gem on the host machine.\n"
  36. print_style " up [services]" "success"; printf "\t Starts docker-sync and runs docker compose.\n"
  37. print_style " down" "success"; printf "\t\t\t Stops containers and docker-sync.\n"
  38. print_style " bash" "success"; printf "\t\t\t Opens bash on the workspace.\n"
  39. print_style " sync" "success"; printf "\t\t Manually triggers the synchronization of files.\n"
  40. print_style " clean" "danger"; printf "\t\t Removes all files from docker-sync.\n"
  41. }
  42. if [[ $# -eq 0 ]] ; then
  43. print_style "Missing arguments.\n" "danger"
  44. display_options
  45. exit 1
  46. fi
  47. if [ "$1" == "up" ] ; then
  48. print_style "Initializing Docker Sync\n" "info"
  49. print_style "May take a long time (15min+) on the first run\n" "info"
  50. docker-sync start;
  51. print_style "Initializing Docker Compose\n" "info"
  52. shift # removing first argument
  53. docker-compose -f docker-compose.yml -f docker-compose.sync.yml up -d ${@}
  54. elif [ "$1" == "down" ]; then
  55. print_style "Stopping Docker Compose\n" "info"
  56. docker-compose down
  57. print_style "Stopping Docker Sync\n" "info"
  58. docker-sync stop
  59. elif [ "$1" == "bash" ]; then
  60. docker-compose exec workspace bash
  61. elif [ "$1" == "install" ]; then
  62. print_style "Installing docker-sync\n" "info"
  63. gem install docker-sync
  64. elif [ "$1" == "sync" ]; then
  65. print_style "Manually triggering sync between host and docker-sync container.\n" "info"
  66. docker-sync sync;
  67. elif [ "$1" == "clean" ]; then
  68. print_style "Removing and cleaning up files from the docker-sync container.\n" "warning"
  69. docker-sync clean
  70. else
  71. print_style "Invalid arguments.\n" "danger"
  72. display_options
  73. exit 1
  74. fi