diff --git a/.github/docker/README.md b/.github/docker/README.md index 989222e35..e61845316 100644 --- a/.github/docker/README.md +++ b/.github/docker/README.md @@ -105,6 +105,6 @@ The policy depends on whether the extension system is enabled, even if no extens Set `LARAVEL_OPTIMIZE=false` to disable deployment caching for diagnostics; startup still removes old snapshots. Changing `.env` requires a container restart; changing Compose environment variables requires recreating the container. One-off entrypoint commands do not rebuild caches. Run documentation generation in a fresh, isolated command container as described above. -`PHP_FPM_MAX_CHILDREN` (default `9`) and `PHP_FPM_MAX_REQUESTS` (default `200`) configure the existing on-demand pool. `PHP_OPCACHE_MEMORY_CONSUMPTION` controls shared OPcache memory in MiB (default `128`). OPcache retains comments for reflection/documentation and disables JIT. The image does not disable timestamp checks because extensions and framework cache files can change at runtime. +`PHP_FPM_MAX_CHILDREN` (default `9`) and `PHP_FPM_MAX_REQUESTS` (default `200`) configure the existing on-demand pool. `PHP_OPCACHE_MEMORY_CONSUMPTION` controls shared OPcache memory in MiB (default `128`). OPcache retains comments for reflection/documentation and disables JIT. The image does not disable timestamp checks because extensions and framework cache files can change at runtime. `PHP_OPCACHE_REVALIDATE_FREQ` (default `2`) sets how many seconds a worker reuses a cached script before checking its timestamp again, so changed PHP files take effect within that window. `0` checks on every request, which roughly doubles PHP CPU time per request. These are starting values, not workload-specific tuning. Size the worker pool from measured busy-worker memory and the container's memory limit, leaving room for the queue worker, scheduler, OPcache, and Nginx. Increase concurrency only after measuring request latency, CPU use, and memory under representative load. Recreate the container after changing PHP sizing variables. diff --git a/.github/docker/default.conf b/.github/docker/default.conf index 4817c749c..d2fb35a7d 100644 --- a/.github/docker/default.conf +++ b/.github/docker/default.conf @@ -17,10 +17,26 @@ server { } location ^~ /assets/ { + # Compress static build output only. Dynamic responses stay uncompressed so + # secrets in them cannot leak through compression side channels (BREACH). + gzip on; + gzip_comp_level 5; + gzip_min_length 1024; + gzip_proxied any; + gzip_vary on; + gzip_types text/css text/javascript application/javascript application/json image/svg+xml; + location ~ /\. { deny all; } + # Build output is content-hashed, so it never changes under the same name. + # Extension assets keep their own names and are revalidated as usual. + location ~ "^/assets/(?!extensions/).+\.[A-Za-z0-9_-]{8}\.(?:js|css|svg|woff2?)$" { + expires 1y; + try_files $uri =404; + } + try_files $uri =404; } diff --git a/.github/docker/default_ssl.conf b/.github/docker/default_ssl.conf index 363577be4..56fb430a2 100644 --- a/.github/docker/default_ssl.conf +++ b/.github/docker/default_ssl.conf @@ -49,10 +49,27 @@ server { } location ^~ /assets/ { + # Compress static build output only. Dynamic responses stay uncompressed so + # secrets in them cannot leak through compression side channels (BREACH). + gzip on; + gzip_comp_level 5; + gzip_min_length 1024; + gzip_proxied any; + gzip_vary on; + gzip_types text/css text/javascript application/javascript application/json image/svg+xml; + location ~ /\. { deny all; } + # Build output is content-hashed, so it never changes under the same name. + # Extension assets keep their own names and are revalidated as usual. This uses + # `expires` rather than add_header so the server-level security headers still apply. + location ~ "^/assets/(?!extensions/).+\.[A-Za-z0-9_-]{8}\.(?:js|css|svg|woff2?)$" { + expires 1y; + try_files $uri =404; + } + try_files $uri =404; } diff --git a/.github/docker/healthcheck.sh b/.github/docker/healthcheck.sh index 2e212d39c..117f9e73b 100644 --- a/.github/docker/healthcheck.sh +++ b/.github/docker/healthcheck.sh @@ -1,17 +1,19 @@ #!/bin/ash set -eu -check_process() { - status=$(supervisorctl status "$1") - printf '%s\n' "$status" | awk '$2 != "RUNNING" { exit 1 }' -} - -check_process nginx -check_process php-fpm +required="nginx php-fpm" if [ "$QUEUE_WORKER_ENABLED" = true ]; then - check_process queue-worker + required="$required queue-worker" fi if [ "$SCHEDULER_ENABLED" = true ]; then - check_process scheduler + required="$required scheduler" fi + +# Query every program in one call; each supervisorctl run starts a Python interpreter. +# Fail on any line that is not RUNNING, and on missing lines if supervisord is unreachable. +# shellcheck disable=SC2086 +supervisorctl status $required | awk -v expected="$(echo $required | wc -w)" ' + $2 != "RUNNING" { bad = 1 } + END { exit (bad || NR != expected) } +' curl --fail --silent --show-error --max-time 5 http://127.0.0.1:8080/ping | grep -qx pong diff --git a/.github/docker/php.ini b/.github/docker/php.ini index 9bd5c05a2..ea5c203c5 100644 --- a/.github/docker/php.ini +++ b/.github/docker/php.ini @@ -1,10 +1,12 @@ ; Keep timestamp checks for runtime-generated caches and live extension updates. +; Checking every request stats ~900 files per request; a short interval keeps changes +; live within seconds at a fraction of the cost. opcache.enable=1 opcache.memory_consumption=${PHP_OPCACHE_MEMORY_CONSUMPTION} opcache.interned_strings_buffer=16 opcache.max_accelerated_files=20000 opcache.validate_timestamps=1 -opcache.revalidate_freq=0 +opcache.revalidate_freq=${PHP_OPCACHE_REVALIDATE_FREQ} opcache.save_comments=1 opcache.jit=disable opcache.jit_buffer_size=0 diff --git a/.github/docker/smoke-test.sh b/.github/docker/smoke-test.sh index b5ad73949..4bee40d2a 100755 --- a/.github/docker/smoke-test.sh +++ b/.github/docker/smoke-test.sh @@ -156,7 +156,7 @@ test "$(docker exec "$redis" redis-cli get smoke-preserved)" = yes docker run -d --name "$dynamic" --network "$prefix" "${environment[@]}" \ -e APP_ENVIRONMENT_ONLY=false -e PTERODACTYL_EXTENSIONS_ENABLED=true \ -e QUEUE_WORKER_ENABLED=false -e SCHEDULER_ENABLED=false \ - -e PHP_FPM_MAX_CHILDREN=3 -e PHP_OPCACHE_MEMORY_CONSUMPTION=192 \ + -e PHP_FPM_MAX_CHILDREN=3 -e PHP_OPCACHE_MEMORY_CONSUMPTION=192 -e PHP_OPCACHE_REVALIDATE_FREQ=5 \ "$image" >/dev/null wait_for healthy "$dynamic" docker exec "$dynamic" /bin/ash -ec ' @@ -165,6 +165,7 @@ docker exec "$dynamic" /bin/ash -ec ' test ! -f bootstrap/cache/events.php php-fpm -tt 2>&1 | grep -q "pm.max_children = 3" php -r '\''exit(ini_get("opcache.memory_consumption") === "192" ? 0 : 1);'\'' + php -r '\''exit(ini_get("opcache.revalidate_freq") === "5" ? 0 : 1);'\'' ' for name in 'First live name' 'Second live name'; do docker exec -i -e SMOKE_NAME="$name" "$dynamic" php <<'PHP' diff --git a/Dockerfile b/Dockerfile index 65eba2e04..04d117397 100644 --- a/Dockerfile +++ b/Dockerfile @@ -52,7 +52,8 @@ ENV APP_ENV=production \ LARAVEL_OPTIMIZE=true \ PHP_FPM_MAX_CHILDREN=9 \ PHP_FPM_MAX_REQUESTS=200 \ - PHP_OPCACHE_MEMORY_CONSUMPTION=128 + PHP_OPCACHE_MEMORY_CONSUMPTION=128 \ + PHP_OPCACHE_REVALIDATE_FREQ=2 COPY --from=dependencies /app /app COPY --from=dependencies /usr/local/bin/composer /usr/local/bin/composer diff --git a/resources/scripts/router/routeTree.ts b/resources/scripts/router/routeTree.ts index 519914475..9f231a8de 100644 --- a/resources/scripts/router/routeTree.ts +++ b/resources/scripts/router/routeTree.ts @@ -72,10 +72,6 @@ import { getBootstrapExtensions, hasBootstrapSession } from '@/bootstrap'; import { registerClassPrefixes } from '@/lib/cn'; import RootLayout from '@/router/layouts/RootLayout'; import AuthLayout from '@/router/layouts/AuthLayout'; -import AuthenticatedLayout from '@/router/layouts/AuthenticatedLayout'; -import AccountLayout from '@/router/layouts/AccountLayout'; -import ServerLayout from '@/router/layouts/ServerLayout'; -import AdminLayout from '@/router/layouts/AdminLayout'; import RootNotFound from '@/router/RootNotFound'; import { RouteAccessDenied } from '@/router/RouteError'; import { eggIdParam, idParam, scheduleIdParam } from '@/router/params'; @@ -158,7 +154,9 @@ const authenticatedRoute = createRoute({ loader: async ({ context }) => { await context.queryClient.ensureQueryData({ ...currentUserQueryOptions(), revalidateIfStale: true }); }, - component: AuthenticatedLayout, + // Layouts behind the session are lazy so the login screen does not ship the navigation + // bar, admin sidebar, or server console in the entry chunk. + component: lazyRouteComponent(() => import('@/router/layouts/AuthenticatedLayout')), }); const dashboardRoute = createRoute({ @@ -183,7 +181,7 @@ const dashboardRoute = createRoute({ const accountRoute = createRoute({ getParentRoute: () => authenticatedRoute, path: 'account', - component: AccountLayout, + component: lazyRouteComponent(() => import('@/router/layouts/AccountLayout')), }); const accountChildren = [ createRoute({ @@ -256,7 +254,7 @@ const serverRoute = createRoute({ return { serverUuid: server.attributes.uuid, serverPermissions: selectServerPermissions(server) }; }, - component: ServerLayout, + component: lazyRouteComponent(() => import('@/router/layouts/ServerLayout')), }); const serverChildren = [ // ServerLayout renders the console itself. @@ -462,7 +460,7 @@ const panelRoute = createRoute({ throw new RouteAccessDenied('You do not have permission to access the administrative area.'); } }, - component: AdminLayout, + component: lazyRouteComponent(() => import('@/router/layouts/AdminLayout')), }); const adminPage = slottedRouteComponent;