Skip to content

Commit

Permalink
Create multi-stage dockerfile and run the service as www-data user
Browse files Browse the repository at this point in the history
Helping with Issue farmOS#582
  • Loading branch information
AlMaVizca committed Oct 11, 2023
1 parent 010a895 commit 7ebd0aa
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 51 deletions.
83 changes: 32 additions & 51 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
# Inherit from the Drupal 9 image on Docker Hub.
FROM drupal:9.5 as geos
# Install git and unzip (needed to build PHP GEOS and needed by Composer).
# RUN apt-get update \
# && apt-get install -y git

ARG PHP_GEOS_VERSION=e77d5a16abbf89a59d947d1fe49381a944762c9d
# Build and install the GEOS PHP extension.
# See https://git.osgeo.org/gitea/geos/php-geos
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\
)


FROM drupal:9.5


# Install postgresql-client so Drush can connect to the database.
RUN apt-get update \
&& apt-get install -y git unzip postgresql-client\
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean

# Set the farmOS and composer project repository URLs and versions.
ARG FARMOS_REPO=https://github.com/farmOS/farmOS.git
ARG FARMOS_VERSION=2.x
Expand All @@ -13,58 +39,12 @@ RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf
# Install the BCMath PHP extension.
RUN docker-php-ext-install bcmath

# Install git and unzip (needed to build PHP GEOS and needed by Composer).
RUN apt-get update \
&& apt-get install -y git unzip

# 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
# Install and enable geos
COPY --from=geos /usr/local/lib/php/extensions/ /usr/local/lib/php/extensions/
RUN docker-php-ext-enable geos

# 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
#Add custom configurations
COPY conf.d/ /usr/local/etc/php/conf.d

# Set the COMPOSER_MEMORY_LIMIT environment variable to unlimited.
ENV COMPOSER_MEMORY_LIMIT=-1
Expand All @@ -83,5 +63,6 @@ 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"]
1 change: 1 addition & 0 deletions docker/build-farmOS.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ sed -i "s|version: 2.x|version: ${FARMOS_VERSION}|g" /var/farmOS/web/profiles/fa

# Remove the Composer cache directory.
rm -rf "$COMPOSER_HOME"
chown -R www-data:www-data /var/www/html/sites
9 changes: 9 additions & 0 deletions docker/conf.d/farmOS-recommended.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Set recommended PHP settings for farmOS.
# See https://farmos.org/hosting/installing/#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
6 changes: 6 additions & 0 deletions docker/conf.d/opcache-recommended.overrides.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# 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.
opcache.memory_consumption=256
opcache.max_accelerated_files=20000
5 changes: 5 additions & 0 deletions docker/conf.d/realpath_cache-recommended.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# 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

0 comments on commit 7ebd0aa

Please sign in to comment.