-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdockerize-clis-php.sh
74 lines (60 loc) · 2.06 KB
/
dockerize-clis-php.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
DOCKERIZE_PHP=${DOCKERIZE_PHP:-false}
DOCKERIZE_COMPOSER=${DOCKERIZE_COMPOSER:-false}
DOCKERIZE_PHPUNIT=${DOCKERIZE_PHPUNIT:-false}
DOCKERIZE_PHPSTAN=${DOCKERIZE_PHPSTAN:-false}
PHP_VERSION=${PHP_VERSION:-8.1}
PHP_PUBLISH_PORTS=${PHP_PUBLISH_PORTS:-""} # ex: "--publish 8000:8000"
PHP_USER=${PHP_USER:-$(id -u):$(id -g)} # or: www-data
COMPOSER_HOME=${COMPOSER_HOME:-$HOME/.composer}
# Volumes mounted in every container
DOCKER_COMMON_VOLUMES=${DOCKER_COMMON_VOLUMES:-""}
if [ "$DOCKERIZE_PHP" = true ]; then
function php {
tty=
tty -s && tty=--tty
docker run $tty --interactive --rm \
--user $PHP_USER \
$DOCKER_COMMON_VOLUMES \
--volume $(dockerize_bind_path $(pwd)):/code \
--workdir $(dockerize_path '/code') \
$PHP_PUBLISH_PORTS \
php:$PHP_VERSION-cli php "$@"
}
fi
if [ "$DOCKERIZE_COMPOSER" = true ]; then
function composer {
[ ! -d "$COMPOSER_HOME" ] && echo "Creating \$COMPOSER_HOME directory ($COMPOSER_HOME)" && mkdir $COMPOSER_HOME
tty=
tty -s && tty=--tty
docker run $tty --interactive --rm \
--user $PHP_USER \
$DOCKER_COMMON_VOLUMES \
--volume $(dockerize_bind_path $COMPOSER_HOME):/tmp \
--volume $(dockerize_bind_path $(pwd)):/code \
--workdir $(dockerize_path '/code') \
composer "$@"
}
function laravel {
if [ ! -f "$COMPOSER_HOME/vendor/bin/laravel" ]; then
echo "Installing Laravel Installer globally..."
echo ""
composer global require "laravel/installer"
echo ""
fi
composer $(dockerize_path '/tmp/vendor/bin/laravel') "$@"
}
fi
if [ "$DOCKERIZE_PHPUNIT" = true ]; then
function phpunit {
php vendor/phpunit/phpunit/phpunit "$@"
}
fi
if [ "$DOCKERIZE_PHPSTAN" = true ]; then
function phpstan {
tty=
tty -s && tty=--tty
docker run $tty --interactive --rm \
--volume $(dockerize_bind_path $(pwd)):/app \
phpstan/phpstan "$@"
}
fi