simplify file creation, copy in one layer only

This commit is contained in:
duhow 2024-08-30 13:18:05 +02:00
parent 41129bc8f1
commit 76df7e5869
No known key found for this signature in database

View file

@ -1,5 +1,5 @@
ARG BASE_IMAGE=debian:bullseye-slim ARG BASE_IMAGE=debian:bullseye-slim
FROM ${BASE_IMAGE} FROM ${BASE_IMAGE} AS base
# Install needed dependencies for PHP build # Install needed dependencies for PHP build
#RUN apt-get update && apt-get install -y pkg-config curl libcurl4-openssl-dev libicu-dev \ #RUN apt-get update && apt-get install -y pkg-config curl libcurl4-openssl-dev libicu-dev \
@ -73,61 +73,68 @@ RUN sed -ri 's/^export ([^=]+)=(.*)$/: ${\1:=\2}\nexport \1/' "$APACHE_ENVVARS"
ln -sfT /dev/stdout "$APACHE_LOG_DIR/other_vhosts_access.log"; \ ln -sfT /dev/stdout "$APACHE_LOG_DIR/other_vhosts_access.log"; \
chown -R --no-dereference "$APACHE_RUN_USER:$APACHE_RUN_GROUP" "$APACHE_LOG_DIR"; chown -R --no-dereference "$APACHE_RUN_USER:$APACHE_RUN_GROUP" "$APACHE_LOG_DIR";
# ---
FROM scratch AS apache-config
# Configure php-fpm to log to stdout of the container (stdout of PID 1) # Configure php-fpm to log to stdout of the container (stdout of PID 1)
# We have to use /proc/1/fd/1 because /dev/stdout or /proc/self/fd/1 does not point to the container stdout (because we use apache as entrypoint) # We have to use /proc/1/fd/1 because /dev/stdout or /proc/self/fd/1 does not point to the container stdout (because we use apache as entrypoint)
# We also disable the clear_env option to allow the use of environment variables in php-fpm # We also disable the clear_env option to allow the use of environment variables in php-fpm
RUN { \ COPY <<EOF /etc/php/8.1/fpm/pool.d/zz-docker.conf
echo '[global]'; \ [global]
echo 'error_log = /proc/1/fd/1'; \ error_log = /proc/1/fd/1
echo; \
echo '[www]'; \ [www]
echo 'access.log = /proc/1/fd/1'; \ access.log = /proc/1/fd/1
echo 'catch_workers_output = yes'; \ catch_workers_output = yes
echo 'decorate_workers_output = no'; \ decorate_workers_output = no
echo 'clear_env = no'; \ clear_env = no
} | tee "/etc/php/8.1/fpm/pool.d/zz-docker.conf" EOF
# PHP files should be handled by PHP, and should be preferred over any other file type # PHP files should be handled by PHP, and should be preferred over any other file type
RUN { \ COPY <<EOF /etc/apache2/conf-available/docker-php.conf
echo '<FilesMatch \.php$>'; \ <FilesMatch \\.php$>
echo '\tSetHandler application/x-httpd-php'; \ SetHandler application/x-httpd-php
echo '</FilesMatch>'; \ </FilesMatch>
echo; \
echo 'DirectoryIndex disabled'; \ DirectoryIndex disabled
echo 'DirectoryIndex index.php index.html'; \ DirectoryIndex index.php index.html
echo; \
echo '<Directory /var/www/>'; \ <Directory /var/www/>
echo '\tOptions -Indexes'; \ Options -Indexes
echo '\tAllowOverride All'; \ AllowOverride All
echo '</Directory>'; \ </Directory>
} | tee "$APACHE_CONFDIR/conf-available/docker-php.conf" EOF
# Enable opcache and configure it recommended for symfony (see https://symfony.com/doc/current/performance.html) # Enable opcache and configure it recommended for symfony (see https://symfony.com/doc/current/performance.html)
RUN \ COPY <<EOF /etc/php/8.1/fpm/conf.d/symfony-recommended.ini
{ \ opcache.memory_consumption=256
echo 'opcache.memory_consumption=256'; \ opcache.max_accelerated_files=20000
echo 'opcache.max_accelerated_files=20000'; \ opcache.validate_timestamp=0
echo 'opcache.validate_timestamp=0'; \ # Configure Realpath cache for performance
# Configure Realpath cache for performance realpath_cache_size=4096K
echo 'realpath_cache_size=4096K'; \ realpath_cache_ttl=600
echo 'realpath_cache_ttl=600'; \ EOF
} > /etc/php/8.1/fpm/conf.d/symfony-recommended.ini
# Increase upload limit and enable preloading # Increase upload limit and enable preloading
RUN \ COPY <<EOF /etc/php/8.1/fpm/conf.d/partdb.ini
{ \ upload_max_filesize=256M
echo 'upload_max_filesize=256M'; \ post_max_size=300M
echo 'post_max_size=300M'; \ opcache.preload_user=www-data
echo 'opcache.preload_user=www-data'; \ opcache.preload=/var/www/html/config/preload.php
echo 'opcache.preload=/var/www/html/config/preload.php'; \ EOF
} > /etc/php/8.1/fpm/conf.d/partdb.ini
COPY ./.docker/symfony.conf /etc/apache2/sites-available/symfony.conf
# ---
FROM base
# Set working dir # Set working dir
WORKDIR /var/www/html WORKDIR /var/www/html
COPY --chown=www-data:www-data . . COPY --chown=www-data:www-data . .
COPY --from=apache-config / /
# Setup apache2 # Setup apache2
COPY ./.docker/symfony.conf /etc/apache2/sites-available/symfony.conf
RUN a2dissite 000-default.conf && \ RUN a2dissite 000-default.conf && \
a2ensite symfony.conf && \ a2ensite symfony.conf && \
# Enable php-fpm # Enable php-fpm