2017-07-15 21:40:25 +08:00
|
|
|
#!/bin/bash
|
2017-07-16 01:52:23 +08:00
|
|
|
|
2017-07-16 04:03:33 +08:00
|
|
|
# This shell script is an optional tool to simplify
|
|
|
|
# the installation and usage of laradock with docker-sync.
|
|
|
|
|
2017-07-16 06:32:05 +08:00
|
|
|
# Make sure that the DOCKER_SYNC_STRATEGY is set in the .env
|
|
|
|
# DOCKER_SYNC_STRATEGY=native_osx # osx
|
|
|
|
# DOCKER_SYNC_STRATEGY=unison # windows
|
|
|
|
|
2017-07-16 04:03:33 +08:00
|
|
|
# To run, make sure to add permissions to this file:
|
|
|
|
# chmod 755 sync.sh
|
|
|
|
|
2017-07-16 06:32:05 +08:00
|
|
|
# USAGE EXAMPLE:
|
2017-07-16 04:58:17 +08:00
|
|
|
# Install docker-sync: ./sync.sh install
|
|
|
|
# Start sync and services with nginx and mysql: ./sync.sh up nginx mysql
|
|
|
|
# Stop containers and sync: ./sync.sh down
|
2017-07-16 04:03:33 +08:00
|
|
|
|
2017-07-16 01:52:23 +08:00
|
|
|
# prints colored text
|
|
|
|
print_style () {
|
2017-07-16 02:36:15 +08:00
|
|
|
|
2017-07-16 01:52:23 +08:00
|
|
|
if [ "$2" == "info" ] ; then
|
2017-07-16 05:15:07 +08:00
|
|
|
COLOR="96m"
|
2017-07-16 01:52:23 +08:00
|
|
|
elif [ "$2" == "success" ] ; then
|
2017-07-16 05:15:07 +08:00
|
|
|
COLOR="92m"
|
2017-07-16 01:52:23 +08:00
|
|
|
elif [ "$2" == "warning" ] ; then
|
2017-07-16 05:15:07 +08:00
|
|
|
COLOR="93m"
|
2017-07-16 01:52:23 +08:00
|
|
|
elif [ "$2" == "danger" ] ; then
|
2017-07-16 05:15:07 +08:00
|
|
|
COLOR="91m"
|
2017-07-16 03:46:00 +08:00
|
|
|
else #default color
|
2017-07-16 05:15:07 +08:00
|
|
|
COLOR="0m"
|
2017-07-16 01:52:23 +08:00
|
|
|
fi
|
|
|
|
|
2017-07-16 05:15:07 +08:00
|
|
|
STARTCOLOR="\e[$COLOR"
|
|
|
|
ENDCOLOR="\e[0m"
|
2017-07-16 02:24:01 +08:00
|
|
|
|
2017-07-16 05:15:07 +08:00
|
|
|
printf "$STARTCOLOR%b$ENDCOLOR" "$1"
|
2017-07-16 01:52:23 +08:00
|
|
|
}
|
|
|
|
|
2017-07-16 03:46:00 +08:00
|
|
|
display_options () {
|
|
|
|
printf "Available options:\n";
|
2017-07-16 05:15:07 +08:00
|
|
|
print_style " install" "info"; printf "\t\t Installs docker-sync gem on the host machine.\n"
|
|
|
|
print_style " up [services]" "success"; printf "\t Starts docker-sync and runs docker compose.\n"
|
|
|
|
print_style " down" "success"; printf "\t\t\t Stops containers and docker-sync.\n"
|
2018-11-27 16:57:36 +08:00
|
|
|
print_style " bash" "success"; printf "\t\t\t Opens bash on the workspace with user laradock.\n"
|
2017-07-16 07:28:02 +08:00
|
|
|
print_style " sync" "info"; printf "\t\t\t Manually triggers the synchronization of files.\n"
|
2017-07-16 06:32:05 +08:00
|
|
|
print_style " clean" "danger"; printf "\t\t Removes all files from docker-sync.\n"
|
2017-07-16 03:46:00 +08:00
|
|
|
}
|
2017-07-16 01:52:23 +08:00
|
|
|
|
2017-07-16 03:46:00 +08:00
|
|
|
if [[ $# -eq 0 ]] ; then
|
2017-07-16 05:15:07 +08:00
|
|
|
print_style "Missing arguments.\n" "danger"
|
|
|
|
display_options
|
2017-07-15 21:40:25 +08:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-07-16 04:58:17 +08:00
|
|
|
if [ "$1" == "up" ] ; then
|
2017-07-16 05:15:07 +08:00
|
|
|
print_style "Initializing Docker Sync\n" "info"
|
2017-07-16 06:47:02 +08:00
|
|
|
print_style "May take a long time (15min+) on the first run\n" "info"
|
2017-07-16 04:58:17 +08:00
|
|
|
docker-sync start;
|
|
|
|
|
2017-07-16 05:15:07 +08:00
|
|
|
print_style "Initializing Docker Compose\n" "info"
|
|
|
|
shift # removing first argument
|
2017-11-22 05:48:22 +08:00
|
|
|
docker-compose up -d ${@}
|
2017-07-16 00:00:44 +08:00
|
|
|
|
2017-07-16 04:58:17 +08:00
|
|
|
elif [ "$1" == "down" ]; then
|
2017-07-16 05:15:07 +08:00
|
|
|
print_style "Stopping Docker Compose\n" "info"
|
2017-11-28 22:33:27 +08:00
|
|
|
docker-compose stop
|
2017-07-16 04:03:33 +08:00
|
|
|
|
2017-07-16 05:15:07 +08:00
|
|
|
print_style "Stopping Docker Sync\n" "info"
|
|
|
|
docker-sync stop
|
2017-07-16 00:00:44 +08:00
|
|
|
|
2017-07-16 04:58:17 +08:00
|
|
|
elif [ "$1" == "bash" ]; then
|
2018-11-27 16:57:36 +08:00
|
|
|
docker-compose exec --user=laradock workspace bash
|
2017-07-16 04:36:25 +08:00
|
|
|
|
2017-07-16 04:58:17 +08:00
|
|
|
elif [ "$1" == "install" ]; then
|
2017-07-16 05:15:07 +08:00
|
|
|
print_style "Installing docker-sync\n" "info"
|
|
|
|
gem install docker-sync
|
2017-07-16 00:00:44 +08:00
|
|
|
|
2017-07-16 06:32:05 +08:00
|
|
|
elif [ "$1" == "sync" ]; then
|
2017-07-16 05:15:07 +08:00
|
|
|
print_style "Manually triggering sync between host and docker-sync container.\n" "info"
|
2017-07-16 04:58:17 +08:00
|
|
|
docker-sync sync;
|
2017-07-16 04:03:33 +08:00
|
|
|
|
2017-07-16 04:58:17 +08:00
|
|
|
elif [ "$1" == "clean" ]; then
|
2017-07-16 05:15:07 +08:00
|
|
|
print_style "Removing and cleaning up files from the docker-sync container.\n" "warning"
|
|
|
|
docker-sync clean
|
2017-07-16 04:58:17 +08:00
|
|
|
else
|
2017-07-16 05:15:07 +08:00
|
|
|
print_style "Invalid arguments.\n" "danger"
|
|
|
|
display_options
|
2017-07-16 04:58:17 +08:00
|
|
|
exit 1
|
2017-11-28 22:33:27 +08:00
|
|
|
fi
|