From de5539948aaa6e4baf070cc3a1aa29098d149efa Mon Sep 17 00:00:00 2001 From: viniciusss Date: Wed, 29 Nov 2023 16:53:59 -0300 Subject: [PATCH 1/3] (feat): permitir configurar o memory limit --- Dockerfile | 18 ++++++++++-------- apache-run.sh => bin/apache-run | 4 ++++ bin/docker-php-entrypoint | 9 +++++++++ configs/php-memory-limit-apache.ini.dist | 1 + configs/php-memory-limit.ini | 1 + 5 files changed, 25 insertions(+), 8 deletions(-) rename apache-run.sh => bin/apache-run (86%) create mode 100644 bin/docker-php-entrypoint create mode 100644 configs/php-memory-limit-apache.ini.dist create mode 100644 configs/php-memory-limit.ini diff --git a/Dockerfile b/Dockerfile index 0ec650d..067e4ac 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,7 +18,9 @@ ENV \ XDEBUG_VERSION="-3.2.1" \ XDEBUG_REMOTE_PORT=9000 \ PHP_EXTENSION_WDDX=1 \ - PHP_OPENSSL=1 + PHP_OPENSSL=1 \ + PHP_MEMORY_LIMIT="-1" \ + PHP_USE_MEMORY_LIMIT_APACHE=true ENV CONTAINER_STARTED_LOCK=/var/lock/container.starting @@ -78,7 +80,7 @@ RUN echo "---> Adding Tini" && \ RUN echo "---> Config sudoers" && \ echo "www-data ALL = ( ALL ) NOPASSWD: ALL" >> /etc/sudoers -COPY --from=composer:latest /usr/bin/composer /usr/bin/composer +COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer RUN echo "---> Fix permissions" \ && chown -R www-data:www-data /var/log/apache2 \ && mkdir /var/www/.composer && chown -R www-data:www-data /var/www/.composer @@ -86,13 +88,12 @@ RUN echo "---> Fix permissions" \ COPY configs/ports.conf /etc/apache2/ports.conf COPY configs/logs.conf /etc/apache2/conf-enabled/logs.conf COPY configs/php-errors.ini /usr/local/etc/php/conf.d/php-errors.ini -COPY apache-run.sh /usr/bin/apache-run -COPY ./bin /usr/bin/ +COPY configs/php-memory-limit.ini /usr/local/etc/php/conf.d/php-memory-limit.ini +COPY configs/php-memory-limit-apache.ini.dist /usr/local/etc/php/conf.d/php-memory-limit-apache.ini.dist +COPY ./bin /usr/local/bin/ RUN chmod a+x \ - /usr/bin/apache-run \ - /usr/bin/xdebug-set-mode \ - /usr/bin/post-startup-hook + /usr/local/bin/* USER www-data @@ -100,4 +101,5 @@ WORKDIR "/var/www/html" EXPOSE 8080 9001 -CMD ["/tini", "--", "/usr/bin/apache-run"] +ENTRYPOINT [ "docker-php-entrypoint" ] +CMD ["apache-run"] diff --git a/apache-run.sh b/bin/apache-run similarity index 86% rename from apache-run.sh rename to bin/apache-run index bfef85e..4154224 100755 --- a/apache-run.sh +++ b/bin/apache-run @@ -11,6 +11,10 @@ fi sudo -E newrelic-setup sudo -E opcache-setup +if [[ ${PHP_USE_MEMORY_LIMIT_APACHE} == true ]]; then + sudo cp /usr/local/etc/php/conf.d/php-memory-limit-apache.ini.dist /usr/local/etc/php/conf.d/php-memory-limit.ini +fi + if [[ ${SESSION_HANDLER} == true ]]; then sudo rm -f /usr/local/etc/php/conf.d/session-handler.ini echo "session.save_handler = ${SESSION_HANDLER_NAME}" | sudo tee -a /usr/local/etc/php/conf.d/session-handler.ini diff --git a/bin/docker-php-entrypoint b/bin/docker-php-entrypoint new file mode 100644 index 0000000..5454a0a --- /dev/null +++ b/bin/docker-php-entrypoint @@ -0,0 +1,9 @@ +#!/bin/sh +set -e + +# first arg is `-f` or `--some-option` +if [ "${1#-}" != "$1" ]; then + set -- apache2-foreground "$@" +fi + +exec "$@" \ No newline at end of file diff --git a/configs/php-memory-limit-apache.ini.dist b/configs/php-memory-limit-apache.ini.dist new file mode 100644 index 0000000..88ce3fd --- /dev/null +++ b/configs/php-memory-limit-apache.ini.dist @@ -0,0 +1 @@ +memory_limit = 128M \ No newline at end of file diff --git a/configs/php-memory-limit.ini b/configs/php-memory-limit.ini new file mode 100644 index 0000000..e3712df --- /dev/null +++ b/configs/php-memory-limit.ini @@ -0,0 +1 @@ +memory_limit = ${PHP_MEMORY_LIMIT} \ No newline at end of file From 57aa51f6136b94c5118cbd3ee74ac7c5d66a78ae Mon Sep 17 00:00:00 2001 From: viniciusss Date: Wed, 29 Nov 2023 16:56:47 -0300 Subject: [PATCH 2/3] (fix): nao precisa de entrypoint customizado --- Dockerfile | 1 - bin/docker-php-entrypoint | 9 --------- 2 files changed, 10 deletions(-) delete mode 100644 bin/docker-php-entrypoint diff --git a/Dockerfile b/Dockerfile index 067e4ac..f932476 100644 --- a/Dockerfile +++ b/Dockerfile @@ -101,5 +101,4 @@ WORKDIR "/var/www/html" EXPOSE 8080 9001 -ENTRYPOINT [ "docker-php-entrypoint" ] CMD ["apache-run"] diff --git a/bin/docker-php-entrypoint b/bin/docker-php-entrypoint deleted file mode 100644 index 5454a0a..0000000 --- a/bin/docker-php-entrypoint +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh -set -e - -# first arg is `-f` or `--some-option` -if [ "${1#-}" != "$1" ]; then - set -- apache2-foreground "$@" -fi - -exec "$@" \ No newline at end of file From 98b67f42b5d22fdac4673ede753f6260896e8215 Mon Sep 17 00:00:00 2001 From: viniciusss Date: Fri, 1 Dec 2023 15:51:19 -0300 Subject: [PATCH 3/3] (improv): simplificando config de memoria padrao apache --- Dockerfile | 1 - bin/apache-run | 2 +- configs/php-memory-limit-apache.ini.dist | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) delete mode 100644 configs/php-memory-limit-apache.ini.dist diff --git a/Dockerfile b/Dockerfile index f932476..4520c4f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -89,7 +89,6 @@ COPY configs/ports.conf /etc/apache2/ports.conf COPY configs/logs.conf /etc/apache2/conf-enabled/logs.conf COPY configs/php-errors.ini /usr/local/etc/php/conf.d/php-errors.ini COPY configs/php-memory-limit.ini /usr/local/etc/php/conf.d/php-memory-limit.ini -COPY configs/php-memory-limit-apache.ini.dist /usr/local/etc/php/conf.d/php-memory-limit-apache.ini.dist COPY ./bin /usr/local/bin/ RUN chmod a+x \ diff --git a/bin/apache-run b/bin/apache-run index 4154224..b2501f0 100755 --- a/bin/apache-run +++ b/bin/apache-run @@ -12,7 +12,7 @@ sudo -E newrelic-setup sudo -E opcache-setup if [[ ${PHP_USE_MEMORY_LIMIT_APACHE} == true ]]; then - sudo cp /usr/local/etc/php/conf.d/php-memory-limit-apache.ini.dist /usr/local/etc/php/conf.d/php-memory-limit.ini + export PHP_MEMORY_LIMIT=128M fi if [[ ${SESSION_HANDLER} == true ]]; then diff --git a/configs/php-memory-limit-apache.ini.dist b/configs/php-memory-limit-apache.ini.dist deleted file mode 100644 index 88ce3fd..0000000 --- a/configs/php-memory-limit-apache.ini.dist +++ /dev/null @@ -1 +0,0 @@ -memory_limit = 128M \ No newline at end of file