-
Notifications
You must be signed in to change notification settings - Fork 0
/
dr.sh
executable file
·194 lines (182 loc) · 4.83 KB
/
dr.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/bin/sh
#loads docker env vars into this process
DENV="./docker.env"
if [ -e $DENV ]; then
. $DENV
fi
#loads user env vars into this process
ENV="./.env"
if [ -e $ENV ]; then
. $ENV
fi
#handle env vars
if [ -z "$DOCKER_YARN_PATH" ]; then
DOCKER_YARN_PATH="themes/"
fi
if [ -z "$DOCKER_CLISCRIPT_PATH" ]; then
DOCKER_CLISCRIPT_PATH="framework/cli-script.php"
fi
if [ -z "$DOCKER_EXEC_IDS" ]; then
DOCKER_EXEC_IDS="`id -u`:`id -g`"
fi
if [ -z "$DOCKER_SHARED_PATH" ]; then
DOCKER_SHARED_PATH="~/docker-data"
fi
CMD=$1
CONTAINER="none"
ACTION="pass"
RUN_OPTS="-it"
CONTAINER_PREFIX=$(basename "$(pwd)")
case "$CMD"
in
php)
CONTAINER="phpcli"
ACTION="php"
;;
composer)
CONTAINER="phpcli"
ACTION="composer"
;;
sspak)
CONTAINER="phpcli"
ACTION="sspak"
;;
phing)
CONTAINER="phpcli"
ACTION="phing"
;;
codecept)
CONTAINER="phpcli"
ACTION="vendor/bin/codecept"
;;
task)
CONTAINER="phpcli"
ACTION="task"
;;
fpm)
CONTAINER="php"
ACTION="bash"
;;
fpmreload)
CONTAINER="php"
ACTION="reload"
;;
mysql)
CONTAINER="mysql"
ACTION="mysql"
;;
mysqlimport)
CONTAINER="mysql"
ACTION="mysql"
RUN_OPTS="-i"
;;
sel)
CONTAINER="selenium"
;;
node)
CONTAINER="node"
ACTION="bash"
;;
yarn)
CONTAINER="node"
ACTION="yarn"
;;
fixperms)
ACTION="fixperms"
;;
help)
ACTION="help"
;;
esac
case "$2"
in
cli)
ACTION="cli"
;;
exec)
ACTION="exec"
;;
esac
# help action
if [ $ACTION = "help" ]; then
echo "Usage: ./dr.sh <container> <action> [args]"
echo " ./dr.sh <action> [args]"
echo ""
echo "<container> : { apache | adminer | php | phpcli | mysql | node | sel }"
echo "<arguments> : { cli | exec [args] | [args] }"
echo ""
echo "[args] : free-form - will be passed as-is to the container"
echo ""
echo "commands : { composer | sspak | phing | codecept | task | fpm"
echo " | fpmreload | mysqlimport | yarn | fixperms | help }"
echo ""
echo "See the readme for more information:"
echo " - https://github.com/symbiote/docker-project/blob/master/readme.md"
exit 1;
fi
# fix perms action
if [ $ACTION = "fixperms" ]; then
#get sudo perms
sudo echo "" > /dev/null
# set perms for project directory
echo "Fixing $PWD"
sudo chown -Rf `id -u`:1000 .
# get shared root (expanding '~')
SHARED=$(eval ls -d -- "$DOCKER_SHARED_PATH")
# shared perms are OS specific (to work around silly mac)
NOT_MAC=$(echo `uname -a` | grep "Darwin")
if [ -z "$NOT_MAC" ]; then
PERMS="775"
else
PERMS="777"
fi
# set blanket perms everything in shared
sudo chown -Rf 1000:33 $SHARED
sudo chmod -Rf $PERMS $SHARED
# loop all dirs in shared
for DIR in $SHARED/*/; do
echo "Fixing $DIR"
# into dir
cd $DIR
# set perms for snowflake dirs
sudo chown -Rf 999:999 mysql-data
sudo chown -Rf 8983:8983 solr-data solr-logs
sudo chmod -Rf 777 logs solr-logs
sudo chmod -Rf 100:101 redis-data
# back out
cd ..
done
exit 1;
fi
# check for container
if [ $CONTAINER = "none" ]; then
echo "Please provide a container or a command to be run. Use the 'dr.sh help' for more information."
exit 1;
fi
# check whether we're running in CI on gitlab
if [ ! -z "${CI}" ]; then
# noop
RUN_OPTS="-i"
echo "Executing in CI, setting to no TTY"
fi
CONTAINER_NAME=${CONTAINER_PREFIX}_${CONTAINER}_1
if [ $ACTION = "cli" ]; then
echo "Dropping to shell in $CONTAINER"
docker exec ${RUN_OPTS} -u ${DOCKER_EXEC_IDS} ${CONTAINER_NAME} /bin/bash
elif [ $ACTION = "exec" ]; then
echo "Execute bash wrapped command on $CONTAINER" && shift && shift
docker exec ${RUN_OPTS} -u ${DOCKER_EXEC_IDS} ${CONTAINER_NAME} bash -c "$@"
else
echo "Running command $ACTION in $CONTAINER" && shift
if [ "yarn" = $CMD ]; then
docker exec ${RUN_OPTS} -u ${DOCKER_EXEC_IDS} ${CONTAINER_NAME} bash -c "cd $DOCKER_YARN_PATH; yarn $*"
elif [ "task" = $CMD ]; then
docker exec ${RUN_OPTS} -u ${DOCKER_EXEC_IDS} ${CONTAINER_NAME} bash -c "php $DOCKER_CLISCRIPT_PATH dev/tasks/$@"
elif [ "mysqlimport" = $CMD ]; then
docker exec ${RUN_OPTS} -u ${DOCKER_EXEC_IDS} ${CONTAINER_NAME} ${ACTION} "$@" < /proc/$$/fd/0
elif [ "fpmreload" = $CMD ]; then
docker exec ${RUN_OPTS} -u ${DOCKER_EXEC_IDS} ${CONTAINER_NAME} ${ACTION} bash -c kill -USR2 1
else
docker exec ${RUN_OPTS} -u ${DOCKER_EXEC_IDS} ${CONTAINER_NAME} ${ACTION} "$@"
fi
fi