-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdock
executable file
·71 lines (61 loc) · 1.31 KB
/
dock
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
#!/usr/bin/env bash
set -e
usage() {
cat <<EOF
Usage: $0 <command> [options]
Commands:
init Initialize the .env file from .env.example if it doesn't exist.
test Run PHPUnit tests using the specified PHP version.
composer Run Composer commands using the specified PHP version.
<service> Run a specified Docker service with optional arguments.
Examples:
$0 init
$0 test --filter=MyTest
$0 composer install
$0 php8.1 bash
EOF
exit 1
}
if [ "$#" -lt 1 ]; then
usage
fi
run_service() {
local service=$1
shift
if ! docker compose run --rm "$service" "$@"; then
exit 1
fi
}
case "$1" in
init)
if [ ! -f ".env" ]; then
cp ".env.example" ".env"
echo "cp '.env.example' '.env'"
fi
exit 0;
;;
esac
if [ ! -f ".env" ]; then
echo "Project does not have a .env file. Please provide one or run: dock init"
exit 0
fi
PHP_VERSION=$(grep "^PHP_VERSION=" .env | cut -d '=' -f2-)
case "$1" in
test)
shift
run_service "php${PHP_VERSION}" vendor/bin/phpunit "$@"
;;
build)
shift
docker compose build "php${PHP_VERSION}" "$@"
docker compose build "debug${PHP_VERSION}" "$@"
docker compose build "composer${PHP_VERSION}" "$@"
;;
composer)
shift
run_service "composer${PHP_VERSION}" composer "$@"
;;
*)
run_service "$@"
;;
esac