Skip to content

Commit

Permalink
refs #000: keep 8.3.2 phpfpm version available
Browse files Browse the repository at this point in the history
  • Loading branch information
Monska85 committed Feb 13, 2024
1 parent 004d3d9 commit ca04950
Show file tree
Hide file tree
Showing 12 changed files with 232 additions and 0 deletions.
127 changes: 127 additions & 0 deletions 8.3.2/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
ARG PHPVER

FROM golang:1.22.0-alpine3.18 as mailhog

# Install mailhog.
ENV MAILHOG_VERSION 1.0.1
RUN apk add git && \
go install github.com/mailhog/MailHog@v${MAILHOG_VERSION} && \
mv /go/bin/MailHog /go/mailhog

FROM php:$PHPVER as dist

# Build target arch passed by BuildKit
ARG TARGETARCH

# Pass inexistent UUID (e.g.: 1001) to enhance the container security
ARG user=root

# Default php configurations values.
ENV PHP_MEMORY_LIMIT 64M
ENV PHP_TIMEZONE=Europe/Rome
ENV PHP_REALPATH_CACHE_SIZE 2M
ENV PHP_UPLOAD_MAX_FILE_SIZE 32M
ENV PHP_POST_MAX_SIZE 32M
ENV PHP_MAX_EXECUTION_TIME 30
ENV BLACKFIRE_HOST=${BLACKFIRE_HOST:-blackfire}
ENV BLACKFIRE_PORT=${BLACKFIRE_PORT:-8307}
ENV PHP_EXPOSE_PHP 0

# FPM Configurations.
ENV PHP_FPM_PM_TYPE dynamic
ENV PHP_FPM_MAX_CHILDREN 5
ENV PHP_FPM_START_SERVERS 2
ENV PHP_FPM_MIN_SPARE_SERVERS 1
ENV PHP_FPM_MAX_SPARE_SERVERS 3
ENV PHP_FPM_PM_STATUS_PATH /status

