-
Notifications
You must be signed in to change notification settings - Fork 0
/
vessel
executable file
·277 lines (238 loc) · 7.52 KB
/
vessel
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
#!/usr/bin/env bash
UNAMEOUT="$(uname -s)"
case "${UNAMEOUT}" in
Linux*) MACHINE=linux;;
Darwin*) MACHINE=mac;;
MINGW64_NT-10.0*) MACHINE=mingw64;;
*) MACHINE="UNKNOWN"
esac
if [ "$MACHINE" == "UNKNOWN" ]; then
echo "Unsupported system type"
echo "System must be a Macintosh, Linux or Windows"
echo ""
echo "System detection determined via uname command"
echo "If the following is empty, could not find uname command: $(which uname)"
echo "Your reported uname is: $(uname -s)"
fi
# Set environment variables for dev
if [ "$MACHINE" == "linux" ]; then
if grep -q Microsoft /proc/version; then # WSL
export XDEBUG_HOST=10.0.75.1
else
if [ "$(command -v ip)" ]; then
export XDEBUG_HOST=$(ip addr show docker0 | grep "inet\b" | awk '{print $2}' | cut -d/ -f1)
else
export XDEBUG_HOST=$(ifconfig docker0 | grep "inet addr" | cut -d ':' -f 2 | cut -d ' ' -f 1)
fi
fi
SEDCMD="sed -i"
elif [ "$MACHINE" == "mac" ]; then
export XDEBUG_HOST=$(ipconfig getifaddr en0) # Ethernet
if [ -z "$XDEBUG_HOST" ]; then
export XDEBUG_HOST=$(ipconfig getifaddr en1) # Wifi
fi
SEDCMD="sed -i .bak"
elif [ "$MACHINE" == "mingw64" ]; then # Git Bash
export XDEBUG_HOST=10.0.75.1
SEDCMD="sed -i"
fi
export APP_PORT=${APP_PORT:-80}
export PGSQL_PORT=${PGSQL_PORT:-5432}
export WWWUSER=${WWWUSER:-$UID}
# Is the environment running
PSRESULT="$(docker-compose ps -q)"
if [ ! -z "$PSRESULT" ]; then
EXEC="yes"
else
EXEC="no"
fi
# Create base docker-compose command to run
COMPOSE="docker-compose"
# If we pass any arguments...
if [ $# -gt 0 ]; then
# Source .env, which can over-ride env vars
# such as APP_PORT, MYSQL_PORT, and WWWUSER
if [ -f .env ]; then
source .env
fi
# Edit .env file to set correct hostnames for mysql/redis
if [ "$1" == "init" ]; then
echo "VESSEL: Initializing Vessel..."
COMPOSER=$(which composer)
echo "VESSEL: Installing Predis"
if [ -z "$COMPOSER" ]; then
docker run -u $UID --rm -it \
-v $(pwd):/opt \
-w /opt \
shippingdocker/php-composer:latest \
composer require predis/predis
else
$COMPOSER require predis/predis
fi
if [ ! -f .env ]; then
echo "No .env file found within current working directory $(pwd)"
echo "Create a .env file before re-initializing"
exit 0
fi
echo "VESSEL: Setting .env Variables"
cp .env .env.bak.vessel
if [ ! -z "$(grep "DB_HOST" .env)" ]; then
$SEDCMD "s/DB_HOST=.*/DB_HOST=mysql/" .env
else
echo "DB_HOST=mysql" >>.env
fi
if [ ! -z "$(grep "CACHE_DRIVER" .env)" ]; then
$SEDCMD "s/CACHE_DRIVER=.*/CACHE_DRIVER=redis/" .env
else
echo "CACHE_DRIVER=redis" >>.env
fi
if [ ! -z "$(grep "SESSION_DRIVER" .env)" ]; then
$SEDCMD "s/SESSION_DRIVER=.*/SESSION_DRIVER=redis/" .env
else
echo "SESSION_DRIVER=redis" >>.env
fi
if [ ! -z "$(grep "REDIS_HOST" .env)" ]; then
$SEDCMD "s/REDIS_HOST=.*/REDIS_HOST=redis/" .env
else
echo "REDIS_HOST=redis" >>.env
fi
if [ -f .env.bak ]; then
rm .env.bak
fi
if [ ! -f vessel ]; then
echo "No vessel file found within current working directory $(pwd)"
echo "Have you run the artisan vendor:publish command yet?"
exit 0
fi
echo "VESSEL: Making vessel command available"
chmod +x vessel
echo ""
echo "VESSEL: Complete!"
echo "VESSEL: You can now use Vessel"
echo "VESSEL: Try starting it:"
echo "./vessel start"
# Start up containers
elif [ "$1" == "start" ]; then
$COMPOSE up -d
# Stop the containers
elif [ "$1" == "stop" ]; then
$COMPOSE down
# If "php" is used, pass-thru to "php"
# inside a new container
elif [ "$1" == "php" ]; then
shift 1
if [ "$EXEC" == "yes" ]; then
$COMPOSE exec -u tesseract app php "$@"
else
$COMPOSE run --rm app php "$@"
fi
# If "art" is used, pass-thru to "artisan"
# inside a new container
elif [ "$1" == "artisan" ] || [ "$1" == "art" ]; then
shift 1
if [ "$EXEC" == "yes" ]; then
$COMPOSE exec -u tesseract app php artisan "$@"
else
$COMPOSE run --rm app php artisan "$@"
fi
# If "composer" is used, pass-thru to "composer"
# inside a new container
elif [ "$1" == "composer" ] || [ "$1" == "comp" ]; then
shift 1
if [ "$EXEC" == "yes" ]; then
$COMPOSE exec -u tesseract app composer "$@"
else
$COMPOSE run --rm app composer "$@"
fi
# If "composer" is used, pass-thru to "composer"
# inside a new container
elif [ "$1" == "composer" ] || [ "$1" == "comp" ]; then
shift 1
if [ "$EXEC" == "yes" ]; then
$COMPOSE exec -u tesseract app composer "$@"
else
$COMPOSE run --rm app composer "$@"
fi
# If "test" is used, run unit tests,
# pass-thru any extra arguments to php-unit
elif [ "$1" == "test" ]; then
shift 1
if [ "$EXEC" == "yes" ]; then
$COMPOSE exec -u tesseract app ./vendor/bin/phpunit "$@"
else
$COMPOSE run --rm app ./vendor/bin/phpunit "$@"
fi
# If "tinker" is used, drop into the REPL
# inside a new container
elif [ "$1" == "tinker" ]; then
shift 1
if [ "$EXEC" == "yes" ]; then
$COMPOSE exec -u tesseract app php artisan tinker
else
$COMPOSE run --rm app php artisan tinker
fi
# If "node" is used, run node
# from our node container
elif [ "$1" == "node" ]; then
shift 1
$COMPOSE exec node node "$@"
# If "npm" is used, run npm
# from our node container
elif [ "$1" == "npm" ]; then
shift 1
$COMPOSE exec node npm "$@"
# If "yarn" is used, run yarn
# from our node container
elif [ "$1" == "yarn" ] || [ "$1" == "y" ]; then
shift 1
$COMPOSE exec node yarn "$@"
# If "gulp" is used, run gulp
# from our node container
elif [ "$1" == "gulp" ]; then
shift 1
$COMPOSE exec node ./node_modules/.bin/gulp "$@"
# If "dump" is used, run mysqldump
# from our mysql container
elif [ "$1" == "dump" ]; then
shift 1
if [ "$EXEC" == "yes" ]; then
$COMPOSE exec mysql bash -c 'MYSQL_PWD=$MYSQL_ROOT_PASSWORD mysqldump -u root --default-character-set=utf8mb4 $MYSQL_DATABASE'
else
$COMPOSE run --rm mysql bash -c 'MYSQL_PWD=$MYSQL_ROOT_PASSWORD mysqldump -u root --default-character-set=utf8mb4 $MYSQL_DATABASE'
fi
# If "mysql" is used, run mysql
# from our mysql container
elif [ "$1" == "mysql" ]; then
shift 1
if [ "$EXEC" == "yes" ]; then
$COMPOSE exec mysql bash -c 'MYSQL_PWD=$MYSQL_ROOT_PASSWORD mysql -u root $MYSQL_DATABASE'
else
echo "Error: This command can only be run while a MySQL container is running mysqld (mysql server)."
echo "This command cannot run the server and the mysql client at the same time."
fi
# If "ssh" is used, pass-thru to "ssh"
# inside a new container
# e.g.: ./vessel ssh app
# e.g.: ./vessel ssh mysql
elif [ "$1" == "ssh" ]; then
shift 1
if [ "$EXEC" == "yes" ] && [ "$1" != "node" ]; then
$COMPOSE exec -u tesseract $1 sh
else
$COMPOSE run --rm $1 sh
fi
# phpcs
elif [ "$1" == "phpcs" ]; then
shift 1
docker run --rm -v $(pwd):/data cytopia/phpcs --error-severity=1 --warning-severity=8 --ignore=*/cache/* .
elif [ "$1" == "phpcbf" ]; then
shift 1
docker run --rm -v $(pwd):/data cytopia/phpcbf --error-severity=1 --warning-severity=8 --ignore=*/cache/* .
# Else, pass-thru args to docker-compose
else
$COMPOSE "$@"
fi
else
# Use the docker-compose ps command if nothing else passed through
$COMPOSE ps
fi