From df4fdbde3c520d17dca75bf6c4a8e7996631107c Mon Sep 17 00:00:00 2001 From: Daniel Winning Date: Mon, 14 Apr 2025 02:52:39 +0100 Subject: [PATCH] Add opcache to PHP container --- config/nginx/Dockerfile | 2 +- config/php-fpm/Dockerfile | 9 ++++++--- config/php-fpm/XDebug.Dockerfile | 9 +-------- config/php-fpm/opcache.ini | 8 ++++++++ src/Classes/Config/Config.php | 1 + src/Classes/File/PHPDockerFileBuilder.php | 5 +++++ src/Command/SpinCommand.php | 4 +--- 7 files changed, 23 insertions(+), 15 deletions(-) create mode 100644 config/php-fpm/opcache.ini diff --git a/config/nginx/Dockerfile b/config/nginx/Dockerfile index 6903350..8745dbe 100644 --- a/config/nginx/Dockerfile +++ b/config/nginx/Dockerfile @@ -1,4 +1,4 @@ -FROM nginx:1.23-alpine +FROM nginx:1.23-alpine AS nginx-build CMD ["nginx", "-g", "daemon off;"] diff --git a/config/php-fpm/Dockerfile b/config/php-fpm/Dockerfile index bc84266..9a12dba 100644 --- a/config/php-fpm/Dockerfile +++ b/config/php-fpm/Dockerfile @@ -1,4 +1,4 @@ -FROM php:${PHP_VERSION}-fpm +FROM php:${PHP_VERSION}-fpm AS php-build RUN mkdir -p /var/www/html @@ -11,10 +11,13 @@ RUN apt-get -qq update && apt-get -qq install -y \ libicu-dev \ nano \ bash \ - dnsutils + dnsutils \ + > /dev/null 2>&1 -RUN docker-php-ext-configure intl > /dev/null +RUN docker-php-ext-configure intl > /dev/null 2>&1 RUN docker-php-ext-install mysqli pdo pdo_mysql sockets intl exif bcmath > /dev/null +RUN docker-php-ext-install opcache > /dev/null 2>&1 +COPY ./opcache.ini "${PHP_INI_DIR}/conf.d" COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer diff --git a/config/php-fpm/XDebug.Dockerfile b/config/php-fpm/XDebug.Dockerfile index 95fd859..df3362b 100644 --- a/config/php-fpm/XDebug.Dockerfile +++ b/config/php-fpm/XDebug.Dockerfile @@ -1,10 +1,3 @@ -#RUN pecl install xdebug redis \ -# && docker-php-ext-enable redis -# -#COPY ./xdebug.ini.tmp "${PHP_INI_DIR}/conf.d/xdebug.ini" -#RUN docker-php-ext-install opcache > /dev/null -#COPY ./opcache.ini "${PHP_INI_DIR}/conf.d" - -RUN pecl install xdebug +RUN pecl install xdebug > /dev/null 2&>1 COPY ./xdebug.ini "${PHP_INI_DIR}/conf.d/xdebug.ini" \ No newline at end of file diff --git a/config/php-fpm/opcache.ini b/config/php-fpm/opcache.ini new file mode 100644 index 0000000..4f37efd --- /dev/null +++ b/config/php-fpm/opcache.ini @@ -0,0 +1,8 @@ +opcache.enabled=1 +opcache.revalidate_freq=0 +opcache.validate_timestamps=1 +opcache.max_accelerated_files=10000 +opcache.memory_consumption=192 +opcache.max_wasted_percentage=10 +opcache.interned_strings_buffer=16 +opcache.fast_shutdown=1 \ No newline at end of file diff --git a/src/Classes/Config/Config.php b/src/Classes/Config/Config.php index 1329e3c..2e82204 100644 --- a/src/Classes/Config/Config.php +++ b/src/Classes/Config/Config.php @@ -139,6 +139,7 @@ class Config DataPathInterface::CONFIG_NGINX_DOCKERFILE => new SpinnerFilePath(DataPathInterface::CONFIG_NGINX_DOCKERFILE), 'nodeDockerfileTemplate' => new SpinnerFilePath('config/php-fpm/Node.Dockerfile'), 'xdebugIniTemplate' => new SpinnerFilePath('config/php-fpm/xdebug.ini'), + 'opcacheIniTemplate' => new SpinnerFilePath('config/php-fpm/opcache.ini'), 'xdebugDockerfileTemplate' => new SpinnerFilePath('config/php-fpm/XDebug.Dockerfile'), ]); } diff --git a/src/Classes/File/PHPDockerFileBuilder.php b/src/Classes/File/PHPDockerFileBuilder.php index eb855ef..b43863c 100644 --- a/src/Classes/File/PHPDockerFileBuilder.php +++ b/src/Classes/File/PHPDockerFileBuilder.php @@ -33,6 +33,11 @@ class PHPDockerFileBuilder extends AbstractFileBuilder $this->content = str_replace('${PHP_VERSION}', (string) $this->config->getPhpVersion($input), $this->content); + file_put_contents( + (new SpinnerFilePath(sprintf('data/environments/%s/php-fpm/opcache.ini', $input->getArgument('name'))))->getProvidedPath(), + file_get_contents($this->config->getFilePaths()->get('opcacheIniTemplate')->getAbsolutePath()) + ); + if ($this->config->isNodeEnabled($input)) { $this->addNewLine(); $this->content .= file_get_contents($this->config->getFilePaths()->get('nodeDockerfileTemplate')->getAbsolutePath()); diff --git a/src/Command/SpinCommand.php b/src/Command/SpinCommand.php index 0bad9ce..add4e87 100644 --- a/src/Command/SpinCommand.php +++ b/src/Command/SpinCommand.php @@ -92,15 +92,13 @@ class SpinCommand extends AbstractSpinnerCommand passthru($command); - $this->style->success('Docker images built.'); - return Command::SUCCESS; } protected function projectDataExists(): bool { if ($this->config->getFilePaths()->get('projectData')->exists()) { - $this->style->warning('Project data already exists. Skipping new build.'); + $this->style->warning('Project already exists. Skipping new build.'); return true; }