Skip to content

Commit 2e2d00e

Browse files
committed
feat: update entrypoint script to ensure user switching occurs only for root
1 parent 28a429e commit 2e2d00e

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

php/8.4/entrypoint.sh

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,34 @@
11
#!/bin/sh
22
set -e
33

4-
if [ -n "$HOST_UID" ] && [ -n "$HOST_GID" ]; then
5-
WWW_DATA_CURRENT_UID=$(id -u www-data)
6-
WWW_DATA_CURRENT_GID=$(id -g www-data)
7-
8-
if [ "$WWW_DATA_CURRENT_UID" != "$HOST_UID" ] || [ "$WWW_DATA_CURRENT_GID" != "$HOST_GID" ]; then
9-
groupmod -o -g "$HOST_GID" www-data
10-
usermod -o -u "$HOST_UID" www-data
4+
if [ "$(id -u)" = "0" ]; then
5+
if [ -n "$HOST_UID" ] && [ -n "$HOST_GID" ]; then
6+
WWW_DATA_CURRENT_UID=$(id -u www-data)
7+
WWW_DATA_CURRENT_GID=$(id -g www-data)
8+
9+
if [ "$WWW_DATA_CURRENT_UID" != "$HOST_UID" ] || [ "$WWW_DATA_CURRENT_GID" != "$HOST_GID" ]; then
10+
groupmod -o -g "$HOST_GID" www-data
11+
usermod -o -u "$HOST_UID" www-data
12+
fi
1113
fi
12-
fi
1314

14-
if [ -f /etc/nginx/custom.conf ]; then
15-
cp /etc/nginx/custom.conf /etc/nginx/conf.d/default.conf
16-
else
17-
envsubst '$NGINX_ROOT' < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf
18-
fi
15+
if [ -f /etc/nginx/custom.conf ]; then
16+
cp /etc/nginx/custom.conf /etc/nginx/conf.d/default.conf
17+
else
18+
envsubst '$NGINX_ROOT' < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf
19+
fi
1920

20-
if [ "${VITE_ENABLED}" = "true" ]; then
21-
envsubst '$PROJECT_ROOT' < /etc/supervisor/conf.d/vite.conf.template >> /etc/supervisor/conf.d/supervisord.conf
22-
fi
21+
if [ "${VITE_ENABLED}" = "true" ]; then
22+
envsubst '$PROJECT_ROOT' < /etc/supervisor/conf.d/vite.conf.template >> /etc/supervisor/conf.d/supervisord.conf
23+
fi
24+
25+
chown -R www-data:www-data /var/log/supervisor
26+
chown -R www-data:www-data /var/log/nginx
27+
chown -R www-data:www-data /var/lib/nginx
28+
chown -R www-data:www-data /var/run
29+
chown -R www-data:www-data /home/wwwroot
2330

24-
if [ -n "$HOST_UID" ] && [ -n "$HOST_GID" ]; then
25-
exec gosu www-data "$@"
26-
else
27-
exec "$@"
31+
exec gosu www-data "$0" "$@"
2832
fi
33+
34+
exec "$@"

0 commit comments

Comments
 (0)