Skip to content

Commit cd032b0

Browse files
authored
Proof-of-concept: allow building sail to run PHP as root (#677)
This commit is a proof-of-concept to kickstart the PR and should not be merged as-is.
1 parent 0758cd1 commit cd032b0

File tree

12 files changed

+48
-8
lines changed

12 files changed

+48
-8
lines changed

runtimes/8.0/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ WORKDIR /var/www/html
1111
ENV DEBIAN_FRONTEND noninteractive
1212
ENV TZ=UTC
1313
ENV SUPERVISOR_PHP_COMMAND="/usr/bin/php -d variables_order=EGPCS /var/www/html/artisan serve --host=0.0.0.0 --port=80"
14+
ENV SUPERVISOR_PHP_USER="sail"
1415

1516
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
1617

runtimes/8.0/start-container

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#!/usr/bin/env bash
22

3+
if [ "$SUPERVISOR_PHP_USER" != "root" ] && [ "$SUPERVISOR_PHP_USER" != "sail" ]; then
4+
echo "You should set SUPERVISOR_PHP_USER to either 'sail' or 'root'."
5+
exit 1
6+
fi
7+
38
if [ ! -z "$WWWUSER" ]; then
49
usermod -u $WWWUSER sail
510
fi
@@ -11,7 +16,11 @@ fi
1116
chmod -R ugo+rw /.composer
1217

1318
if [ $# -gt 0 ]; then
14-
exec gosu $WWWUSER "$@"
19+
if [ "$SUPERVISOR_PHP_USER" = "root" ]; then
20+
exec "$@"
21+
else
22+
exec gosu $WWWUSER "$@"
23+
fi
1524
else
1625
exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
1726
fi

runtimes/8.0/supervisord.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pidfile=/var/run/supervisord.pid
66

77
[program:php]
88
command=%(ENV_SUPERVISOR_PHP_COMMAND)s
9-
user=sail
9+
user=%(ENV_SUPERVISOR_PHP_USER)s
1010
environment=LARAVEL_SAIL="1"
1111
stdout_logfile=/dev/stdout
1212
stdout_logfile_maxbytes=0

runtimes/8.1/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ WORKDIR /var/www/html
1111
ENV DEBIAN_FRONTEND noninteractive
1212
ENV TZ=UTC
1313
ENV SUPERVISOR_PHP_COMMAND="/usr/bin/php -d variables_order=EGPCS /var/www/html/artisan serve --host=0.0.0.0 --port=80"
14+
ENV SUPERVISOR_PHP_USER="sail"
1415

1516
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
1617

runtimes/8.1/start-container

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#!/usr/bin/env bash
22

3+
if [ "$SUPERVISOR_PHP_USER" != "root" ] && [ "$SUPERVISOR_PHP_USER" != "sail" ]; then
4+
echo "You should set SUPERVISOR_PHP_USER to either 'sail' or 'root'."
5+
exit 1
6+
fi
7+
38
if [ ! -z "$WWWUSER" ]; then
49
usermod -u $WWWUSER sail
510
fi
@@ -11,7 +16,11 @@ fi
1116
chmod -R ugo+rw /.composer
1217

1318
if [ $# -gt 0 ]; then
14-
exec gosu $WWWUSER "$@"
19+
if [ "$SUPERVISOR_PHP_USER" = "root" ]; then
20+
exec "$@"
21+
else
22+
exec gosu $WWWUSER "$@"
23+
fi
1524
else
1625
exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
1726
fi

runtimes/8.1/supervisord.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pidfile=/var/run/supervisord.pid
66

77
[program:php]
88
command=%(ENV_SUPERVISOR_PHP_COMMAND)s
9-
user=sail
9+
user=%(ENV_SUPERVISOR_PHP_USER)s
1010
environment=LARAVEL_SAIL="1"
1111
stdout_logfile=/dev/stdout
1212
stdout_logfile_maxbytes=0

runtimes/8.2/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ WORKDIR /var/www/html
1111
ENV DEBIAN_FRONTEND noninteractive
1212
ENV TZ=UTC
1313
ENV SUPERVISOR_PHP_COMMAND="/usr/bin/php -d variables_order=EGPCS /var/www/html/artisan serve --host=0.0.0.0 --port=80"
14+
ENV SUPERVISOR_PHP_USER="sail"
1415

1516
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
1617

runtimes/8.2/start-container

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#!/usr/bin/env bash
22

3+
if [ "$SUPERVISOR_PHP_USER" != "root" ] && [ "$SUPERVISOR_PHP_USER" != "sail" ]; then
4+
echo "You should set SUPERVISOR_PHP_USER to either 'sail' or 'root'."
5+
exit 1
6+
fi
7+
38
if [ ! -z "$WWWUSER" ]; then
49
usermod -u $WWWUSER sail
510
fi
@@ -11,7 +16,11 @@ fi
1116
chmod -R ugo+rw /.composer
1217

1318
if [ $# -gt 0 ]; then
14-
exec gosu $WWWUSER "$@"
19+
if [ "$SUPERVISOR_PHP_USER" = "root" ]; then
20+
exec "$@"
21+
else
22+
exec gosu $WWWUSER "$@"
23+
fi
1524
else
1625
exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
1726
fi

runtimes/8.2/supervisord.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pidfile=/var/run/supervisord.pid
66

77
[program:php]
88
command=%(ENV_SUPERVISOR_PHP_COMMAND)s
9-
user=sail
9+
user=%(ENV_SUPERVISOR_PHP_USER)s
1010
environment=LARAVEL_SAIL="1"
1111
stdout_logfile=/dev/stdout
1212
stdout_logfile_maxbytes=0

runtimes/8.3/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ WORKDIR /var/www/html
1111
ENV DEBIAN_FRONTEND noninteractive
1212
ENV TZ=UTC
1313
ENV SUPERVISOR_PHP_COMMAND="/usr/bin/php -d variables_order=EGPCS /var/www/html/artisan serve --host=0.0.0.0 --port=80"
14+
ENV SUPERVISOR_PHP_USER="sail"
1415

1516
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
1617

0 commit comments

Comments
 (0)