-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker.sh
executable file
·117 lines (104 loc) · 3.36 KB
/
docker.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/env bash
print_style () {
if [ "$2" == "info" ] ; then
COLOR="96m"
elif [ "$2" == "success" ] ; then
COLOR="92m"
elif [ "$2" == "warning" ] ; then
COLOR="93m"
elif [ "$2" == "danger" ] ; then
COLOR="91m"
else #default color
COLOR="0m"
fi
STARTCOLOR="\e[$COLOR"
ENDCOLOR="\e[0m"
printf "$STARTCOLOR%b$ENDCOLOR" "$1"
}
display_options () {
printf "Available options:\n";
print_style " install_dockersync" "info"; printf "\t\t ONLY MAC Installs docker-sync gem on the host machine.\n"
print_style " init" "info"; printf "\t\t Initialize docker project.\n"
print_style " start" "info"; printf "\t\t Installs docker-sync gem on the host machine.\n"
print_style " synclogs" "info"; printf "\t\t For mac get synchro logs.\n"
print_style " logs" "info"; printf "\t\t Get containers logs\n"
print_style " bash" "info"; printf "\t\t Connect to a container\n"
print_style " xdebug enable/disable" "info"; printf "\t\t enable or disable xdebug on php container r\n"
}
if [[ $# -eq 0 ]] ; then
print_style "Missing arguments.\n" "danger"
display_options
exit 1
fi
if [ ! -f .env ] ; then
if [ "$1" != "init" ] ; then
print_style "You have to use init first \n"
display_options
exit 1
fi
fi
if [ "$1" == "init" ] ; then
rm -rf .env
cp env-conf .env
export $(egrep -v '^#' .env | xargs)
echo $"" >> .env
#Add docker-compose for your platform
composeFiles="docker-compose.yml"
if [ "$(uname)" == "Darwin" ]; then
# Do something under Mac OS X platform
composeFiles="$composeFiles:docker-compose.mac.yml"
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
# Do something under GNU/Linux platform
composeFiles="$composeFiles:docker-compose.linux.yml"
fi
#Now build compose file for each plugins
for plugin in $(echo $PLUGINS | tr "/" "\n")
do
composeFiles="$composeFiles:plugins/$plugin/docker-compose.yml"
done
echo $"COMPOSE_FILE=$composeFiles" >> .env
elif [ "$1" == "install_dockersync" ]; then
if [ "$(uname)" == "Darwin" ]; then
print_style "Installing docker-sync\n" "info"
gem install docker-sync
fi
elif [ "$1" == "start" ]; then
if [ "$(uname)" == "Darwin" ]; then
# Do something under Mac OS X platform
docker-sync start
fi
docker-compose up -d
elif [ "$1" == "logs" ]; then
docker-compose logs -f
elif [ "$1" == "synclogs" ]; then
if [ "$(uname)" == "Darwin" ]; then
# Do something under Mac OS X platform
docker-sync logs -f
fi
elif [ "$1" == "bash" ]; then
NAME=$(docker ps --format '{{.Names}}')
#
arr=($NAME)
PS3='Choose a container : '
select opt in "${arr[@]}"
do
case $opt in
*) docker exec -it $opt bash
break;;
esac
done
elif [ "$1" == "stop" ]; then
if [ "$(uname)" == "Darwin" ]; then
# Do something under Mac OS X platform
docker-sync stop
fi
docker-compose stop
elif [ "$1" == "xdebug" ]; then
# get container names on env
export $(egrep -v '^#' .env | xargs)
chmod a+x docker/scripts/xdebug-$2.sh && ./docker/scripts/xdebug-$2.sh $APPLICATION_NAME"_php" $PHP_VERSION
else
print_style "Invalid arguments.\n" "danger"
display_options
exit 1
fi