-
Notifications
You must be signed in to change notification settings - Fork 0
/
vessel
executable file
·212 lines (183 loc) · 5.85 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
#!/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
export XDEBUG_HOST=$(/sbin/ifconfig docker0 | grep "inet addr" | cut -d ':' -f 2 | cut -d ' ' -f 1)
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 MYSQL_PORT=${MYSQL_PORT:-3306}
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 -f docker-compose.yml"
# 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
$SEDCMD "s/DB_HOST=.*/DB_HOST=mysql/" .env
$SEDCMD "s/CACHE_DRIVER=.*/CACHE_DRIVER=redis/" .env
$SEDCMD "s/SESSION_DRIVER=.*/SESSION_DRIVER=redis/" .env
$SEDCMD "s/REDIS_HOST=.*/REDIS_HOST=redis/" .env
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 "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 vessel \
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 vessel \
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 vessel \
app \
./vendor/bin/phpunit "$@"
else
$COMPOSE run --rm \
app \
./vendor/bin/phpunit "$@"
fi
# If "npm" is used, run npm
# from our node container
elif [ "$1" == "npm" ]; then
shift 1
$COMPOSE run --rm \
node \
npm "$@"
# If "yarn" is used, run yarn
# from our node container
elif [ "$1" == "yarn" ]; then
shift 1
$COMPOSE run --rm \
node \
yarn "$@"
# If "gulp" is used, run gulp
# from our node container
elif [ "$1" == "gulp" ]; then
shift 1
$COMPOSE run --rm \
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 \
mysqldump -u root -p$DB_PASSWORD --default-character-set=utf8mb4 $DB_DATABASE | grep -v "mysqldump: \[Warning\]"
else
$COMPOSE run --rm \
mysql \
mysqldump -h mysql -u root -p$DB_PASSWORD --default-character-set=utf8mb4 $DB_DATABASE | grep -v "mysqldump: \[Warning\]"
fi
# 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