Create multi-stage dockerfile #734

This commit is contained in:
Michael Stenta 2023-11-06 11:47:49 -05:00
commit 0df3970683
9 changed files with 92 additions and 97 deletions

View File

@ -1,4 +1,23 @@
# Inherit from the Drupal 10 image on Docker Hub.
# Use the official Drupal 10 image to build GEOS PHP extension.
FROM drupal:10.1 as php-dependencies
# Build and install the GEOS PHP extension.
# See https://git.osgeo.org/gitea/geos/php-geos
ARG PHP_GEOS_VERSION=e77d5a16abbf89a59d947d1fe49381a944762c9d
ADD https://github.com/libgeos/php-geos/archive/${PHP_GEOS_VERSION}.tar.gz /opt/php-geos.tar.gz
RUN apt-get update && apt-get install -y libgeos-dev \
&& ( tar xzf /opt/php-geos.tar.gz -C /opt/ \
&& cd /opt/php-geos-${PHP_GEOS_VERSION} \
&& ./autogen.sh \
&& ./configure \
&& make \
&& make install \
)
# Install the BCMath PHP extension.
RUN docker-php-ext-install bcmath
# Inherit from the official Drupal 10 image.
FROM drupal:10.1
# Set the farmOS and composer project repository URLs and versions.
@ -10,61 +29,23 @@ ARG PROJECT_VERSION=3.x
# Set Apache ServerName directive globally to suppress AH00558 message.
RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf
# Install the BCMath PHP extension.
RUN docker-php-ext-install bcmath
# Install and enable geos.
COPY --from=php-dependencies /usr/local/lib/php/extensions/ /usr/local/lib/php/extensions/
RUN docker-php-ext-enable geos bcmath
# Install git and unzip (needed to build PHP GEOS and needed by Composer).
RUN apt-get update \
&& apt-get install -y git unzip
# Add custom PHP configurations.
COPY conf.d/ /usr/local/etc/php/conf.d
# Build and install the GEOS PHP extension.
# See https://git.osgeo.org/gitea/geos/php-geos
RUN apt-get update && apt-get install -y libgeos-dev \
&& git clone https://github.com/libgeos/php-geos.git \
&& ( \
cd php-geos \
# Checkout latest commit with PHP 8 support.
&& git checkout e77d5a16abbf89a59d947d1fe49381a944762c9d \
&& ./autogen.sh \
&& ./configure \
&& make \
&& make install \
) \
&& rm -r php-geos \
&& docker-php-ext-enable geos
# Set recommended PHP settings for farmOS.
# See https://farmos.org/hosting/installing/#requirements
RUN { \
echo 'memory_limit=256M'; \
echo 'max_execution_time=240'; \
echo 'max_input_time=240'; \
echo 'max_input_vars=5000'; \
echo 'post_max_size=100M'; \
echo 'upload_max_filesize=100M'; \
echo 'expose_php=Off'; \
} > /usr/local/etc/php/conf.d/farmOS-recommended.ini
# Set recommended realpath_cache settings.
# See https://www.drupal.org/docs/7/managing-site-performance/tuning-phpini-for-drupal
RUN { \
echo 'realpath_cache_size=4096K'; \
echo 'realpath_cache_ttl=3600'; \
} > /usr/local/etc/php/conf.d/realpath_cache-recommended.ini
# Set recommended OPcache for maximum performance in Symfony applications.
# See https://symfony.com/doc/current/performance.html#configure-opcache-for-maximum-performance
# @todo
# Remove this when https://github.com/docker-library/drupal/pull/156 is merged.
RUN sed -i 's|opcache.memory_consumption=128|opcache.memory_consumption=256|g' /usr/local/etc/php/conf.d/opcache-recommended.ini \
&& sed -i 's|opcache.max_accelerated_files=4000|opcache.max_accelerated_files=20000|g' /usr/local/etc/php/conf.d/opcache-recommended.ini
# Install postgresql-client so Drush can connect to the database.
RUN apt-get update \
# See https://stackoverflow.com/questions/51033689/how-to-fix-error-on-postgres-install-ubuntu
&& mkdir -p /usr/share/man/man1 \
&& mkdir -p /usr/share/man/man7 \
&& apt-get install -y postgresql-client
# Install apt dependencies.
RUN apt-get update && apt-get install -y \
# Install git and unzip (needed by Composer).
git unzip \
# Install postgresql-client so Drush can connect to the database.
postgresql-client \
# Install libgeos-c1v5 so geos php extension can use libgeos_c.so.1.
libgeos-c1v5 \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
# Set the COMPOSER_MEMORY_LIMIT environment variable to unlimited.
ENV COMPOSER_MEMORY_LIMIT=-1
@ -82,6 +63,5 @@ RUN mkdir /var/farmOS \
# Set the entrypoint.
COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod u+x /usr/local/bin/docker-entrypoint.sh
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["apache2-foreground"]

View File

@ -0,0 +1,9 @@
# Set recommended PHP settings for farmOS.
# See https://farmos.org/hosting/install/#server-requirements
memory_limit=256M
max_execution_time=240
max_input_time=240
max_input_vars=5000
post_max_size=100M
upload_max_filesize=100M
expose_php=Off

View File

@ -0,0 +1,5 @@
# Set recommended OPcache for maximum performance in Symfony applications.
# See https://symfony.com/doc/current/performance.html#configure-opcache-for-maximum-performance
# @todo https://github.com/docker-library/drupal/issues/155
opcache.memory_consumption=256
opcache.max_accelerated_files=20000

