-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathdocker.sh
83 lines (72 loc) · 2.31 KB
/
docker.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
75
76
77
78
79
80
81
82
83
build() {
local with_exakat=""
if [[ "$*" == *--with-exakat* ]]; then
with_exakat="--build-arg WITH_EXAKAT=1"
fi
local without_watchr=""
if [[ "$*" == *--without-watchr* ]] || [ "$PHP_VERSION" = "81" ]; then
without_watchr="--build-arg WITHOUT_WATCHR=1"
fi
echo -e "Building \033[0;32m$PHPCTL_IMAGE\033[0m"
# shellcheck disable=SC2068
# shellcheck disable=SC2154
$PHPCTL_RUNTIME buildx build \
--build-arg PHP="$PHP_VERSION" \
--build-arg COMPOSER_AUTH="$COMPOSER_AUTH" \
--build-arg HOST_USER="$(whoami)" \
$with_exakat \
$without_watchr \
${build[@]} -t "$PHPCTL_IMAGE" .
}
push() {
echo -e "Pushing \033[0;32m$PHPCTL_IMAGE\033[0m"
$PHPCTL_RUNTIME push "$PHPCTL_IMAGE"
}
pull() {
echo -e "Pulling \033[0;32m$PHPCTL_IMAGE\033[0m"
$PHPCTL_RUNTIME pull "$PHPCTL_IMAGE"
}
images() {
$PHPCTL_RUNTIME images | grep phpctl
}
run() {
if [ -n "$PHPCTL_VERBOSE" ]; then
echo -e "Running \033[0;32m$PHPCTL_IMAGE\033[0m"
fi
local phpctl_ini=""
if [ -s phpctl.ini ]; then
phpctl_ini="-v $(pwd)/phpctl.ini:/etc/php$PHP_VERSION/conf.d/zzzphp.ini"
fi
local composer_home=""
composer_home="$(composer-home)"
if [ -n "$composer_home" ]; then
composer_home="-v $composer_home:$composer_home"
fi
local gitconfig=""
if [ -f ~/.gitconfig ]; then
gitconfig="-v $HOME/.gitconfig:/root/.gitconfig:ro"
fi
if [ -n "$GIT_EXEC_PATH" ]; then
# In a Git hook environment, we need to disable TTY allocation
PHPCTL_TTY="--label=no-tty"
fi
# shellcheck disable=SC2046
# shellcheck disable=SC2068
# shellcheck disable=SC2086
# shellcheck disable=SC2154
$PHPCTL_RUNTIME run \
--init \
--platform linux/x86_64 \
--rm "$PHPCTL_TTY" \
--name "phpctl_$(openssl rand -hex 6)" \
--user "$PHPCTL_USER" \
$(env | awk -F= '/^[[:alpha:]]/{print $1}' | sed 's/^/-e/') \
-v /var/run/docker.sock:/var/run/docker.sock \
$gitconfig \
-v "$(pwd)":/usr/local/src -w /usr/local/src \
-v "$PHPCTL_DIR/php.ini:/etc/php$PHP_VERSION/conf.d/zphp.ini" \
$phpctl_ini \
$composer_home \
--net host --entrypoint sh \
${args[@]} "$1" "$PHPCTL_IMAGE" -c "${*:2}"
}