Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/docker.build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
needs: prepare
strategy:
matrix:
php: [ 8.2.36, 8.3.37, 8.4.28, 8.5.13 ]
php: [ 8.2.36, 8.3.37, 8.4.28, 8.5.13, 8.6.0 ]
platform: [ linux/amd64, linux/arm64 ]
include:
- platform: linux/amd64
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker.test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [ 8.2.36, 8.3.37, 8.4.28, 8.5.13 ]
php: [ 8.2.36, 8.3.37, 8.4.28, 8.5.13, 8.6.0 ]
runs-on: ubuntu-latest
timeout-minutes: 90
env:
Expand Down
16 changes: 2 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,8 @@ RUN export FLOWNATIVE_LOG_PATH_AND_FILENAME=/dev/stdout \
&& /build.sh init \
&& /build.sh prepare \
&& /build.sh build \
&& /build.sh build_extension vips \
&& /build.sh build_extension igbinary \
&& /build.sh disable_extension igbinary \
&& /build.sh build_extension imagick \
&& /build.sh build_extension yaml \
&& /build.sh build_extension phpredis \
&& /build.sh build_extension xdebug \
&& /build.sh disable_extension xdebug \
&& /build.sh build_extension php-spx \
&& /build.sh disable_extension php-spx \
&& /build.sh build_extension php-excimer \
&& /build.sh disable_extension php-excimer \
&& /build.sh build_extension ssh2 \
&& /build.sh build_extension mongodb \
&& /build.sh build_extensions \
&& /build.sh disable_extensions \
&& /build.sh clean

USER 1000
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@ similar mechanism in Kubernetes or your actual platform.

† – `*` (match all) and subnet masks (e.g. `192.168.1.0/24`) are supported.

### Extensions in PHP 8.6 and later

Images for PHP 8.6 and later no longer contain these extensions:

- **igbinary** is dropped. It appears to be unmaintained, and the
advantage it promised over PHP's own serializer no longer holds.
`PHP_IGBINARY_ENABLE` is ignored, with a warning.
- **vips** is dropped. Current versions of php-vips require FFI, which
this image does not allow. Use Imagick instead.

Images for PHP 8.2 to 8.5 still contain both extensions.

## Security aspects