ENV XDEBUG_VERSION 3.3.1
ENV MEMCACHE_VERSION 3.2.0
ENV PHPREDIS_VERSION 5.3.7
RUN export XDEBUG_DEPS="linux-headers" && \
export PHP_EXTRA_DEPS="libxml2-dev icu-dev libmemcached-dev cyrus-sasl-dev libpng libjpeg-turbo freetype-dev libpng-dev libjpeg-turbo-dev libzip-dev oniguruma-dev libwebp-dev ldb-dev libldap openldap-dev" && \
apk update && \
apk add ${PHP_EXTRA_DEPS} ${PHPIZE_DEPS} ${XDEBUG_DEPS} gettext && \
docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/ --with-webp=/usr/include && \
docker-php-ext-configure ldap && \
docker-php-ext-install bcmath gd intl mbstring pcntl pdo pdo_mysql soap zip ldap && \
pecl install xdebug-${XDEBUG_VERSION} && \
pecl install redis-${PHPREDIS_VERSION} && \
pecl install igbinary memcached-${MEMCACHE_VERSION} --disable-memcached-sasl && \
apk del ${PHPIZE_DEPS} ${XDEBUG_DEPS} && \
rm -rf /var/cache/apk/*

# Install APCu.
ENV APCU_VERSION 5.1.21
RUN apk add --no-cache --virtual .phpize-deps-configure $PHPIZE_DEPS && \
pecl install apcu-${APCU_VERSION} && \
apk del .phpize-deps-configure

# Install blackfire client.
ENV BLACKFIRE_CLIENT_VERSION 2.8.1
RUN mkdir -p /tmp/blackfire && \
curl -A "Docker" -L https://packages.blackfire.io/binaries/blackfire/${BLACKFIRE_CLIENT_VERSION}/blackfire-linux_${TARGETARCH}.tar.gz | tar zxp -C /tmp/blackfire && \
mv /tmp/blackfire/blackfire /usr/bin/blackfire && \
rm -Rf /tmp/blackfire

# Install blackfire probe.
RUN version=$(php -r "echo PHP_MAJOR_VERSION.PHP_MINOR_VERSION;") \
&& architecture=$(uname -m) \
&& curl -A "Docker" -o /tmp/blackfire-probe.tar.gz -D - -L -s https://blackfire.io/api/v1/releases/probe/php/alpine/$architecture/$version \
&& mkdir -p /tmp/blackfire \
&& tar zxpf /tmp/blackfire-probe.tar.gz -C /tmp/blackfire \
&& mv /tmp/blackfire/blackfire-*.so $(php -r "echo ini_get ('extension_dir');")/blackfire.so \
&& printf "extension=blackfire.so\nblackfire.agent_socket=tcp://\${BLACKFIRE_HOST}:${BLACKFIRE_PORT}\nblackfire.apm_enabled=\${BLACKFIRE_APM_ENABLED}\n" > $PHP_INI_DIR/conf.d/blackfire.ini \
&& rm -rf /tmp/blackfire /tmp/blackfire-probe.tar.gz

# Copy mailhog from golang image.
COPY --from=mailhog /go/mailhog /usr/local/bin/mailhog
RUN chmod +x /usr/local/bin/mailhog

# Configure entrypoint.
COPY docker-entrypoint.sh /docker-entrypoint.sh
RUN chmod +x /docker-entrypoint.sh

# Configure PHP.
COPY conf/*.ini /usr/local/etc/php/conf.d/
COPY conf.disabled /usr/local/etc/php/conf.disabled
COPY fpm-conf-templates/ /templates/

# Make folders writable for the root group
RUN chmod 775 /usr/local/etc/php && \
chmod 775 /usr/local/etc/php/conf.d && \
chmod 775 /usr/local/etc/php-fpm.d && \
chmod 775 /templates

# Go to target user
USER $user

ENTRYPOINT [ "/docker-entrypoint.sh" ]
CMD ["php-fpm"]

FROM dist as dev

# Build target arch passed by BuildKit
ARG TARGETARCH

# Pass inexistent UUID (e.g.: 1001) to enhance the container security
ARG user=root

ARG COMPOSER_VERSION

USER root

ENV COMPOSER_MEMORY_LIMIT -1
ENV COMPOSER_HOME /composer-libs

RUN apk add --no-cache patch rsync git

RUN mkdir $COMPOSER_HOME \
&& chmod -R 775 $COMPOSER_HOME \
&& curl -L -o /usr/local/bin/composer https://github.com/composer/composer/releases/download/${COMPOSER_VERSION}/composer.phar \
&& chmod +x /usr/local/bin/composer \
&& echo "PS1='\[\033[1;36m\]\u\[\033[1;31m\]@\[\033[1;32m\]\h:\[\033[1;35m\]\w\[\033[1;31m\]\$\[\033[0m\] '" >> /etc/profile \
&& echo "export TERM=xterm" >> /etc/profile

# Go to target user
USER $user
1 change: 1 addition & 0 deletions 8.3.2/conf.disabled/apcu.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
extension=apcu.so
1 change: 1 addition & 0 deletions 8.3.2/conf.disabled/mailhog.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sendmail_path="/usr/local/bin/mailhog sendmail --smtp-addr='${MAILHOG_HOST}:${MAILHOG_PORT}' [email protected]"
2 changes: 2 additions & 0 deletions 8.3.2/conf.disabled/memcached.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
extension=igbinary.so
extension=memcached.so
1 change: 1 addition & 0 deletions 8.3.2/conf.disabled/redis.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
extension=redis.so
4 changes: 4 additions & 0 deletions 8.3.2/conf.disabled/xdebug.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
zend_extension=xdebug.so
xdebug.start_with_request=yes
xdebug.client_host=${XDEBUG_REMOTE_HOST}
xdebug.mode=develop
9 changes: 9 additions & 0 deletions 8.3.2/conf/docker.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
realpath_cache_size=${PHP_REALPATH_CACHE_SIZE}
memory_limit=${PHP_MEMORY_LIMIT}
date.timezone=${PHP_TIMEZONE}
upload_max_filesize=${PHP_UPLOAD_MAX_FILE_SIZE}
post_max_size=${PHP_POST_MAX_SIZE}
max_execution_time=${PHP_MAX_EXECUTION_TIME}
max_input_vars=${PHP_MAX_INPUT_VARS}
display_errors=${PHP_DISPLAY_ERRORS}
display_startup_errors=${PHP_DISPLAY_STARTUP_ERRORS}
1 change: 1 addition & 0 deletions 8.3.2/conf/expose.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
expose_php="${PHP_EXPOSE_PHP}"
9 changes: 9 additions & 0 deletions 8.3.2/conf/opcache.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
zend_extension=opcache.so
opcache.enable=${PHP_OPCACHE_ENABLE}
opcache.enable_cli=0
opcache.memory_consumption=${PHP_OPCACHE_MEMORY}
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=100000
opcache.use_cwd=1
opcache.fast_shutdown=1
opcache.revalidate_freq=0
67 changes: 67 additions & 0 deletions 8.3.2/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/sh
export PHP_MEMORY_LIMIT="${PHP_MEMORY_LIMIT:-"128M"}"
export PHP_TIMEZONE="${PHP_TIMEZONE:-"Europe/Rome"}"
export PHP_OPCACHE_ENABLE="${PHP_OPCACHE_ENABLE:-1}"
export PHP_OPCACHE_MEMORY="${PHP_OPCACHE_MEMORY:-64}"
export PHP_MAX_INPUT_VARS="${PHP_MAX_INPUT_VARS:-3000}"
export PHP_DISPLAY_ERRORS="${PHP_DISPLAY_ERRORS:-0}"
export PHP_DISPLAY_STARTUP_ERRORS="${PHP_DISPLAY_STARTUP_ERRORS:-0}"

# Services.
export MAILHOG_ENABLE="${MAILHOG_ENABLE:-0}"
export MEMCACHED_ENABLE="${MEMCACHED_ENABLE:-0}"
export REDIS_ENABLE="${REDIS_ENABLE:-0}"
export XDEBUG_ENABLE="${XDEBUG_ENABLE:-0}"
export LDAP_ENABLE="${LDAP_ENABLE:-0}"

# Services configurations.
export MAILHOG_HOST="${MAILHOG_HOST:-"mail"}"
export MAILHOG_PORT="${MAILHOG_PORT:-1025}"
export APCU_ENABLE="${APCU_ENABLE:-1}"

# Blackfire configurations.
export BLACKFIRE_APM_ENABLED="${BLACKFIRE_APM_ENABLED:-0}"

if [ "${MEMCACHED_ENABLE}" = "1" ]; then
cp /usr/local/etc/php/conf.disabled/memcached.ini /usr/local/etc/php/conf.d/memcached.ini
else
rm -f /usr/local/etc/php/conf.d/memcached.ini || true
fi

if [ "${REDIS_ENABLE}" = "1" ]; then
cp /usr/local/etc/php/conf.disabled/redis.ini /usr/local/etc/php/conf.d/redis.ini
else
rm -f /usr/local/etc/php/conf.d/redis.ini || true
fi

if [ "${MAILHOG_ENABLE}" = "1" ]; then
cp /usr/local/etc/php/conf.disabled/mailhog.ini /usr/local/etc/php/conf.d/mailhog.ini
else
rm -f /usr/local/etc/php/conf.d/mailhog.ini || true
fi

if [ "${XDEBUG_ENABLE}" = "1" ]; then
cp /usr/local/etc/php/conf.disabled/xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini
else
rm -f /usr/local/etc/php/conf.d/xdebug.ini || true
fi

if [ "${LDAP_ENABLE}" = "0" ]; then
rm -f /usr/local/etc/php/conf.d/docker-php-ext-ldap.ini || true
fi

if [ "${APCU_ENABLE}" = "1" ]; then
cp /usr/local/etc/php/conf.disabled/apcu.ini /usr/local/etc/php/conf.d/apcu.ini
else
rm -f /usr/local/etc/php/conf.d/apcu.ini || true
fi

# php-fpm template env subst.
envsubst </templates/zz2-docker-custom.conf >/usr/local/etc/php-fpm.d/zz2-docker-custom.conf

# If the environment is not local, we enable structured logging.
if [ "${ENV:-}" != "loc" ]; then
envsubst </templates/zz3-structured-logs.conf >/usr/local/etc/php-fpm.d/zz3-structured-logs.conf
fi

exec "$@"
8 changes: 8 additions & 0 deletions 8.3.2/fpm-conf-templates/zz2-docker-custom.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[www]
pm = ${PHP_FPM_PM_TYPE}
pm.max_children = ${PHP_FPM_MAX_CHILDREN}
pm.start_servers = ${PHP_FPM_START_SERVERS}
pm.min_spare_servers = ${PHP_FPM_MIN_SPARE_SERVERS}
pm.max_spare_servers = ${PHP_FPM_MAX_SPARE_SERVERS}
pm.status_path = ${PHP_FPM_PM_STATUS_PATH}
access.format = '%{REMOTE_ADDR}e - %{WEBSERVER_REQUEST_ID}e - %t - %s "%m %r%Q%q" %{REQUEST_URI}e'
2 changes: 2 additions & 0 deletions 8.3.2/fpm-conf-templates/zz3-structured-logs.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[www]
access.format = '{"requestId": "%{WEBSERVER_REQUEST_ID}e", "status": %s, "time": "%t", "requestMethod": "%m", "requestUrl": "%r%Q%q", "requestUri": "%{REQUEST_URI}e", "remoteAddr": "%{REMOTE_ADDR}e", "http_x_forwarded_for": "%{X_FORWARDED_FOR}e", "proxy_add_x_forwarded_for": "%{ADD_X_FORWARDED_FOR}e"}';

0 comments on commit ca04950

Please sign in to comment.