blackbirdchess-docker-dev/sync.sh

61 lines
2.0 KiB
Bash
Raw Normal View History

2017-07-15 15:40:25 +02:00
#!/bin/bash
2017-07-15 19:52:23 +02:00
# prints colored text
print_style () {
if [ "$2" == "info" ] ; then
COLOR="1;96m";
elif [ "$2" == "success" ] ; then
COLOR="1;92m";
elif [ "$2" == "warning" ] ; then
COLOR="1;93m";
elif [ "$2" == "danger" ] ; then
COLOR="1;31m";
else #white
COLOR="1;97m";
fi
printf "\e[$COLOR%-6s\e[m" "$1";
}
2017-07-15 15:40:25 +02:00
if [[ $# -eq 0 ]] ; then
2017-07-15 19:52:23 +02:00
print_style "Invalid argument." 'danger'; printf " Available commands:\n";
print_style " install" "success"; 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";
print_style " trigger" "success"; printf "\t\t Manually triggers the synchronization of files.\n";
print_style " clean" "warning"; printf "\t\t Removes all synched files from docker-sync container.\n";
2017-07-15 15:40:25 +02:00
exit 1
fi
2017-07-15 15:46:52 +02:00
if [ "$1" == "up" ] ; then
2017-07-15 19:52:23 +02:00
print_style "Initializing Docker Sync\n" 'info';
print_style "(May take a long time (15min+) on the 'Looking for changes' step the first time)\n" 'warning';
2017-07-15 15:40:25 +02:00
docker-sync start;
2017-07-15 19:52:23 +02:00
print_style "Initializing Docker Compose\n" 'info';
2017-07-15 17:13:50 +02:00
shift; # removing first argument
docker-compose -f docker-compose.yml -f docker-compose.sync.yml up -d ${@};
2017-07-15 18:00:44 +02:00
2017-07-15 15:46:52 +02:00
elif [ "$1" == "down" ]; then
2017-07-15 19:52:23 +02:00
print_style "Stopping Docker Compose\n" 'info';
2017-07-15 15:40:25 +02:00
docker-compose down;
2017-07-15 19:52:23 +02:00
print_style "Stopping Docker Sync\n" 'info';
2017-07-15 15:44:09 +02:00
docker-sync stop;
2017-07-15 18:00:44 +02:00
2017-07-15 17:01:52 +02:00
elif [ "$1" == "install" ]; then
2017-07-15 19:52:23 +02:00
print_style "Installing docker-sync" 'info';
2017-07-15 17:01:52 +02:00
gem install docker-sync;
2017-07-15 18:00:44 +02:00
elif [ "$1" == "trigger" ]; then
2017-07-15 19:52:23 +02:00
print_style "Manually triggering sync between host and docker-sync container.\n" 'info';
2017-07-15 17:01:52 +02:00
docker-sync sync;
2017-07-15 18:00:44 +02:00
2017-07-15 17:01:52 +02:00
elif [ "$1" == "clean" ]; then
2017-07-15 19:52:23 +02:00
print_style "Removing and cleaning up files from the docker-sync container.\n" 'warning';
2017-07-15 17:01:52 +02:00
docker-sync clean;
2017-07-15 18:00:44 +02:00
2017-07-15 15:46:52 +02:00
else
2017-07-15 19:52:23 +02:00
print_style "Invalid argument. Use 'up','down','install','trigger' or 'clean'\n" 'danger';
2017-07-15 15:40:25 +02:00
fi