-
Notifications
You must be signed in to change notification settings - Fork 0
/
toolbox.sh
executable file
·144 lines (130 loc) · 2.91 KB
/
toolbox.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env bash
cd `dirname $0`
if [ -z ${VOLUME_DIR+x} ]; then
export VOLUME_DIR=`pwd`
fi
if [ -z ${PROJECT_NAME+x} ]; then
export PROJECT_NAME=bus115
fi
export BUS115_DOCKER_DIR=`pwd`
export VOLUME_DIR="$BUS115_DOCKER_DIR"
MYSQL_ROOT_PASS=rootpass
CONTAINER_TOOLBOX_ID=`docker ps --format '{{.ID}}\t{{.Names}}' | grep bus115_bus115_1 | cut -f1`
function ssh_to()
{
if [ -z $1 ]; then
# Connect to toolbox
docker exec -t -i $CONTAINER_TOOLBOX_ID /bin/bash #-u oht
else
# search container
CONTAINER=`docker ps --format 'table {{.Names}}' | grep $1 | tr -d ' '`
if [ -e $CONTAINER ]
then
echo "Container '$1' is not running!. Please select container from this list:"
docker ps
else
docker exec -t -i $CONTAINER /bin/bash
fi
fi
}
function execute_arbitraty(){
if [ -t 1 ] ; then
docker exec -t -i $CONTAINER_TOOLBOX_ID $@
RET=$?
else
echo "$Name Warning: running in a non-interactive environment. Some features may not work"
docker exec $CONTAINER_TOOLBOX_ID $@
RET=$?
fi
return $RET
}
function command_boot()
{
# Start the developer environment
docker-compose -f docker-compose.yml up &
echo -n "Waiting for the services to initialize.. "
while [[ ! $(docker ps | grep bus115_bus115_1) ]] ; do
echo -n "."
sleep 1
done
echo ""
echo "composer install --prefer-source --no-interaction" | docker exec -u bus115 -i bus115_bus115_1 /bin/bash
echo ""
if [[ $1 == "--on-production" ]]; then
echo "REMOVING XDEBUG"
echo "rm -f /usr/local/etc/php/conf.d/xdebug.ini" | docker exec -i bus115_bus115_1 /bin/bash
echo "composer development-disable" | docker exec -u bus115 -i bus115_bus115_1 /bin/bash
else
echo "composer development-enable" | docker exec -u bus115 -i bus115_bus115_1 /bin/bash
fi
}
function command_rebuild(){
DOCKERS=`cat images_list.txt`
for DOCKER in $DOCKERS
do
echo "Building image $DOCKER"
docker build --no-cache -t "$DOCKER" .
done
docker-compose -f docker-compose.yml build
}
function rebuild_apidoc(){
echo "apidoc -i src/ -o public/apidoc/" | docker exec -u bus115 -i bus115_bus115_1 /bin/bash
}
function command_tests(){
echo "vendor/bin/phpunit ./tests/" | docker exec -i bus115_bus115_1 /bin/bash
}
function command_shutdown()
{
docker-compose -f docker-compose.yml down $@
}
function logs(){
tail -f $VOLUME_DIR/data/logs/*
}
while (( "$#" )); do
case "$1" in
boot|up)
shift
command_boot $@
exit
;;
rebuild)
command_rebuild;
exit;
;;
down)
shift
command_shutdown $@
exit
;;
exec)
shift
execute_arbitraty $@
exit $?
;;
tests)
command_tests
exit
;;
logs)
logs
exit
;;
apidoc)
rebuild_apidoc
exit
;;
ssh|connect)
ssh_to $2
exit
;;
clean_docker)
docker container rm -v -f `docker container ls -aq`
docker image rm -f `docker images -q`
exit;
;;
*)
COMMAND=$@
exit $?
;;
esac
done