blackbirdchess-docker-dev/sync.sh

120 lines
3.9 KiB
Bash
Raw Normal View History

2017-07-15 15:40:25 +02:00
#!/bin/bash
2017-07-15 19:52:23 +02:00
2017-07-15 22:03:33 +02:00
# This shell script is an optional tool to simplify
# the installation and usage of laradock with docker-sync.
# To run, make sure to add permissions to this file:
# chmod 755 sync.sh
# Usage:
2017-07-15 22:36:25 +02:00
# Install docker-sync: ./laradock.sh sync install
# Start sync and services with nginx and mysql: ./laradock.sh sync up nginx mysql
# Stop containers and sync: ./laradock.sh sync down
# Open bash inside the workspace: ./laradock.sh bash
# Force sync: ./laradock.sh sync trigger
# Clean synced files: ./laradock.sh sync clean
2017-07-15 22:03:33 +02:00
2017-07-15 19:52:23 +02:00
# prints colored text
print_style () {
2017-07-15 20:36:15 +02:00
2017-07-15 19:52:23 +02:00
if [ "$2" == "info" ] ; then
2017-07-15 20:24:01 +02:00
COLOR="96m";
2017-07-15 19:52:23 +02:00
elif [ "$2" == "success" ] ; then
2017-07-15 20:24:01 +02:00
COLOR="92m";
2017-07-15 19:52:23 +02:00
elif [ "$2" == "warning" ] ; then
2017-07-15 20:24:01 +02:00
COLOR="93m";
2017-07-15 19:52:23 +02:00
elif [ "$2" == "danger" ] ; then
2017-07-15 21:46:00 +02:00
COLOR="91m";
else #default color
COLOR="0m";
2017-07-15 19:52:23 +02:00
fi
2017-07-15 21:46:00 +02:00
STARTCOLOR="\e[$COLOR";
ENDCOLOR="\e[0m";
2017-07-15 20:24:01 +02:00
printf "$STARTCOLOR%b$ENDCOLOR" "$1";
2017-07-15 19:52:23 +02:00
}
2017-07-15 21:46:00 +02:00
display_options () {
printf "Available options:\n";
2017-07-15 22:58:07 +02:00
print_style " up [services]" "success"; printf "\t Starts workspace and services.\n";
print_style " down" "success"; printf "\t\t\t Stops services.\n";
2017-07-15 22:24:49 +02:00
print_style " bash" "success"; printf "\t\t\t Opens bash on the workspace.\n";
2017-07-15 22:58:07 +02:00
print_style " build" "success"; printf "\t\t\t Builds images.\n";
print_style " sync install" "info"; printf "\t\t Installs docker-sync gem on the host machine.\n";
print_style " sync up [services]" "success"; printf "\t Starts docker-sync and runs docker compose.\n";
print_style " sync down" "success"; printf "\t\t\t Stops containers and docker-sync.\n";
print_style " sync trigger" "success"; printf "\t\t Manually triggers the synchronization of files.\n";
print_style " sync clean" "warning"; printf "\t\t Removes all files from docker-sync.\n";
2017-07-15 21:46:00 +02:00
}
2017-07-15 19:52:23 +02:00
2017-07-15 21:46:00 +02:00
if [[ $# -eq 0 ]] ; then
print_style "Missing arguments.\n" "danger";
display_options;
2017-07-15 15:40:25 +02:00
exit 1
fi
2017-07-15 22:24:59 +02:00
if [ "$1" == "sync" ] ; then
2017-07-15 20:41:35 +02:00
shift; # removing first argument
2017-07-15 22:36:25 +02:00
print_style "Using docker-sync to speed up Docker on OSX and Windows.\n" "success";
2017-07-15 22:24:59 +02:00
if [ "$1" == "up" ] ; then
print_style "Initializing Docker Sync\n" "info";
print_style "May take a long time (15min+) the first run\n" "info";
docker-sync start;
print_style "Initializing Docker Compose\n" "info";
shift; # removing first argument
docker-compose -f docker-compose.yml -f docker-compose.sync.yml up -d ${@};
elif [ "$1" == "down" ]; then
print_style "Stopping Docker Compose\n" "info";
docker-compose down;
print_style "Stopping Docker Sync\n" "info";
docker-sync stop;
elif [ "$1" == "install" ]; then
print_style "Installing docker-sync\n" "info";
gem install docker-sync;
elif [ "$1" == "trigger" ]; then
print_style "Manually triggering sync between host and docker-sync container.\n" "info";
docker-sync sync;
elif [ "$1" == "clean" ]; then
print_style "Removing and cleaning up files from the docker-sync container.\n" "warning";
docker-sync clean;
else
print_style "Invalid arguments.\n" "danger";
display_options;
exit 1
fi
else
2017-07-15 22:36:25 +02:00
print_style "Not using docker-sync might might be slow on OSX and Windows. Use 'sync' option to speed up.\n";
2017-07-15 18:00:44 +02:00
2017-07-15 22:24:59 +02:00
if [ "$1" == "up" ] ; then
print_style "Initializing Docker Compose\n" "info";
shift; # removing first argument
docker-compose up -d ${@};
2017-07-15 22:03:33 +02:00
2017-07-15 22:24:59 +02:00
elif [ "$1" == "down" ]; then
print_style "Stopping Docker Compose\n" "info";
docker-compose down;
2017-07-15 18:00:44 +02:00
2017-07-15 22:36:25 +02:00
elif [ "$1" == "build" ]; then
print_style "Building workspace\n" "info";
docker-compose build workspace;
2017-07-15 22:24:59 +02:00
elif [ "$1" == "bash" ]; then
docker-compose exec workspace bash;
2017-07-15 18:00:44 +02:00
2017-07-15 22:24:59 +02:00
else
print_style "Invalid arguments.\n" "danger";
display_options;
exit 1
fi
2017-07-15 22:03:33 +02:00
2017-07-15 15:40:25 +02:00
fi