From 939989727ade47f886fc9ebc02f761a5f4c27fec Mon Sep 17 00:00:00 2001 From: Lucas Mirloup <97196064+lucasmirloup@users.noreply.github.com> Date: Tue, 5 Mar 2024 20:02:20 +0100 Subject: [PATCH 1/4] refactor: merge all Dockerfile into one + compose.yaml, use Docker Bake WIP --- .github/workflows/main.yml | 50 +++++++------ 7.4/Dockerfile | 64 ----------------- 7.4/symfony.ini | 18 ----- 8.0/Dockerfile | 65 ----------------- 8.0/symfony.ini | 18 ----- 8.0/symfony.pool.conf | 81 ---------------------- 8.1/Dockerfile | 68 ------------------ 8.1/symfony.pool.conf | 81 ---------------------- 8.2/Dockerfile | 68 ------------------ 8.2/symfony.ini | 18 ----- 8.2/symfony.pool.conf | 81 ---------------------- Dockerfile | 71 +++++++++++++++++++ compose.yaml | 38 ++++++++++ 8.1/symfony.ini => symfony.ini | 1 + 7.4/symfony.pool.conf => symfony.pool.conf | 0 15 files changed, 140 insertions(+), 582 deletions(-) delete mode 100644 7.4/Dockerfile delete mode 100644 7.4/symfony.ini delete mode 100644 8.0/Dockerfile delete mode 100644 8.0/symfony.ini delete mode 100644 8.0/symfony.pool.conf delete mode 100644 8.1/Dockerfile delete mode 100644 8.1/symfony.pool.conf delete mode 100644 8.2/Dockerfile delete mode 100644 8.2/symfony.ini delete mode 100644 8.2/symfony.pool.conf create mode 100644 Dockerfile create mode 100644 compose.yaml rename 8.1/symfony.ini => symfony.ini (96%) rename 7.4/symfony.pool.conf => symfony.pool.conf (100%) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0d1a7af..43c1889 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -21,14 +21,38 @@ jobs: strategy: fail-fast: false matrix: - php_version: - - '7.4' - - '8.0' - - '8.1' - - '8.2' + platform: + - linux/amd64 + - linux/arm64 steps: - - uses: actions/checkout@v2 + - name: Prepare + run: | + platform=${{ matrix.platform }} + echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV + + - uses: actions/checkout@v4 + + - name: Docker meta + id: docker_meta + uses: docker/metadata-action@v5 + with: + images: lephare/php + tags: | + type=raw,${{ matrix.php_version }} + + - + name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - + name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} - name: Set up Docker Buildx id: setup-buildx @@ -38,20 +62,6 @@ jobs: linux/amd64 linux/arm64 - - name: Login to Docker Hub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: Docker meta - id: meta - uses: docker/metadata-action@v4 - with: - images: lephare/php - tags: | - type=raw,${{ matrix.php_version }} - - name: Build and push uses: docker/build-push-action@v4 with: diff --git a/7.4/Dockerfile b/7.4/Dockerfile deleted file mode 100644 index ea842c5..0000000 --- a/7.4/Dockerfile +++ /dev/null @@ -1,64 +0,0 @@ -FROM php:7.4-fpm - -ENV XDEBUG_VERSION 3.1.6 - -# Xdebug: remote step debugging port -EXPOSE 9003 - -RUN apt-get update \ - && apt-get full-upgrade -y \ - && apt-get install -y --no-install-recommends \ - locales \ - git \ - ssh \ - unzip \ - libfreetype6-dev \ - libjpeg62-turbo-dev \ - libpng-dev \ - libmemcached-dev \ - libzip-dev \ - libicu-dev \ - libpq-dev \ - libssh2-1 libssh2-1-dev \ - libxml2-dev \ - libwebp-dev \ - libmagickwand-dev \ - # oniguruma not bundled in php, use libonig: https://www.php.net/manual/en/migration74.other-changes.php - libonig-dev \ - && rm -rf /var/lib/apt/lists/* \ - && dpkg-reconfigure -f noninteractive locales \ - && echo 'en_US.UTF-8 UTF-8' > /etc/locale.gen \ - && echo 'fr_FR.UTF-8 UTF-8' >> /etc/locale.gen \ - && locale-gen - -# migrating to pkg-config: https://www.php.net/manual/en/migration74.other-changes.php#migration74.other-changes.pkg-config -RUN docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp \ - && docker-php-ext-install -j$(nproc) intl gd opcache mbstring zip pdo_pgsql pdo_mysql soap pgsql mysqli exif - -# PECL modules -RUN pecl install imagick && docker-php-ext-enable imagick -RUN pecl install memcached && docker-php-ext-enable memcached -RUN pecl install apcu && docker-php-ext-enable apcu -RUN pecl install ssh2-1.2 && docker-php-ext-enable ssh2 -RUN pecl install xdebug-$XDEBUG_VERSION && docker-php-ext-enable xdebug - -# Install Composer -ENV COMPOSER_ALLOW_SUPERUSER 1 -COPY --from=composer /usr/bin/composer /usr/local/bin/composer - -# Install Blackfire -RUN export VERSION=`php -r "echo PHP_MAJOR_VERSION.PHP_MINOR_VERSION;"` \ - && export ARCHITECTURE=$(uname -m) \ - && curl -A "Docker" -o /tmp/blackfire-probe.tar.gz -D - -L -s https://blackfire.io/api/v1/releases/probe/php/linux/${ARCHITECTURE}/${VERSION} \ - && tar zxpf /tmp/blackfire-probe.tar.gz -C /tmp \ - && mv /tmp/blackfire-*.so `php -r "echo ini_get('extension_dir');"`/blackfire.so \ - && echo "extension=blackfire.so\nblackfire.agent_socket=tcp://blackfire:8707" > $PHP_INI_DIR/conf.d/blackfire.ini - -RUN usermod -u 1000 www-data -RUN usermod -G staff www-data - -WORKDIR /var/www/symfony - -# Config -COPY symfony.ini $PHP_INI_DIR/conf.d/ -COPY symfony.pool.conf $PHP_INI_DIR/pool.d/ diff --git a/7.4/symfony.ini b/7.4/symfony.ini deleted file mode 100644 index ae6b4dc..0000000 --- a/7.4/symfony.ini +++ /dev/null @@ -1,18 +0,0 @@ -short_open_tag = Off -magic_quotes_gpc = Off -register_globals = Off -session.autostart = Off -date.timezone = Europe/Paris -upload_max_filesize = 32M -post_max_size = 33M -session.save_handler = "memcached" -session.save_path = "memcached:11211" -max_execution_time = 600 -memory_limit = 1024M -memcached.sess_lock_wait_min = 150 -memcached.sess_lock_wait_max = 150 -memcached.sess_lock_retries = 800 -opcache.max_accelerated_files=7963 -opcache.memory_consumption=192 -opcache.interned_strings_buffer=32 -opcache.fast_shutdown=1 diff --git a/8.0/Dockerfile b/8.0/Dockerfile deleted file mode 100644 index a67e2ae..0000000 --- a/8.0/Dockerfile +++ /dev/null @@ -1,65 +0,0 @@ -FROM php:8.0-fpm - -ARG PICKLE_EXTENSIONS - -RUN apt-get update \ - && apt-get full-upgrade -y \ - && apt-get install -y --no-install-recommends \ - locales \ - git \ - ssh \ - unzip \ - libfreetype6-dev \ - libjpeg62-turbo-dev \ - libpng-dev \ - libmemcached-dev \ - libzip-dev \ - libicu-dev \ - libpq-dev \ - libssh2-1 libssh2-1-dev \ - libxml2-dev \ - libwebp-dev \ - libmagickwand-dev \ - # oniguruma not bundled in php, use libonig: https://www.php.net/manual/en/migration74.other-changes.php - libonig-dev \ - && rm -rf /var/lib/apt/lists/* \ - && dpkg-reconfigure -f noninteractive locales \ - && echo 'en_US.UTF-8 UTF-8' > /etc/locale.gen \ - && echo 'fr_FR.UTF-8 UTF-8' >> /etc/locale.gen \ - && locale-gen - -# migrating to pkg-config: https://www.php.net/manual/en/migration74.other-changes.php#migration74.other-changes.pkg-config -RUN docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp \ - && docker-php-ext-install -j$(nproc) intl gd opcache mbstring zip pdo_pgsql soap pgsql exif - -# Extra extensions using pickle: https://github.com/docker-library/php/pull/840#issuecomment-502251019 -ADD https://github.com/FriendsOfPHP/pickle/releases/download/v0.7.7/pickle.phar /usr/local/bin/pickle -ENV PICKLE_EXTENSIONS=${PICKLE_EXTENSIONS:-"apcu memcached imagick xdebug"} -RUN chmod +x /usr/local/bin/pickle && \ - ( \ - for extension in $PICKLE_EXTENSIONS; do \ - pickle install -n $extension; \ - docker-php-ext-enable $extension; \ - done \ - ) - -# Install Composer -ENV COMPOSER_ALLOW_SUPERUSER 1 -COPY --from=composer /usr/bin/composer /usr/local/bin/composer - -# # Install Blackfire -RUN export VERSION=`php -r "echo PHP_MAJOR_VERSION.PHP_MINOR_VERSION;"` \ - && echo https://blackfire.io/api/v1/releases/probe/php/linux/amd64/${VERSION} \ - && curl -A "Docker" -o /tmp/blackfire-probe.tar.gz -D - -L -s https://blackfire.io/api/v1/releases/probe/php/linux/amd64/${VERSION} \ - && tar zxpf /tmp/blackfire-probe.tar.gz -C /tmp \ - && mv /tmp/blackfire-*.so `php -r "echo ini_get('extension_dir');"`/blackfire.so \ - && echo -e "extension=blackfire.so\nblackfire.agent_socket=tcp://blackfire:8707" > $PHP_INI_DIR/conf.d/blackfire.ini - -RUN usermod -u 1000 www-data -RUN usermod -G staff www-data - -WORKDIR /var/www/symfony - -# Config -COPY symfony.ini $PHP_INI_DIR/conf.d/ -COPY symfony.pool.conf $PHP_INI_DIR/pool.d/ diff --git a/8.0/symfony.ini b/8.0/symfony.ini deleted file mode 100644 index ae6b4dc..0000000 --- a/8.0/symfony.ini +++ /dev/null @@ -1,18 +0,0 @@ -short_open_tag = Off -magic_quotes_gpc = Off -register_globals = Off -session.autostart = Off -date.timezone = Europe/Paris -upload_max_filesize = 32M -post_max_size = 33M -session.save_handler = "memcached" -session.save_path = "memcached:11211" -max_execution_time = 600 -memory_limit = 1024M -memcached.sess_lock_wait_min = 150 -memcached.sess_lock_wait_max = 150 -memcached.sess_lock_retries = 800 -opcache.max_accelerated_files=7963 -opcache.memory_consumption=192 -opcache.interned_strings_buffer=32 -opcache.fast_shutdown=1 diff --git a/8.0/symfony.pool.conf b/8.0/symfony.pool.conf deleted file mode 100644 index 94649b1..0000000 --- a/8.0/symfony.pool.conf +++ /dev/null @@ -1,81 +0,0 @@ -; Start a new pool named 'symfony'. -; the variable $pool can we used in any directive and will be replaced by the -; pool name ('symfony' here) -[symfony] - -; Unix user/group of processes -; Note: The user is mandatory. If the group is not set, the default user's group -; will be used. -user = www-data -group = www-data - -; The address on which to accept FastCGI requests. -; Valid syntaxes are: -; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific address on -; a specific port; -; 'port' - to listen on a TCP socket to all addresses on a -; specific port; -; '/path/to/unix/socket' - to listen on a unix socket. -; Note: This value is mandatory. -listen = 0.0.0.0:9000 - -; Choose how the process manager will control the number of child processes. -; Possible Values: -; static - a fixed number (pm.max_children) of child processes; -; dynamic - the number of child processes are set dynamically based on the -; following directives. With this process management, there will be -; always at least 1 children. -; pm.max_children - the maximum number of children that can -; be alive at the same time. -; pm.start_servers - the number of children created on startup. -; pm.min_spare_servers - the minimum number of children in 'idle' -; state (waiting to process). If the number -; of 'idle' processes is less than this -; number then some children will be created. -; pm.max_spare_servers - the maximum number of children in 'idle' -; state (waiting to process). If the number -; of 'idle' processes is greater than this -; number then some children will be killed. -; ondemand - no children are created at startup. Children will be forked when -; new requests will connect. The following parameter are used: -; pm.max_children - the maximum number of children that -; can be alive at the same time. -; pm.process_idle_timeout - The number of seconds after which -; an idle process will be killed. -; Note: This value is mandatory. -pm = dynamic - -; The number of child processes to be created when pm is set to 'static' and the -; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'. -; This value sets the limit on the number of simultaneous requests that will be -; served. Equivalent to the ApacheMaxClients directive with mpm_prefork. -; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP -; CGI. The below defaults are based on a server without much resources. Don't -; forget to tweak pm.* to fit your needs. -; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand' -; Note: This value is mandatory. -pm.max_children = 20 - -; The number of child processes created on startup. -; Note: Used only when pm is set to 'dynamic' -; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2 -pm.start_servers = 2 - -; The desired minimum number of idle server processes. -; Note: Used only when pm is set to 'dynamic' -; Note: Mandatory when pm is set to 'dynamic' -pm.min_spare_servers = 1 - -; The desired maximum number of idle server processes. -; Note: Used only when pm is set to 'dynamic' -; Note: Mandatory when pm is set to 'dynamic' -pm.max_spare_servers = 3 - -;--------------------- - -; Make specific Docker environment variables available to PHP -env[DB_1_ENV_MYSQL_DATABASE] = $DB_1_ENV_MYSQL_DATABASE -env[DB_1_ENV_MYSQL_USER] = $DB_1_ENV_MYSQL_USER -env[DB_1_ENV_MYSQL_PASSWORD] = $DB_1_ENV_MYSQL_PASSWORD - -catch_workers_output = yes diff --git a/8.1/Dockerfile b/8.1/Dockerfile deleted file mode 100644 index 3b260d6..0000000 --- a/8.1/Dockerfile +++ /dev/null @@ -1,68 +0,0 @@ -FROM php:8.1-fpm - -ARG PICKLE_EXTENSIONS -ENV PICKLE_VERSION v0.7.11 - -RUN apt-get update \ - && apt-get full-upgrade -y \ - && apt-get install -y --no-install-recommends \ - locales \ - git \ - ssh \ - unzip \ - libfreetype6-dev \ - libjpeg62-turbo-dev \ - libpng-dev \ - libmemcached-dev \ - libzip-dev \ - libicu-dev \ - libpq-dev \ - libssh2-1 libssh2-1-dev \ - libxml2-dev \ - libwebp-dev \ - libmagickwand-dev \ - # oniguruma not bundled in php, use libonig: https://www.php.net/manual/en/migration74.other-changes.php - libonig-dev \ - && rm -rf /var/lib/apt/lists/* \ - && dpkg-reconfigure -f noninteractive locales \ - && echo 'en_US.UTF-8 UTF-8' > /etc/locale.gen \ - && echo 'fr_FR.UTF-8 UTF-8' >> /etc/locale.gen \ - && locale-gen - -# migrating to pkg-config: https://www.php.net/manual/en/migration74.other-changes.php#migration74.other-changes.pkg-config -RUN docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp \ - && docker-php-ext-install -j$(nproc) intl gd opcache mbstring zip pdo_pgsql soap pgsql exif - -# Extra extensions using pickle: https://github.com/docker-library/php/pull/840#issuecomment-502251019 -ADD https://github.com/FriendsOfPHP/pickle/releases/download/${PICKLE_VERSION}/pickle.phar /usr/local/bin/pickle -ENV PICKLE_EXTENSIONS=${PICKLE_EXTENSIONS:-"apcu memcached imagick xdebug"} -RUN chmod +x /usr/local/bin/pickle && \ - ( \ - for extension in $PICKLE_EXTENSIONS; do \ - pickle install -n $extension; \ - docker-php-ext-enable $extension; \ - done \ - ) - -# Install Composer -ENV COMPOSER_ALLOW_SUPERUSER 1 -COPY --from=composer /usr/bin/composer /usr/local/bin/composer - -# Install Blackfire (https://blackfire.io/docs/php/integrations/php-docker) -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/linux/$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:8307\n" > $PHP_INI_DIR/conf.d/blackfire.ini \ - && rm -rf /tmp/blackfire /tmp/blackfire-probe.tar.gz - -RUN usermod -u 1000 www-data -RUN usermod -G staff www-data - -WORKDIR /var/www/symfony - -# Config -COPY symfony.ini $PHP_INI_DIR/conf.d/ -COPY symfony.pool.conf $PHP_INI_DIR/pool.d/ diff --git a/8.1/symfony.pool.conf b/8.1/symfony.pool.conf deleted file mode 100644 index 94649b1..0000000 --- a/8.1/symfony.pool.conf +++ /dev/null @@ -1,81 +0,0 @@ -; Start a new pool named 'symfony'. -; the variable $pool can we used in any directive and will be replaced by the -; pool name ('symfony' here) -[symfony] - -; Unix user/group of processes -; Note: The user is mandatory. If the group is not set, the default user's group -; will be used. -user = www-data -group = www-data - -; The address on which to accept FastCGI requests. -; Valid syntaxes are: -; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific address on -; a specific port; -; 'port' - to listen on a TCP socket to all addresses on a -; specific port; -; '/path/to/unix/socket' - to listen on a unix socket. -; Note: This value is mandatory. -listen = 0.0.0.0:9000 - -; Choose how the process manager will control the number of child processes. -; Possible Values: -; static - a fixed number (pm.max_children) of child processes; -; dynamic - the number of child processes are set dynamically based on the -; following directives. With this process management, there will be -; always at least 1 children. -; pm.max_children - the maximum number of children that can -; be alive at the same time. -; pm.start_servers - the number of children created on startup. -; pm.min_spare_servers - the minimum number of children in 'idle' -; state (waiting to process). If the number -; of 'idle' processes is less than this -; number then some children will be created. -; pm.max_spare_servers - the maximum number of children in 'idle' -; state (waiting to process). If the number -; of 'idle' processes is greater than this -; number then some children will be killed. -; ondemand - no children are created at startup. Children will be forked when -; new requests will connect. The following parameter are used: -; pm.max_children - the maximum number of children that -; can be alive at the same time. -; pm.process_idle_timeout - The number of seconds after which -; an idle process will be killed. -; Note: This value is mandatory. -pm = dynamic - -; The number of child processes to be created when pm is set to 'static' and the -; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'. -; This value sets the limit on the number of simultaneous requests that will be -; served. Equivalent to the ApacheMaxClients directive with mpm_prefork. -; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP -; CGI. The below defaults are based on a server without much resources. Don't -; forget to tweak pm.* to fit your needs. -; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand' -; Note: This value is mandatory. -pm.max_children = 20 - -; The number of child processes created on startup. -; Note: Used only when pm is set to 'dynamic' -; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2 -pm.start_servers = 2 - -; The desired minimum number of idle server processes. -; Note: Used only when pm is set to 'dynamic' -; Note: Mandatory when pm is set to 'dynamic' -pm.min_spare_servers = 1 - -; The desired maximum number of idle server processes. -; Note: Used only when pm is set to 'dynamic' -; Note: Mandatory when pm is set to 'dynamic' -pm.max_spare_servers = 3 - -;--------------------- - -; Make specific Docker environment variables available to PHP -env[DB_1_ENV_MYSQL_DATABASE] = $DB_1_ENV_MYSQL_DATABASE -env[DB_1_ENV_MYSQL_USER] = $DB_1_ENV_MYSQL_USER -env[DB_1_ENV_MYSQL_PASSWORD] = $DB_1_ENV_MYSQL_PASSWORD - -catch_workers_output = yes diff --git a/8.2/Dockerfile b/8.2/Dockerfile deleted file mode 100644 index 741339d..0000000 --- a/8.2/Dockerfile +++ /dev/null @@ -1,68 +0,0 @@ -FROM php:8.2-fpm - -ARG PICKLE_EXTENSIONS -ENV PICKLE_VERSION v0.7.11 - -RUN apt-get update \ - && apt-get full-upgrade -y \ - && apt-get install -y --no-install-recommends \ - locales \ - git \ - ssh \ - unzip \ - libfreetype6-dev \ - libjpeg62-turbo-dev \ - libpng-dev \ - libmemcached-dev \ - libzip-dev \ - libicu-dev \ - libpq-dev \ - libssh2-1 libssh2-1-dev \ - libxml2-dev \ - libwebp-dev \ - libmagickwand-dev \ - # oniguruma not bundled in php, use libonig: https://www.php.net/manual/en/migration74.other-changes.php - libonig-dev \ - && rm -rf /var/lib/apt/lists/* \ - && dpkg-reconfigure -f noninteractive locales \ - && echo 'en_US.UTF-8 UTF-8' > /etc/locale.gen \ - && echo 'fr_FR.UTF-8 UTF-8' >> /etc/locale.gen \ - && locale-gen - -# migrating to pkg-config: https://www.php.net/manual/en/migration74.other-changes.php#migration74.other-changes.pkg-config -RUN docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp \ - && docker-php-ext-install -j$(nproc) intl gd opcache mbstring zip pdo_pgsql soap pgsql exif - -# Extra extensions using pickle: https://github.com/docker-library/php/pull/840#issuecomment-502251019 -ADD https://github.com/FriendsOfPHP/pickle/releases/download/${PICKLE_VERSION}/pickle.phar /usr/local/bin/pickle -ENV PICKLE_EXTENSIONS=${PICKLE_EXTENSIONS:-"apcu memcached imagick xdebug"} -RUN chmod +x /usr/local/bin/pickle && \ - ( \ - for extension in $PICKLE_EXTENSIONS; do \ - pickle install -n $extension; \ - docker-php-ext-enable $extension; \ - done \ - ) - -# Install Composer -ENV COMPOSER_ALLOW_SUPERUSER 1 -COPY --from=composer /usr/bin/composer /usr/local/bin/composer - -# Install Blackfire (https://blackfire.io/docs/php/integrations/php-docker) -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/linux/$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:8307\n" > $PHP_INI_DIR/conf.d/blackfire.ini \ - && rm -rf /tmp/blackfire /tmp/blackfire-probe.tar.gz - -RUN usermod -u 1000 www-data -RUN usermod -G staff www-data - -WORKDIR /var/www/symfony - -# Config -COPY symfony.ini $PHP_INI_DIR/conf.d/ -COPY symfony.pool.conf $PHP_INI_DIR/pool.d/ diff --git a/8.2/symfony.ini b/8.2/symfony.ini deleted file mode 100644 index ae6b4dc..0000000 --- a/8.2/symfony.ini +++ /dev/null @@ -1,18 +0,0 @@ -short_open_tag = Off -magic_quotes_gpc = Off -register_globals = Off -session.autostart = Off -date.timezone = Europe/Paris -upload_max_filesize = 32M -post_max_size = 33M -session.save_handler = "memcached" -session.save_path = "memcached:11211" -max_execution_time = 600 -memory_limit = 1024M -memcached.sess_lock_wait_min = 150 -memcached.sess_lock_wait_max = 150 -memcached.sess_lock_retries = 800 -opcache.max_accelerated_files=7963 -opcache.memory_consumption=192 -opcache.interned_strings_buffer=32 -opcache.fast_shutdown=1 diff --git a/8.2/symfony.pool.conf b/8.2/symfony.pool.conf deleted file mode 100644 index 94649b1..0000000 --- a/8.2/symfony.pool.conf +++ /dev/null @@ -1,81 +0,0 @@ -; Start a new pool named 'symfony'. -; the variable $pool can we used in any directive and will be replaced by the -; pool name ('symfony' here) -[symfony] - -; Unix user/group of processes -; Note: The user is mandatory. If the group is not set, the default user's group -; will be used. -user = www-data -group = www-data - -; The address on which to accept FastCGI requests. -; Valid syntaxes are: -; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific address on -; a specific port; -; 'port' - to listen on a TCP socket to all addresses on a -; specific port; -; '/path/to/unix/socket' - to listen on a unix socket. -; Note: This value is mandatory. -listen = 0.0.0.0:9000 - -; Choose how the process manager will control the number of child processes. -; Possible Values: -; static - a fixed number (pm.max_children) of child processes; -; dynamic - the number of child processes are set dynamically based on the -; following directives. With this process management, there will be -; always at least 1 children. -; pm.max_children - the maximum number of children that can -; be alive at the same time. -; pm.start_servers - the number of children created on startup. -; pm.min_spare_servers - the minimum number of children in 'idle' -; state (waiting to process). If the number -; of 'idle' processes is less than this -; number then some children will be created. -; pm.max_spare_servers - the maximum number of children in 'idle' -; state (waiting to process). If the number -; of 'idle' processes is greater than this -; number then some children will be killed. -; ondemand - no children are created at startup. Children will be forked when -; new requests will connect. The following parameter are used: -; pm.max_children - the maximum number of children that -; can be alive at the same time. -; pm.process_idle_timeout - The number of seconds after which -; an idle process will be killed. -; Note: This value is mandatory. -pm = dynamic - -; The number of child processes to be created when pm is set to 'static' and the -; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'. -; This value sets the limit on the number of simultaneous requests that will be -; served. Equivalent to the ApacheMaxClients directive with mpm_prefork. -; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP -; CGI. The below defaults are based on a server without much resources. Don't -; forget to tweak pm.* to fit your needs. -; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand' -; Note: This value is mandatory. -pm.max_children = 20 - -; The number of child processes created on startup. -; Note: Used only when pm is set to 'dynamic' -; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2 -pm.start_servers = 2 - -; The desired minimum number of idle server processes. -; Note: Used only when pm is set to 'dynamic' -; Note: Mandatory when pm is set to 'dynamic' -pm.min_spare_servers = 1 - -; The desired maximum number of idle server processes. -; Note: Used only when pm is set to 'dynamic' -; Note: Mandatory when pm is set to 'dynamic' -pm.max_spare_servers = 3 - -;--------------------- - -; Make specific Docker environment variables available to PHP -env[DB_1_ENV_MYSQL_DATABASE] = $DB_1_ENV_MYSQL_DATABASE -env[DB_1_ENV_MYSQL_USER] = $DB_1_ENV_MYSQL_USER -env[DB_1_ENV_MYSQL_PASSWORD] = $DB_1_ENV_MYSQL_PASSWORD - -catch_workers_output = yes diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..fa6e744 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,71 @@ +FROM php:7.4-fpm as base_php_74 +FROM php:8.0-fpm as base_php_80 +FROM php:8.1-fpm as base_php_81 +FROM php:8.2-fpm as base_php_82 +FROM php:8.3-fpm as base_php_83 + +FROM scratch as config +WORKDIR /usr/local/etc/php/conf.d/ +COPY --link symfony.ini . +WORKDIR /usr/local/etc/php/pool.d/ +COPY --link symfony.pool.conf . + +FROM base_php_74 as php_74 +COPY --from=config / / + +ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/ + +RUN install-php-extensions @composer apcu exif gd imagick intl memcached opcache pdo_pgsql pgsql soap xdebug zip + +RUN usermod -u 1000 www-data +RUN usermod -G staff www-data + +WORKDIR /var/www/symfony + +FROM base_php_80 as php_80 +COPY --from=config / / + +ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/ + +RUN install-php-extensions @composer apcu exif gd imagick intl memcached opcache pdo_pgsql pgsql soap xdebug zip + +RUN usermod -u 1000 www-data +RUN usermod -G staff www-data + +WORKDIR /var/www/symfony + +FROM base_php_81 as php_81 +COPY --from=config / / + +ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/ + +RUN install-php-extensions @composer apcu exif gd imagick intl memcached opcache pdo_pgsql pgsql soap xdebug zip + +RUN usermod -u 1000 www-data +RUN usermod -G staff www-data + +WORKDIR /var/www/symfony + +FROM base_php_82 as php_82 +COPY --from=config / / + +ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/ + +RUN install-php-extensions @composer apcu exif gd imagick intl memcached opcache pdo_pgsql pgsql soap xdebug zip + +RUN usermod -u 1000 www-data +RUN usermod -G staff www-data + +WORKDIR /var/www/symfony + +FROM base_php_83 as php_83 +COPY --from=config / / + +ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/ + +RUN install-php-extensions @composer apcu exif gd imagick intl memcached opcache pdo_pgsql pgsql soap xdebug zip + +RUN usermod -u 1000 www-data +RUN usermod -G staff www-data + +WORKDIR /var/www/symfony diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..26d2bc3 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,38 @@ +services: + php_74: + build: + tags: + - lephare/php:7.4 + target: php_74 + x-bake: &build-x-bake + platforms: + - linux/amd64 + - linux/arm64 + + php_80: + build: + tags: + - lephare/php:8.0 + target: php_80 + x-bake: *build-x-bake + + php_81: + build: + tags: + - lephare/php:8.1 + target: php_81 + x-bake: *build-x-bake + + php_82: + build: + tags: + - lephare/php:8.2 + target: php_82 + x-bake: *build-x-bake + + php_83: + build: + tags: + - lephare/php:8.3 + target: php_83 + x-bake: *build-x-bake diff --git a/8.1/symfony.ini b/symfony.ini similarity index 96% rename from 8.1/symfony.ini rename to symfony.ini index ae6b4dc..4e219ef 100644 --- a/8.1/symfony.ini +++ b/symfony.ini @@ -16,3 +16,4 @@ opcache.max_accelerated_files=7963 opcache.memory_consumption=192 opcache.interned_strings_buffer=32 opcache.fast_shutdown=1 +xdebug.mode=off diff --git a/7.4/symfony.pool.conf b/symfony.pool.conf similarity index 100% rename from 7.4/symfony.pool.conf rename to symfony.pool.conf From 1e321b38129b7da95b4ec279205e8e9d76b184a1 Mon Sep 17 00:00:00 2001 From: Lucas Mirloup <97196064+lucasmirloup@users.noreply.github.com> Date: Tue, 5 Mar 2024 20:27:16 +0100 Subject: [PATCH 2/4] refactor: merge all Dockerfile stages --- .github/workflows/main.yml | 53 ++++++-------------------------- Dockerfile | 63 +++----------------------------------- compose.yaml | 36 +++++++++++++--------- 3 files changed, 36 insertions(+), 116 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 43c1889..2f1e2f9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -5,10 +5,10 @@ name: Build PHP docker images on: push: branches: - - master + - master pull_request: branches: - - master + - master schedule: - cron: '0 12 * * SUN' # every sunday workflow_dispatch: @@ -18,57 +18,24 @@ jobs: name: PHP runs-on: ubuntu-latest continue-on-error: true - strategy: - fail-fast: false - matrix: - platform: - - linux/amd64 - - linux/arm64 steps: - - name: Prepare - run: | - platform=${{ matrix.platform }} - echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV + - name: Checkout + uses: actions/checkout@v4 - - uses: actions/checkout@v4 - - - name: Docker meta - id: docker_meta - uses: docker/metadata-action@v5 - with: - images: lephare/php - tags: | - type=raw,${{ matrix.php_version }} - - - - name: Set up QEMU + - name: Set up QEMU uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx + + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - - name: Login to Docker Hub + + - name: Login to Docker Hub uses: docker/login-action@v3 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - - name: Set up Docker Buildx - id: setup-buildx - uses: docker/setup-buildx-action@v2 - with: - platforms: | - linux/amd64 - linux/arm64 - - name: Build and push - uses: docker/build-push-action@v4 + uses: docker/bake-action@v4 with: - context: "{{defaultContext}}:${{ matrix.php_version }}" push: ${{ github.event_name != 'pull_request' }} - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - platforms: ${{ steps.setup-buildx.outputs.platforms }} - cache-from: type=gha - cache-to: type=gha,mode=max diff --git a/Dockerfile b/Dockerfile index fa6e744..c5fec59 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,69 +1,16 @@ -FROM php:7.4-fpm as base_php_74 -FROM php:8.0-fpm as base_php_80 -FROM php:8.1-fpm as base_php_81 -FROM php:8.2-fpm as base_php_82 -FROM php:8.3-fpm as base_php_83 +ARG PHP_VERSION +ARG PHP_EXTENSIONS + +FROM php:${PHP_VERSION}-fpm -FROM scratch as config WORKDIR /usr/local/etc/php/conf.d/ COPY --link symfony.ini . WORKDIR /usr/local/etc/php/pool.d/ COPY --link symfony.pool.conf . -FROM base_php_74 as php_74 -COPY --from=config / / - -ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/ - -RUN install-php-extensions @composer apcu exif gd imagick intl memcached opcache pdo_pgsql pgsql soap xdebug zip - -RUN usermod -u 1000 www-data -RUN usermod -G staff www-data - -WORKDIR /var/www/symfony - -FROM base_php_80 as php_80 -COPY --from=config / / - -ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/ - -RUN install-php-extensions @composer apcu exif gd imagick intl memcached opcache pdo_pgsql pgsql soap xdebug zip - -RUN usermod -u 1000 www-data -RUN usermod -G staff www-data - -WORKDIR /var/www/symfony - -FROM base_php_81 as php_81 -COPY --from=config / / - -ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/ - -RUN install-php-extensions @composer apcu exif gd imagick intl memcached opcache pdo_pgsql pgsql soap xdebug zip - -RUN usermod -u 1000 www-data -RUN usermod -G staff www-data - -WORKDIR /var/www/symfony - -FROM base_php_82 as php_82 -COPY --from=config / / - -ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/ - -RUN install-php-extensions @composer apcu exif gd imagick intl memcached opcache pdo_pgsql pgsql soap xdebug zip - -RUN usermod -u 1000 www-data -RUN usermod -G staff www-data - -WORKDIR /var/www/symfony - -FROM base_php_83 as php_83 -COPY --from=config / / - ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/ -RUN install-php-extensions @composer apcu exif gd imagick intl memcached opcache pdo_pgsql pgsql soap xdebug zip +RUN install-php-extensions ${PHP_EXTENSIONS} RUN usermod -u 1000 www-data RUN usermod -G staff www-data diff --git a/compose.yaml b/compose.yaml index 26d2bc3..fb9a9bf 100644 --- a/compose.yaml +++ b/compose.yaml @@ -1,38 +1,44 @@ services: php_74: + image: lephare/php:7.4 build: - tags: - - lephare/php:7.4 - target: php_74 + args: &build-args + PHP_VERSION: "7.4" + PHP_EXTENSIONS: "@composer apcu exif gd imagick intl memcached opcache pdo_pgsql pgsql soap xdebug zip" x-bake: &build-x-bake platforms: - linux/amd64 - linux/arm64 php_80: + image: lephare/php:8.0 build: - tags: - - lephare/php:8.0 - target: php_80 + args: + <<: *build-args + PHP_VERSION: "8.0" x-bake: *build-x-bake php_81: + image: lephare/php:8.1 build: - tags: - - lephare/php:8.1 - target: php_81 + args: + <<: *build-args + PHP_VERSION: "8.1" x-bake: *build-x-bake php_82: + image: lephare/php:8.2 build: - tags: - - lephare/php:8.2 - target: php_82 + args: + <<: *build-args + PHP_VERSION: "8.2" x-bake: *build-x-bake php_83: + image: lephare/php:8.3 build: - tags: - - lephare/php:8.3 - target: php_83 + args: + <<: *build-args + PHP_VERSION: "8.3" + PHP_EXTENSIONS: "@composer apcu exif gd intl memcached opcache pdo_pgsql pgsql soap xdebug zip" # Disable Imagick for PHP 8.3 until https://github.com/Imagick/imagick/issues/640 is fixed x-bake: *build-x-bake From aeff47392d14077fe5e20ab1c2a49917d298d198 Mon Sep 17 00:00:00 2001 From: Lucas Mirloup <97196064+lucasmirloup@users.noreply.github.com> Date: Wed, 6 Mar 2024 14:20:19 +0100 Subject: [PATCH 3/4] refactor: Dockerfile stages, hadolint + CI --- .github/workflows/main.yml | 8 ++++++++ .spells | 5 +++++ Dockerfile | 18 +++++++++--------- hadolint.yaml | 1 + 4 files changed, 23 insertions(+), 9 deletions(-) create mode 100644 .spells create mode 100644 hadolint.yaml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2f1e2f9..9c3afa1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -14,6 +14,14 @@ on: workflow_dispatch: jobs: + lint: + name: Lint Dockerfile + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - uses: hadolint/hadolint-action@v3.1.0 + build: name: PHP runs-on: ubuntu-latest diff --git a/.spells b/.spells new file mode 100644 index 0000000..f0f5e4f --- /dev/null +++ b/.spells @@ -0,0 +1,5 @@ +function hadolint() { + docker run --rm -i -v ./hadolint.yaml:/.config/hadolint.yaml hadolint/hadolint < Dockerfile +} + +echo hadolint diff --git a/Dockerfile b/Dockerfile index c5fec59..8b3887a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,18 @@ ARG PHP_VERSION ARG PHP_EXTENSIONS -FROM php:${PHP_VERSION}-fpm +FROM mlocati/php-extension-installer:2 as extension-installer +FROM php:${PHP_VERSION}-fpm as base +FROM base -WORKDIR /usr/local/etc/php/conf.d/ -COPY --link symfony.ini . -WORKDIR /usr/local/etc/php/pool.d/ -COPY --link symfony.pool.conf . +WORKDIR /usr/local/etc/php +COPY --link symfony.ini ./conf.d/ +COPY --link symfony.pool.conf ./pool.d/ -ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/ +COPY --from=extension-installer /usr/bin/install-php-extensions /usr/local/bin -RUN install-php-extensions ${PHP_EXTENSIONS} +RUN install-php-extensions "${PHP_EXTENSIONS}" -RUN usermod -u 1000 www-data -RUN usermod -G staff www-data +RUN usermod -u 1000 www-data && usermod -G staff www-data WORKDIR /var/www/symfony diff --git a/hadolint.yaml b/hadolint.yaml new file mode 100644 index 0000000..e277c53 --- /dev/null +++ b/hadolint.yaml @@ -0,0 +1 @@ +failure-threshold: style From 4835cdfd7dadd06376df1698296fb6eeba1a902b Mon Sep 17 00:00:00 2001 From: Lucas Mirloup <97196064+lucasmirloup@users.noreply.github.com> Date: Fri, 8 Mar 2024 11:22:21 +0100 Subject: [PATCH 4/4] fix(Dockerfile): move `ARG PHP_EXTENSIONS` into the right stage --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8b3887a..7843898 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,9 @@ ARG PHP_VERSION -ARG PHP_EXTENSIONS FROM mlocati/php-extension-installer:2 as extension-installer FROM php:${PHP_VERSION}-fpm as base FROM base +ARG PHP_EXTENSIONS WORKDIR /usr/local/etc/php COPY --link symfony.ini ./conf.d/ @@ -11,7 +11,7 @@ COPY --link symfony.pool.conf ./pool.d/ COPY --from=extension-installer /usr/bin/install-php-extensions /usr/local/bin -RUN install-php-extensions "${PHP_EXTENSIONS}" +RUN install-php-extensions ${PHP_EXTENSIONS} RUN usermod -u 1000 www-data && usermod -G staff www-data