diff --git a/Dockerfile b/Dockerfile index 66cde638..f9bb5beb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -40,6 +40,7 @@ COPY . /var/www/html # Copy Nginx configuration file COPY nginx.conf /etc/nginx/nginx.conf +COPY services/php/php-fpm-pool.conf /usr/local/etc/php-fpm.d/zz-pleno-workers.conf # Install Composer COPY --from=composer:2.6 /usr/bin/composer /usr/bin/composer diff --git a/Dockerfile.coolify-api b/Dockerfile.coolify-api index 09637c19..a7a2d85d 100644 --- a/Dockerfile.coolify-api +++ b/Dockerfile.coolify-api @@ -47,6 +47,7 @@ RUN set -eux; \ COPY services/nginx/app/ /var/www/html/ COPY services/php/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh +COPY services/php/php-fpm-pool.conf /usr/local/etc/php-fpm.d/zz-pleno-workers.conf COPY services/coolify/api/nginx.conf /etc/nginx/nginx.conf COPY services/coolify/api/start.sh /usr/local/bin/coolify-api-start diff --git a/services/nginx/app/tests/Unit/Infrastructure/PhpFpmWorkerConfigTest.php b/services/nginx/app/tests/Unit/Infrastructure/PhpFpmWorkerConfigTest.php new file mode 100644 index 00000000..0d175b80 --- /dev/null +++ b/services/nginx/app/tests/Unit/Infrastructure/PhpFpmWorkerConfigTest.php @@ -0,0 +1,45 @@ +toBeTrue(); + + $poolConfig = (string)file_get_contents($poolPath); + + expect($poolConfig)->toContain('[www]') + ->and($poolConfig)->toContain('pm = dynamic') + ->and(phpFpmWorkerConfigValue($poolConfig, 'pm.max_children'))->toBeGreaterThanOrEqual(8) + ->and(phpFpmWorkerConfigValue($poolConfig, 'pm.start_servers'))->toBeGreaterThanOrEqual(4) + ->and(phpFpmWorkerConfigValue($poolConfig, 'pm.min_spare_servers'))->toBeGreaterThanOrEqual(4) + ->and(phpFpmWorkerConfigValue($poolConfig, 'pm.max_spare_servers'))->toBeGreaterThanOrEqual(8); +}); + +it('copies the worker pool config into every API PHP image', function (): void { + $copyInstruction = 'COPY services/php/php-fpm-pool.conf /usr/local/etc/php-fpm.d/zz-pleno-workers.conf'; + $dockerfiles = [ + phpFpmWorkerConfigRepoPath('Dockerfile'), + phpFpmWorkerConfigRepoPath('Dockerfile.coolify-api'), + phpFpmWorkerConfigRepoPath('services/php/Dockerfile'), + ]; + + foreach ($dockerfiles as $dockerfile) { + expect(is_file($dockerfile))->toBeTrue(); + expect((string)file_get_contents($dockerfile))->toContain($copyInstruction); + } +}); diff --git a/services/php/Dockerfile b/services/php/Dockerfile index 7498e5ed..6295a8d3 100644 --- a/services/php/Dockerfile +++ b/services/php/Dockerfile @@ -73,6 +73,7 @@ WORKDIR /var/www/html # Copy and enable entrypoint that installs Composer deps on first run COPY services/php/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh +COPY services/php/php-fpm-pool.conf /usr/local/etc/php-fpm.d/zz-pleno-workers.conf RUN sed -i 's/\r$//' /usr/local/bin/docker-entrypoint.sh \ && chmod +x /usr/local/bin/docker-entrypoint.sh diff --git a/services/php/php-fpm-pool.conf b/services/php/php-fpm-pool.conf new file mode 100644 index 00000000..060be9ef --- /dev/null +++ b/services/php/php-fpm-pool.conf @@ -0,0 +1,7 @@ +[www] +pm = dynamic +pm.max_children = 8 +pm.start_servers = 4 +pm.min_spare_servers = 4 +pm.max_spare_servers = 8 +pm.max_requests = 500