This image is designed to run as a non-root container. Using an
Expand Down Expand Up @@ -149,6 +161,8 @@ HEIC images, can read SVG, TIFF and the first page of a PDF, keep
transparency when writing PNG, GIF, WebP, AVIF and HEIC, and keep the frames of
an animated GIF when writing GIF and WebP. A library without any API for
a format, such as GD built without AVIF support, is reported as skipped.
So is vips on PHP 8.6 and later, which no longer includes it, and a
format which every library skipped, such as PDF without Ghostscript.
Any other failure, or a format which no library can read or write, fails
the run. The results appear in the job summary and the generated images
are uploaded as a build artifact.
Expand Down
41 changes: 33 additions & 8 deletions root-files/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ build_compile_php() {

php_source_url="https://www.php.net/distributions/php-${PHP_VERSION}.tar.gz"


info "🛠 Downloading source code for PHP ${PHP_VERSION} from ${php_source_url} ..."
with_backoff "curl -sfSL ${php_source_url} -o php.tar.gz" "15" || (
error "Failed downloading PHP source from ${php_source_url}"
Expand Down Expand Up @@ -148,7 +149,7 @@ build_compile_php() {
# For GCC warning options see: https://gcc.gnu.org/onlinedocs/gcc-3.4.4/gcc/Warning-Options.html
export CFLAGS='-Wno-deprecated-declarations -Wno-stringop-overflow -Wno-implicit-function-declaration'

if [[ "${PHP_VERSION}" =~ ^8.[1-5] ]]; then
if [[ "${PHP_VERSION}" =~ ^8.[1-6] ]]; then
./configure \
--prefix=${PHP_BASE_PATH} \
--with-config-file-path="${PHP_BASE_PATH}/etc" \
Expand Down Expand Up @@ -225,8 +226,6 @@ build_php_extension() {
local -r extension_build_packages=$(eval "extensions_${extension_name}_build_packages")
local -r extension_runtime_packages=$(eval "extensions_${extension_name}_runtime_packages")

eval "extensions_${extension_name}_prepare"

# -----------------------------------------------------------------------------------
# Install packages
if [[ "${extension_runtime_packages}" != "" ]]; then
Expand All @@ -243,6 +242,10 @@ build_php_extension() {
info "🔌 ${extension_name}: No additional build packages to install"
fi

# -----------------------------------------------------------------------------------
# Prepare the system, after packages are installed, so that their files can be adjusted
eval "extensions_${extension_name}_prepare"

if [[ "${extension_url}" != "" ]]; then
# ---------------------------------------------------------------------------------
# Download and extract source code
Expand Down Expand Up @@ -285,6 +288,12 @@ build_php_extension() {
# For GCC warning options see: https://gcc.gnu.org/onlinedocs/gcc-3.4.4/gcc/Warning-Options.html
export CFLAGS='-Wno-deprecated-declarations -Wno-stringop-overflow -Wno-implicit-function-declaration'

# PHP 8.6 removed the XtOffsetOf() macro, which several extensions still use. Until
# they have releases supporting PHP 8.6, map it to the standard offsetof().
if [[ "${PHP_VERSION}" =~ ^8.6 ]]; then
export CFLAGS="${CFLAGS} -DXtOffsetOf=offsetof"
fi

./configure ${extension_configure_arguments} 1>$(debug_device) || (
error "Configure failed for extension ${extension_name}"
exit 1
Expand Down Expand Up @@ -404,7 +413,7 @@ case $1 in
init)
banner_flownative 'PHP'

if [[ ! "${PHP_VERSION}" =~ ^8.[1-5] ]]; then
if [[ ! "${PHP_VERSION}" =~ ^8.[1-6] ]]; then
error "🛠 Unsupported PHP version '${PHP_VERSION}'"
exit 1
fi
Expand All @@ -425,11 +434,27 @@ prepare)
build)
build_compile_php
;;
build_extension)
build_php_extension $2
build_extensions)
if [[ "${PHP_VERSION}" =~ ^8.[2-5] ]]; then
build_php_extension vips
build_php_extension igbinary
fi
build_php_extension imagick
build_php_extension yaml
build_php_extension phpredis
build_php_extension xdebug
build_php_extension php-excimer
build_php_extension php-spx
build_php_extension ssh2
build_php_extension mongodb
;;
disable_extension)
build_disable_php_extension $2
disable_extensions)
if [[ "${PHP_VERSION}" =~ ^8.[2-5] ]]; then
build_disable_php_extension igbinary
fi
build_disable_php_extension xdebug
build_disable_php_extension php-excimer
build_disable_php_extension php-spx
;;
clean)
build_adjust_permissions
Expand Down
2 changes: 2 additions & 0 deletions root-files/opt/flownative/lib/php-fpm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ php_fpm_initialize() {
if [ -f "${PHP_CONF_PATH}/conf.d/php-ext-igbinary.ini.inactive" ]; then
info "PHP-FPM: igbinary is enabled"
mv -f "${PHP_CONF_PATH}/conf.d/php-ext-igbinary.ini.inactive" "${PHP_CONF_PATH}/conf.d/php-ext-igbinary.ini"
elif [ ! -f "${PHP_CONF_PATH}/conf.d/php-ext-igbinary.ini" ]; then
warn "PHP-FPM: igbinary is not available in this image (dropped as of PHP 8.6), ignoring PHP_IGBINARY_ENABLE"
fi
else
info "PHP-FPM: igbinary is disabled"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
# @return List of packages
#
extensions_imagick_prepare() {
# see: https://imagemagick.org/script/security-policy.php
# Replace the policy shipped with libmagickcore by our own. This runs after the
# extension's packages are installed, which create /etc/ImageMagick-7.
# see: https://imagemagick.org/security-policy/
if [[ ! -d /etc/ImageMagick-7 ]]; then
error "🔌 imagick: /etc/ImageMagick-7 not found, cannot install ImageMagick policy"
exit 1
fi
rm -f /etc/ImageMagick-7/policy.xml
ln -s ${PHP_BASE_PATH}/build/extensions/imagick/policy.xml /etc/ImageMagick-7/policy.xml
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ extensions_php-spx_runtime_packages() {
# @return string
#
extensions_php-spx_url() {
echo "https://github.com/NoiseByNorthwest/php-spx/archive/refs/tags/v0.4.22.tar.gz"
echo "https://github.com/NoiseByNorthwest/php-spx/archive/refs/heads/v0.5.tar.gz"
}

# ---------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ extensions_phpredis_runtime_packages() {
# @return string
#
extensions_phpredis_url() {
echo "https://github.com/phpredis/phpredis/archive/6.3.0.tar.gz"
echo "https://github.com/phpredis/phpredis/archive/refs/tags/6.4.0RC1.tar.gz"
}

# ---------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ extensions_xdebug_runtime_packages() {
# @return string
#
extensions_xdebug_url() {
echo "https://xdebug.org/files/xdebug-3.5.3.tgz"
echo "https://xdebug.org/files/xdebug-3.6.0alpha1.tgz"
}

# ---------------------------------------------------------------------------------------
Expand Down
67 changes: 62 additions & 5 deletions tests/image-formats.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ public function version(): string;

public function isAvailable(): bool;

/**
* Whether the image is supposed to contain this library. A missing library
* which is not expected is reported as skipped instead of failed.
*/
public function isExpected(): bool;

public function createPattern(int $width, int $height): mixed;

/**
Expand Down Expand Up @@ -145,6 +151,11 @@ public function isAvailable(): bool
return extension_loaded('gd');
}

public function isExpected(): bool
{
return true;
}

public function createPattern(int $width, int $height): mixed
{
$image = imagecreatetruecolor($width, $height);
Expand Down Expand Up @@ -314,6 +325,11 @@ public function isAvailable(): bool
return extension_loaded('imagick');
}

public function isExpected(): bool
{
return true;
}

public function createPattern(int $width, int $height): mixed
{
$image = new Imagick();
Expand Down Expand Up @@ -511,6 +527,14 @@ public function isAvailable(): bool
return extension_loaded('vips');
}

/**
* The vips extension is not included as of PHP 8.6, see README.
*/
public function isExpected(): bool
{
return PHP_VERSION_ID < 80600;
}

public function createPattern(int $width, int $height): mixed
{
$tiles = [];
Expand Down Expand Up @@ -748,11 +772,11 @@ public function status(string $library, string $category, string $format): ?Stat
/**
* @return string[] libraries whose check of the given kind passed
*/
public function librariesWith(string $category, string $format): array
public function librariesWith(string $category, string $format, Status $status = Status::Ok): array
{
$libraries = [];
foreach ($this->checks as $check) {
if ($check->category === $category && $check->format === $format && $check->status === Status::Ok && $check->source === '') {
if ($check->category === $category && $check->format === $format && $check->status === $status && $check->source === '') {
$libraries[] = $check->library;
}
}
Expand Down Expand Up @@ -1155,7 +1179,11 @@ function main(): int
foreach ($libraries as $library) {
$name = $library->name();
if (!$library->isAvailable()) {
$report->add($name, 'extension', '-', Status::Fail, 'extension is not loaded');
if ($library->isExpected()) {
$report->add($name, 'extension', '-', Status::Fail, 'extension is not loaded');
} else {
$report->add($name, 'extension', '-', Status::Skip, sprintf('extension is not included for PHP %s', PHP_VERSION));
}
continue;
}
$versions[] = $library->version();
Expand Down Expand Up @@ -1194,11 +1222,11 @@ function main(): int
$readers = $report->librariesWith('read', $format);
$writers = $report->librariesWith('write', $format);
$detail = sprintf('read: %s; write: %s', $readers === [] ? 'none' : implode(', ', $readers), $writers === [] ? 'none' : implode(', ', $writers));
$report->add('any', 'coverage', $format, $readers !== [] && $writers !== [] ? Status::Ok : Status::Fail, $detail);
$report->add('any', 'coverage', $format, coverageStatus($report, $readers, 'read', $format, $writers, 'write'), $detail);
}
foreach (READ_ONLY_FORMATS as $format) {
$readers = $report->librariesWith('read', $format);
$report->add('any', 'coverage', $format, $readers !== [] ? Status::Ok : Status::Fail, 'read: ' . ($readers === [] ? 'none' : implode(', ', $readers)));
$report->add('any', 'coverage', $format, coverageStatus($report, $readers, 'read', $format), 'read: ' . ($readers === [] ? 'none' : implode(', ', $readers)));
}

printf("\n%d ok, %d failed, %d skipped\n", $report->count(Status::Ok), $report->count(Status::Fail), $report->count(Status::Skip));
Expand All @@ -1216,4 +1244,33 @@ function main(): int
return $report->hasFailures() ? 1 : 0;
}

/**
* Coverage passes if some library can do each of the given operations. If no
* library can, it fails only if a library actually failed the check. If all of
* them skipped it, for example because Ghostscript is not installed, the
* coverage is reported as skipped as well.
*
* @param string[] $readers
* @param string[]|null $writers
*/
function coverageStatus(Report $report, array $readers, string $readCategory, string $format, ?array $writers = null, string $writeCategory = ''): Status
{
$missing = [];
if ($readers === []) {
$missing[] = $readCategory;
}
if ($writers === []) {
$missing[] = $writeCategory;
}
if ($missing === []) {
return Status::Ok;
}
foreach ($missing as $category) {
if ($report->librariesWith($category, $format, Status::Fail) !== []) {
return Status::Fail;
}
}
return Status::Skip;
}

exit(main());