Skip to content

Commit 0a75fdd

Browse files
committed
rootless php
1 parent b7674f2 commit 0a75fdd

File tree

3 files changed

+55
-4
lines changed

3 files changed

+55
-4
lines changed

Dockerfile

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ ARG ALPINE_VERSION
77
FROM composer:$COMPOSER_VERSION AS local-composer
88

99
FROM php:$PHP_VERSION-fpm-alpine$ALPINE_VERSION AS base
10-
WORKDIR /app
1110

1211
COPY --from=mlocati/php-extension-installer:2.8.5 /usr/bin/install-php-extensions /usr/bin/
1312

@@ -36,7 +35,7 @@ RUN <<EOT
3635
-e 's/^;?(expose_php).*/\1 = Off/' \
3736
php.ini-production
3837
ln -s php.ini-production php.ini
39-
mkdir -p /run/nginx
38+
mkdir -p /run/nginx /var/lib/nginx/tmp /var/log/nginx
4039
sed -ri -e 's/#(tcp_nopush on;)/\1/' /etc/nginx/nginx.conf
4140
if [ -d /etc/nginx/http.d ]; then
4241
mv /etc/nginx/http.d /etc/nginx/conf.d
@@ -91,6 +90,22 @@ COPY rootfs/ /
9190

9291
CMD ["s6-svscan", "/etc/services.d"]
9392

93+
FROM base AS base-rootless
94+
95+
RUN <<EOT
96+
sed -ri \
97+
-e 's/^;(user) = .*/\1 = www-data/' \
98+
-e 's/^;(group) = .*/\1 = www-data/' \
99+
"$PHP_INI_DIR"/php-fpm.d/www.conf
100+
sed -i 's/^user .*;/user www-data;/' /etc/nginx/nginx.conf
101+
chown -R www-data:www-data /run/nginx /var/lib/nginx /var/log/nginx
102+
EOT
103+
104+
USER www-data:www-data
105+
WORKDIR /app
106+
107+
CMD ["s6-svscan-rootless", "/etc/services.d"]
108+
94109
FROM base AS onbuild
95110

96111
ONBUILD ARG PHP_FPM_PM_MAX_CHILDREN
@@ -141,3 +156,16 @@ ONBUILD RUN <<EOT
141156
clevyr-build
142157
fi
143158
EOT
159+
160+
FROM onbuild AS onbuild-rootless
161+
162+
ONBUILD USER root
163+
164+
ONBUILD RUN <<EOT
165+
set -eux
166+
if [ "${SKIP_BUILD:-}" != "true" ]; then
167+
clevyr-build
168+
fi
169+
EOT
170+
171+
ONBUILD USER www-data:www-data

rootfs/etc/nginx/conf.d/default.conf.tpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
server {
2-
listen 80;
3-
listen [::]:80 default ipv6only=on;
2+
listen 8080;
3+
listen [::]:8080 default ipv6only=on;
44
55
server_name _;
66

rootfs/usr/bin/s6-svscan-rootless

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/sh
2+
3+
set -euo pipefail
4+
5+
# Wrapper to run s6-svscan from a writable directory
6+
# s6-svscan creates .s6-svscan in the service directory, so we need to copy services to /tmp
7+
8+
SERVICE_DIR="$1"
9+
10+
if [ -z "$SERVICE_DIR" ]; then
11+
echo "Usage: $0 <service-directory>" >&2
12+
exit 1
13+
fi
14+
15+
# Create a unique directory in /tmp for our services
16+
TEMP_SERVICE_DIR="/tmp/s6-services-$$"
17+
mkdir -p "$TEMP_SERVICE_DIR"
18+
19+
# Copy the service directory contents to /tmp
20+
cp -r "$SERVICE_DIR"/* "$TEMP_SERVICE_DIR/" 2>/dev/null || cp -r "$SERVICE_DIR"/. "$TEMP_SERVICE_DIR/"
21+
22+
# Run s6-svscan against the copied services
23+
exec s6-svscan "$TEMP_SERVICE_DIR"

0 commit comments

Comments
 (0)