From 9c386f0baca5a5329786291980ae64205bd57ae2 Mon Sep 17 00:00:00 2001 From: Riccardo Paolo Bestetti Date: Wed, 6 Mar 2024 22:38:30 +0100 Subject: [PATCH] Proof-of-concept: allow building sail to run PHP as root This commit is a proof-of-concept to kickstart the PR and should not be merged as-is. --- runtimes/8.0/Dockerfile | 1 + runtimes/8.0/start-container | 11 ++++++++++- runtimes/8.0/supervisord.conf | 2 +- runtimes/8.1/Dockerfile | 1 + runtimes/8.1/start-container | 11 ++++++++++- runtimes/8.1/supervisord.conf | 2 +- runtimes/8.2/Dockerfile | 1 + runtimes/8.2/start-container | 11 ++++++++++- runtimes/8.2/supervisord.conf | 2 +- runtimes/8.3/Dockerfile | 1 + runtimes/8.3/start-container | 11 ++++++++++- runtimes/8.3/supervisord.conf | 2 +- 12 files changed, 48 insertions(+), 8 deletions(-) diff --git a/runtimes/8.0/Dockerfile b/runtimes/8.0/Dockerfile index 2bc1cb3d..25bfba84 100644 --- a/runtimes/8.0/Dockerfile +++ b/runtimes/8.0/Dockerfile @@ -11,6 +11,7 @@ WORKDIR /var/www/html ENV DEBIAN_FRONTEND noninteractive ENV TZ=UTC ENV SUPERVISOR_PHP_COMMAND="/usr/bin/php -d variables_order=EGPCS /var/www/html/artisan serve --host=0.0.0.0 --port=80" +ENV SUPERVISOR_PHP_USER="sail" RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone diff --git a/runtimes/8.0/start-container b/runtimes/8.0/start-container index b8643990..40c55dfe 100644 --- a/runtimes/8.0/start-container +++ b/runtimes/8.0/start-container @@ -1,5 +1,10 @@ #!/usr/bin/env bash +if [ "$SUPERVISOR_PHP_USER" != "root" ] && [ "$SUPERVISOR_PHP_USER" != "sail" ]; then + echo "You should set SUPERVISOR_PHP_USER to either 'sail' or 'root'." + exit 1 +fi + if [ ! -z "$WWWUSER" ]; then usermod -u $WWWUSER sail fi @@ -11,7 +16,11 @@ fi chmod -R ugo+rw /.composer if [ $# -gt 0 ]; then - exec gosu $WWWUSER "$@" + if [ "$SUPERVISOR_PHP_USER" = "root" ]; then + exec "$@" + else + exec gosu $WWWUSER "$@" + fi else exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf fi diff --git a/runtimes/8.0/supervisord.conf b/runtimes/8.0/supervisord.conf index 26ccc0a5..656da8a9 100644 --- a/runtimes/8.0/supervisord.conf +++ b/runtimes/8.0/supervisord.conf @@ -6,7 +6,7 @@ pidfile=/var/run/supervisord.pid [program:php] command=%(ENV_SUPERVISOR_PHP_COMMAND)s -user=sail +user=%(ENV_SUPERVISOR_PHP_USER)s environment=LARAVEL_SAIL="1" stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 diff --git a/runtimes/8.1/Dockerfile b/runtimes/8.1/Dockerfile index 069107f7..b007beb1 100644 --- a/runtimes/8.1/Dockerfile +++ b/runtimes/8.1/Dockerfile @@ -11,6 +11,7 @@ WORKDIR /var/www/html ENV DEBIAN_FRONTEND noninteractive ENV TZ=UTC ENV SUPERVISOR_PHP_COMMAND="/usr/bin/php -d variables_order=EGPCS /var/www/html/artisan serve --host=0.0.0.0 --port=80" +ENV SUPERVISOR_PHP_USER="sail" RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone diff --git a/runtimes/8.1/start-container b/runtimes/8.1/start-container index b8643990..40c55dfe 100644 --- a/runtimes/8.1/start-container +++ b/runtimes/8.1/start-container @@ -1,5 +1,10 @@ #!/usr/bin/env bash +if [ "$SUPERVISOR_PHP_USER" != "root" ] && [ "$SUPERVISOR_PHP_USER" != "sail" ]; then + echo "You should set SUPERVISOR_PHP_USER to either 'sail' or 'root'." + exit 1 +fi + if [ ! -z "$WWWUSER" ]; then usermod -u $WWWUSER sail fi @@ -11,7 +16,11 @@ fi chmod -R ugo+rw /.composer if [ $# -gt 0 ]; then - exec gosu $WWWUSER "$@" + if [ "$SUPERVISOR_PHP_USER" = "root" ]; then + exec "$@" + else + exec gosu $WWWUSER "$@" + fi else exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf fi diff --git a/runtimes/8.1/supervisord.conf b/runtimes/8.1/supervisord.conf index 26ccc0a5..656da8a9 100644 --- a/runtimes/8.1/supervisord.conf +++ b/runtimes/8.1/supervisord.conf @@ -6,7 +6,7 @@ pidfile=/var/run/supervisord.pid [program:php] command=%(ENV_SUPERVISOR_PHP_COMMAND)s -user=sail +user=%(ENV_SUPERVISOR_PHP_USER)s environment=LARAVEL_SAIL="1" stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 diff --git a/runtimes/8.2/Dockerfile b/runtimes/8.2/Dockerfile index ce30a399..e6225d3a 100644 --- a/runtimes/8.2/Dockerfile +++ b/runtimes/8.2/Dockerfile @@ -11,6 +11,7 @@ WORKDIR /var/www/html ENV DEBIAN_FRONTEND noninteractive ENV TZ=UTC ENV SUPERVISOR_PHP_COMMAND="/usr/bin/php -d variables_order=EGPCS /var/www/html/artisan serve --host=0.0.0.0 --port=80" +ENV SUPERVISOR_PHP_USER="sail" RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone diff --git a/runtimes/8.2/start-container b/runtimes/8.2/start-container index b8643990..40c55dfe 100644 --- a/runtimes/8.2/start-container +++ b/runtimes/8.2/start-container @@ -1,5 +1,10 @@ #!/usr/bin/env bash +if [ "$SUPERVISOR_PHP_USER" != "root" ] && [ "$SUPERVISOR_PHP_USER" != "sail" ]; then + echo "You should set SUPERVISOR_PHP_USER to either 'sail' or 'root'." + exit 1 +fi + if [ ! -z "$WWWUSER" ]; then usermod -u $WWWUSER sail fi @@ -11,7 +16,11 @@ fi chmod -R ugo+rw /.composer if [ $# -gt 0 ]; then - exec gosu $WWWUSER "$@" + if [ "$SUPERVISOR_PHP_USER" = "root" ]; then + exec "$@" + else + exec gosu $WWWUSER "$@" + fi else exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf fi diff --git a/runtimes/8.2/supervisord.conf b/runtimes/8.2/supervisord.conf index 26ccc0a5..656da8a9 100644 --- a/runtimes/8.2/supervisord.conf +++ b/runtimes/8.2/supervisord.conf @@ -6,7 +6,7 @@ pidfile=/var/run/supervisord.pid [program:php] command=%(ENV_SUPERVISOR_PHP_COMMAND)s -user=sail +user=%(ENV_SUPERVISOR_PHP_USER)s environment=LARAVEL_SAIL="1" stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 diff --git a/runtimes/8.3/Dockerfile b/runtimes/8.3/Dockerfile index 99670a25..b2a1f39c 100644 --- a/runtimes/8.3/Dockerfile +++ b/runtimes/8.3/Dockerfile @@ -11,6 +11,7 @@ WORKDIR /var/www/html ENV DEBIAN_FRONTEND noninteractive ENV TZ=UTC ENV SUPERVISOR_PHP_COMMAND="/usr/bin/php -d variables_order=EGPCS /var/www/html/artisan serve --host=0.0.0.0 --port=80" +ENV SUPERVISOR_PHP_USER="sail" RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone diff --git a/runtimes/8.3/start-container b/runtimes/8.3/start-container index b8643990..40c55dfe 100644 --- a/runtimes/8.3/start-container +++ b/runtimes/8.3/start-container @@ -1,5 +1,10 @@ #!/usr/bin/env bash +if [ "$SUPERVISOR_PHP_USER" != "root" ] && [ "$SUPERVISOR_PHP_USER" != "sail" ]; then + echo "You should set SUPERVISOR_PHP_USER to either 'sail' or 'root'." + exit 1 +fi + if [ ! -z "$WWWUSER" ]; then usermod -u $WWWUSER sail fi @@ -11,7 +16,11 @@ fi chmod -R ugo+rw /.composer if [ $# -gt 0 ]; then - exec gosu $WWWUSER "$@" + if [ "$SUPERVISOR_PHP_USER" = "root" ]; then + exec "$@" + else + exec gosu $WWWUSER "$@" + fi else exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf fi diff --git a/runtimes/8.3/supervisord.conf b/runtimes/8.3/supervisord.conf index 26ccc0a5..656da8a9 100644 --- a/runtimes/8.3/supervisord.conf +++ b/runtimes/8.3/supervisord.conf @@ -6,7 +6,7 @@ pidfile=/var/run/supervisord.pid [program:php] command=%(ENV_SUPERVISOR_PHP_COMMAND)s -user=sail +user=%(ENV_SUPERVISOR_PHP_USER)s environment=LARAVEL_SAIL="1" stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0