Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docker/php/etc/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ if [ -n "${PUID:-}" ] && [ "${PUID}" != "1000" ]; then
fi
fi

UID_REMAP_CHANGED=0
if [ -n "${PUID:-}" ]; then
CURRENT_UID=$(id -u www-data)
if [ "${CURRENT_UID}" != "${PUID}" ]; then
echo "Updating www-data UID to ${PUID}..."
if ! sudo usermod -u "${PUID}" www-data; then
echo "Warning: could not update www-data UID to ${PUID}; continuing with UID ${CURRENT_UID}." >&2
else
UID_REMAP_CHANGED=1
fi
fi
fi
Expand Down Expand Up @@ -136,4 +139,8 @@ if [ -n "${NODE_VERSION:-}" ]; then
fi
fi

if [ "${UID_REMAP_CHANGED}" = "1" ] && [ "$(id -u)" != "$(id -u www-data)" ]; then
exec sudo -E -H -u www-data "$@"
fi

exec "$@"
10 changes: 10 additions & 0 deletions tests/php_runtime_cron_support_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ func TestPHPEntrypointUpdatesGIDBeforeUID(t *testing.T) {
}
}

func TestPHPEntrypointRelaunchesProcessAfterUIDRemap(t *testing.T) {
content := readProjectFileForTest(t, filepath.Join("docker", "php", "etc", "entrypoint.sh"))
if !strings.Contains(content, "UID_REMAP_CHANGED=1") {
t.Fatalf("expected php entrypoint to track successful UID remaps, got:\n%s", content)
}
if !strings.Contains(content, "exec sudo -E -H -u www-data \"$@\"") {
t.Fatalf("expected php entrypoint to launch php-fpm as remapped www-data, got:\n%s", content)
}
}

func TestPHPEntrypointStartsCrondBestEffort(t *testing.T) {
content := readProjectFileForTest(t, filepath.Join("docker", "php", "etc", "entrypoint.sh"))
if !strings.Contains(content, "sudo crond 2>/dev/null || true") {
Expand Down