View File

@ -0,0 +1,4 @@
# Set recommended realpath_cache settings.
# See https://www.drupal.org/docs/7/managing-site-performance/tuning-phpini-for-drupal
realpath_cache_size=4096K
realpath_cache_ttl=3600

View File

@ -7,13 +7,12 @@ ARG FARMOS_VERSION=3.x
ARG PROJECT_REPO=https://github.com/farmOS/composer-project.git
ARG PROJECT_VERSION=3.x
# Set OPcache's revalidation frequency to 0 seconds for development.
# See https://www.php.net/manual/en/opcache.configuration.php#ini.opcache.revalidate-freq
RUN sed -i 's|opcache.revalidate_freq=60|opcache.revalidate_freq=0|g' /usr/local/etc/php/conf.d/opcache-recommended.ini
# Install and configure XDebug.
# Install and enable XDebug extension.
RUN yes | pecl install xdebug \
&& echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini
&& docker-php-ext-enable xdebug
# Add opcache revalidation frequency configuration.
COPY conf.d/ /usr/local/etc/php/conf.d
# Change the user/group IDs of www-data inside the image to match the ID of the
# developer's user on the host machine. This allows Composer to create files
@ -37,42 +36,8 @@ USER www-data
# Build the farmOS codebase in /var/farmOS.
RUN /usr/local/bin/build-farmOS.sh
# Configure PHP CodeSniffer.
RUN { \
echo '<?xml version="1.0" encoding="UTF-8"?>'; \
echo '<ruleset name="farmOS">'; \
echo ' <description>PHP CodeSniffer configuration for farmOS development.</description>'; \
echo ' <file>.</file>'; \
echo ' <arg name="extensions" value="php,module,inc,install,test,profile,theme,css,info,txt,yml"/>'; \
echo ' <config name="drupal_core_version" value="10"/>'; \
echo ' <rule ref="Drupal">'; \
echo ' <exclude name="Drupal.InfoFiles.AutoAddedKeys.Project"/>'; \
echo ' <exclude name="Drupal.InfoFiles.AutoAddedKeys.Version"/>'; \
echo ' <exclude name="Drupal.Arrays.Array.LongLineDeclaration"/>'; \
# @todo https://www.drupal.org/project/coder/issues/2159253
echo ' <exclude name="Drupal.Commenting.InlineComment.SpacingAfter"/>'; \
echo ' </rule>'; \
echo ' <rule ref="DrupalPractice">'; \
# @todo https://www.drupal.org/project/coder/issues/2159253
echo ' <exclude name="DrupalPractice.Commenting.CommentEmptyLine.SpacingAfter"/>'; \
echo ' </rule>'; \
echo ' <rule ref="PHPCompatibility"/>'; \
echo ' <config name="testVersion" value="8.2-"/>'; \
echo ' <rule ref="Internal.Tokenizer.Exception"><severity>0</severity></rule>'; \
echo '</ruleset>'; \
} > /var/farmOS/phpcs.xml
# Configure PHPStan.
RUN { \
echo 'parameters:'; \
echo ' level: 1'; \
echo ' ignoreErrors:'; \
echo ' # new static() is a best practice in Drupal, so we cannot fix that.'; \
echo " - '#^Unsafe usage of new static#'"; \
echo ' scanDirectories:'; \
echo ' # Tell PHPStan where to find GeoPHP classes.'; \
echo ' - vendor/itamair/geophp'; \
} > /var/farmOS/phpstan.neon
# Add Configurartions for PHP CodeSniffer, PHPStan.
COPY --chown=www-data ./files/ /var/farmOS/
# Configure PHPUnit.
RUN cp -p /var/farmOS/web/core/phpunit.xml.dist /var/farmOS/phpunit.xml \

View File

@ -0,0 +1,3 @@
# Set OPcache's revalidation frequency to 0 seconds for development.
# See https://www.php.net/manual/en/opcache.configuration.php#ini.opcache.revalidate-freq
opcache.revalidate_freq=0

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="farmOS">
<description>PHP CodeSniffer configuration for farmOS development.</description>
<file>.</file>
<arg name="extensions" value="php,module,inc,install,test,profile,theme,css,info,txt,yml"/>
<config name="drupal_core_version" value="10"/>
<rule ref="Drupal">
<exclude name="Drupal.InfoFiles.AutoAddedKeys.Project"/>
<exclude name="Drupal.InfoFiles.AutoAddedKeys.Version"/>
<exclude name="Drupal.Arrays.Array.LongLineDeclaration"/>
# @todo https://www.drupal.org/project/coder/issues/2159253
<exclude name="Drupal.Commenting.InlineComment.SpacingAfter"/>
</rule>
<rule ref="DrupalPractice">
# @todo https://www.drupal.org/project/coder/issues/2159253
<exclude name="DrupalPractice.Commenting.CommentEmptyLine.SpacingAfter"/>
</rule>
<rule ref="PHPCompatibility"/>
<config name="testVersion" value="8.2-"/>
<rule ref="Internal.Tokenizer.Exception"><severity>0</severity></rule>
</ruleset>

View File

@ -0,0 +1,8 @@
parameters:
level: 1
ignoreErrors:
# new static() is a best practice in Drupal, so we cannot fix that.
- '#^Unsafe usage of new static#'
scanDirectories:
# Tell PHPStan where to find GeoPHP classes.
- vendor/itamair/geophp

0
docker/docker-entrypoint.sh Normal file → Executable file
View File