-
Notifications
You must be signed in to change notification settings - Fork 0
/
os
executable file
·321 lines (238 loc) · 9.19 KB
/
os
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
#!/usr/bin/env /bin/bash
# Modified fork of Laravel sail for Alpine-based projects
# Replaces app bash commands with Ash - Alpine Linux Shell
if ! [ -x "$(command -v docker-compose)" ]; then
shopt -s expand_aliases
alias docker-compose='docker compose'
fi
UNAMEOUT="$(uname -s)"
WHITE='\033[1;37m'
NC='\033[0m'
EXEC="yes"
# Verify operating system is supported...
case "${UNAMEOUT}" in
Linux*) MACHINE=linux;;
Darwin*) MACHINE=mac;;
*) MACHINE="UNKNOWN"
esac
if [ "$MACHINE" == "UNKNOWN" ]; then
echo "Unsupported operating system [$(uname -s)]. Laravel Sail supports macOS, Linux, and Windows (WSL2)." >&2
exit 1
fi
# Source the ".env" file so Laravel's environment variables are available...
if [ -f ./.env ]; then
source ./.env
fi
# Define environment variables...
export API_SERVICE=${API_SERVICE:-"openstead-api"}
export FRONTEND_SERVICE=${FRONTEND_SERVICE:-"openstead-frontend"}
if [ $# -gt 0 ]; then
# Proxy PHP commands to the "php" binary on the application container...
if [ "$1" == "php" ]; then
shift 1
docker-compose exec \
"$API_SERVICE" \
php "$@"
elif [ "$1" == "up" ]; then
./os docker-login
docker-compose up -d
elif [ "$1" == "reload" ]; then
./os down && ./os up
elif [ "$1" == "build-api" ]; then
./os docker-login
docker-compose build
elif [ "$1" == "conf" ]; then
./os artisan config:cache
elif [ "$1" == "config:cache" ]; then
./os artisan config:cache
elif [ "$1" == "config:clear" ]; then
./os artisan config:clear
elif [ "$1" == "cache:clear" ]; then
./os artisan cache:clear
elif [ "$1" == "aws:login" ]; then
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 710021134758.dkr.ecr.us-east-1.amazonaws.com
elif [ "$1" == "aws:conf" ]; then
aws configure
elif [ "$1" == "telescope:install" ]; then
shift 1
docker exec $(docker ps -aqf "name=$API_SERVICE") \
/bin/ash -c "php artisan telescope:install" && ./os telescope:migrate
elif [ "$1" == "telescope:migrate" ]; then
shift 1
docker exec $(docker ps -aqf "name=$API_SERVICE") \
/bin/ash -c "php artisan migrate --path=vendor/laravel/telescope/database/migrations/2018_08_08_100000_create_telescope_entries_table.php"
elif [ "$1" == "db:migrate" ]; then
shift 1
docker exec $(docker ps -aqf "name=$API_SERVICE") \
/bin/ash -c "php artisan migrate"
elif [ "$1" == "db:fresh-seed" ]; then
shift 1
docker exec $(docker ps -aqf "name=$API_SERVICE") \
/bin/ash -c "php artisan migrate:fresh --seed"
elif [ "$1" == "analyze" ]; then
shift 1
docker exec $(docker ps -aqf "name=$API_SERVICE") \
/bin/ash -c "vendor/bin/phpstan analyze"
elif [ "$1" == "insights" ]; then
shift 1
docker exec $(docker ps -aqf "name=$API_SERVICE") \
/bin/ash -c "php artisan insights"
elif [ "$1" == "docker-nuke" ]; then
while true; do
echo "
__ ___ ____ _ _ ___ _ _ ____
\ \ / / \ | _ \| \ | |_ _| \ | |/ ___|
\ \ /\ / / _ \ | |_) | \| || || \| | | _
\ V V / ___ \| _ <| |\ || || |\ | |_| |
\_/\_/_/ \_\_| \_\_| \_|___|_| \_|\____|
"
echo ""
echo "This command will destroy all existing local docker assets (containers, images, volumes, networks, etc)"
echo ""
read -p "Are you sure? [y/n]: " yn
case $yn in
[Yy]* ) docker system prune --all -f --volumes; break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
# Proxy vendor binary commands on the application container...
elif [ "$1" == "document" ]; then
shift 1
docker-compose exec \
"$API_SERVICE" \
php artisan scribe:generate
# Proxy vendor binary commands on the application container...
elif [ "$1" == "bin" ]; then
shift 1
docker-compose exec \
"$API_SERVICE" \
./vendor/bin/"$@"
# Proxy Composer commands to the "composer" binary on the application container...
elif [ "$1" == "composer" ]; then
shift 1
docker-compose exec \
"$API_SERVICE" \
/usr/local/bin/php /usr/bin/composer.phar "$@"
# Proxy Artisan commands to the "artisan" binary on the application container...
elif [ "$1" == "artisan" ] || [ "$1" == "art" ]; then
shift 1
docker-compose exec \
"$API_SERVICE" \
php artisan "$@"
# Proxy NPM commands to the frontend container
elif [ "$1" == "npm" ]; then
shift 1
docker-compose exec \
"$FRONTEND_SERVICE" \
npm "$@"
# Proxy the "debug" command to the "php artisan" binary on the application container with xdebug enabled...
elif [ "$1" == "debug" ]; then
shift 1
docker-compose exec \
-e XDEBUG_SESSION=1 \
"$API_SERVICE" \
php artisan "$@"
# Proxy the "test" command to the "php artisan test" Artisan command...
elif [ "$1" == "test" ]; then
shift 1
docker-compose exec \
"$API_SERVICE" \
php artisan test "$@"
# Proxy the "phpunit" command to "php vendor/bin/phpunit"...
elif [ "$1" == "phpunit" ]; then
shift 1
docker-compose exec \
"$API_SERVICE" \
php vendor/bin/phpunit "$@"
# Proxy the "dusk" command to the "php artisan dusk" Artisan command...
elif [ "$1" == "dusk" ]; then
shift 1
docker-compose exec \
-e "APP_URL=http://${APP_SERVICE}" \
-e "DUSK_DRIVER_URL=http://selenium:4444/wd/hub" \
"$API_SERVICE" \
php artisan dusk "$@"
# Proxy the "dusk:fails" command to the "php artisan dusk:fails" Artisan command...
elif [ "$1" == "dusk:fails" ]; then
shift 1
docker-compose exec \
-e "APP_URL=http://${APP_SERVICE}" \
-e "DUSK_DRIVER_URL=http://selenium:4444/wd/hub" \
"$API_SERVICE" \
php artisan dusk:fails "$@"
# Initiate a Laravel Tinker session within the application container...
elif [ "$1" == "tinker" ] ; then
shift 1
docker-compose exec \
"$API_SERVICE" \
php artisan tinker
# Proxy Node commands to the "node" binary on the application container...
elif [ "$1" == "node" ]; then
shift 1
docker-compose exec \
"$API_SERVICE" \
node "$@"
# Proxy NPM commands to the "npm" binary on the application container...
elif [ "$1" == "npm" ]; then
shift 1
docker-compose exec \
"$API_SERVICE" \
npm "$@"
# Proxy NPX commands to the "npx" binary on the application container...
elif [ "$1" == "npx" ]; then
shift 1
docker-compose exec \
"$API_SERVICE" \
npx "$@"
# Proxy YARN commands to the "yarn" binary on the application container...
elif [ "$1" == "yarn" ]; then
shift 1
docker-compose exec \
"$API_SERVICE" \
yarn "$@"
# Initiate a MySQL CLI terminal session within the "mysql" container...
elif [ "$1" == "mysql" ]; then
shift 1
docker-compose exec \
mysql \
bash -c 'MYSQL_PWD=${MYSQL_PASSWORD} mysql -u ${MYSQL_USER} ${MYSQL_DATABASE}'
# Initiate a MySQL CLI terminal session within the "mariadb" container...
elif [ "$1" == "mariadb" ]; then
shift 1
docker-compose exec \
mariadb \
bash -c 'MYSQL_PWD=${MYSQL_PASSWORD} mysql -u ${MYSQL_USER} ${MYSQL_DATABASE}'
# Initiate a PostgreSQL CLI terminal session within the "pgsql" container...
elif [ "$1" == "psql" ]; then
shift 1
docker-compose exec \
pgsql \
bash -c 'PGPASSWORD=${PGPASSWORD} psql -U ${POSTGRES_USER} ${POSTGRES_DB}'
# Initiate a Ash shell within the application container...
elif [ "$1" == "backend-shell" ] || [ "$1" == "ash" ]; then
shift 1
docker exec -it --user www-data $(docker ps -aqf "name=$API_SERVICE") /bin/ash
# Initiate a Ash shell within the application container...
elif [ "$1" == "frontend-shell" ] || [ "$1" == "ash" ]; then
shift 1
docker exec -it --user www-data $(docker ps -aqf "name=$FRONTEND_SERVICE") /bin/ash
# Initiate a root user Ash shell within the application container...
elif [ "$1" == "root" ] ; then
shift 1
docker-compose exec \
"$API_SERVICE" \
/bin/ash "$@"
# Initiate a Redis CLI terminal session within the "redis" container...
elif [ "$1" == "redis" ] ; then
shift 1
docker-compose exec \
redis \
redis-cli
# Pass unknown commands to the "docker-compose" binary...
else
docker-compose "$@"
fi
else
docker-compose ps
fi