Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: introduce php-helpers image #1105

Merged
merged 5 commits into from
Mar 4, 2025
Merged

feat: introduce php-helpers image #1105

merged 5 commits into from
Mar 4, 2025

Conversation

sjinks
Copy link
Member

@sjinks sjinks commented Mar 4, 2025

This PR adds a ghcr.io/automattic/vip-container-images/php-helpers image to reduce the build time for PHP images.

When building a PHP image, we spend a lot of time building mydumper and PHP extensions (and installing build dependencies). This is especially slow for the linux/arm64 variant because it runs under QEMU.

To the contrary, the php-helpers image employs cross-compilation instead of emulation. As a result, it takes less than three minutes to build all artifacts for both architectures.

To test:

cd php-helpers
docker buildx bake
ls -1R IMAGE

The expected output is

IMAGE:
linux_amd64
linux_arm64

IMAGE/linux_amd64:
mydumper
mydumper.cnf
myloader
usr

IMAGE/linux_amd64/usr:
lib

IMAGE/linux_amd64/usr/lib:
php

IMAGE/linux_amd64/usr/lib/php:
20210902
20220829
20230831
20240924

IMAGE/linux_amd64/usr/lib/php/20210902:
timezonedb.so

IMAGE/linux_amd64/usr/lib/php/20220829:
timezonedb.so

IMAGE/linux_amd64/usr/lib/php/20230831:
timezonedb.so

IMAGE/linux_amd64/usr/lib/php/20240924:
timezonedb.so

IMAGE/linux_arm64:
mydumper
mydumper.cnf
myloader
usr

IMAGE/linux_arm64/usr:
lib

IMAGE/linux_arm64/usr/lib:
php

IMAGE/linux_arm64/usr/lib/php:
20210902
20220829
20230831
20240924

IMAGE/linux_arm64/usr/lib/php/20210902:
timezonedb.so

IMAGE/linux_arm64/usr/lib/php/20220829:
timezonedb.so

IMAGE/linux_arm64/usr/lib/php/20230831:
timezonedb.so

IMAGE/linux_arm64/usr/lib/php/20240924:
timezonedb.so

@sjinks sjinks self-assigned this Mar 4, 2025
Comment on lines 40 to 45
echo 'DPkg::Pre-Invoke { "rm -f /var/lib/dpkg/info/*.postinst || true"; };' > /etc/apt/apt.conf.d/99local && \
xx-apt-get install --no-install-recommends -y -oDPkg::ConfigurePending=0 libglib2.0-dev || true && \
xx-apt-get install --no-install-recommends -y -oDPkg::ConfigurePending=0 libglib2.0-dev || true && \
xx-apt-get install --no-install-recommends -y -oDPkg::ConfigurePending=0 libglib2.0-dev && \
xx-apt-get install --no-install-recommends -y -oDPkg::ConfigurePending=0 \
zlib1g-dev libpcre3-dev libssl-dev libzstd-dev libmysqlclient-dev
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a nightmare.

libglib2.0-dev wants python, python wants to run a bunch of CPU-heavy scripts, which cannot run on a foreign architecture.

The solution was to ignore errors, remove all installed postinst scripts, and try until we succeed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 30 to 32
xx-apt-get update && \
apt-get install -y shtool php-pear && \
sed -i '/^Package: shtool$/a Multi-Arch: foreign' /var/lib/dpkg/status && \
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xx-apt-get update && \
apt-get install -y shtool php-pear && \
sed -i '/^Package: shtool$/a Multi-Arch: foreign' /var/lib/dpkg/status && \
pecl bundle timezonedb
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We must download and unpack everything we need from PECL because xx-apt-get install phpXX-dev might overwrite pecl with the binary with a foreign architecture, which we cannot run.

That is why we run pecl here and then forget it existed.

@sjinks sjinks force-pushed the add/php-helpers branch from 5fe260c to 04cce7b Compare March 4, 2025 19:51
@sjinks sjinks marked this pull request as ready for review March 4, 2025 20:12
@sjinks sjinks requested a review from a team as a code owner March 4, 2025 20:12
@sjinks sjinks merged commit 1c3fa61 into master Mar 4, 2025
3 checks passed
@sjinks sjinks deleted the add/php-helpers branch March 4, 2025 20:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant