Skip to content

Strip build-only tooling from the finished image#180

Open
eiriksm wants to merge 6 commits into
mainfrom
claude/build-tools-cleanup-xmpagv
Open

Strip build-only tooling from the finished image#180
eiriksm wants to merge 6 commits into
mainfrom
claude/build-tools-cleanup-xmpagv

Conversation

@eiriksm

@eiriksm eiriksm commented Jul 7, 2026

Copy link
Copy Markdown
Member

No description provided.

claude and others added 3 commits July 7, 2026 19:21
Split apk installs into a runtime set (CLI tools + libs kept explicit)
and a virtual .build-deps group holding compilers, headers and -dev
packages needed only to compile the PHP extensions. After all
extensions are built, scan the compiled .so files with scanelf to
detect the shared libraries they actually link against, install those
explicitly, then delete .build-deps. Also run docker-php-source delete
to drop the extracted PHP source tree, and dedupe a couple of packages
that were listed twice. This follows the same pattern the official PHP
Docker images use to keep gcc/make/*-dev packages and the PHP source
tree out of the final image.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013HSR8gEQwdQK7LfdNsDRfk
apk add --virtual NAME replaces an existing virtual package's
dependency list rather than merging into it. Reusing .build-deps for
the mid-script oniguruma-dev/krb5-dev installs redefined it down to
just that one package, immediately purging everything from the
original .build-deps set (including zlib-dev, pulled in transitively)
before gd's configure step needed it - which is why the PHP 8.6 build
failed with "Package 'zlib' not found". Install those two as plain
packages instead, same as before this cleanup.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013HSR8gEQwdQK7LfdNsDRfk
@eiriksm eiriksm enabled auto-merge (squash) July 8, 2026 07:08
@eiriksm eiriksm disabled auto-merge July 8, 2026 10:06
claude added 2 commits July 8, 2026 13:17
scanelf only sees libraries linked into a compiled .so's ELF NEEDED
list, not ones loaded by path/config at runtime. LDAP's SASL bind
mechanisms (libsasl2) and unixODBC's driver manager (used by
sqlsrv/pdo_sqlsrv) are loaded that way, so they weren't guaranteed to
survive the .build-deps removal. file is a generally useful CLI tool
that happened to only be present as a side effect of $PHPIZE_DEPS.
Keep all three explicit alongside the other runtime packages.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013HSR8gEQwdQK7LfdNsDRfk
oniguruma-dev (gd, PHP 7.4/8.x) and krb5-dev (imap, PHP 8.4/8.5) were
plain apk add calls, made that way to work around .build-deps getting
redefined instead of merged when reused mid-script. They lingered in
every final image instead of being cleaned up like the rest.

Give each its own uniquely-named virtual group and delete all of them
in the same final scanelf-based cleanup step - the scanelf scan runs
after gd/imap are fully built regardless of which named group provided
their build-time headers, so it still correctly re-pins whatever those
extensions actually link against. Since .build-deps-gd/-imap are only
created on some PHP versions (7.3 skips gd's, most versions skip
imap's), check apk info -e before deleting them - `set -eu` would abort
the whole build on `apk del` failing for a nonexistent virtual package.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013HSR8gEQwdQK7LfdNsDRfk
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.

2 participants