Skip to content

Add --extensions-dir flag to load PHP extension config from filesystem - #126

Merged
tnikolova82 merged 3 commits into
mainfrom
add-extensions-dir-flag
Oct 28, 2026
Merged

tnikolova82 merged 3 commits into
mainfrom
add-extensions-dir-flag

Conversation

@tnikolova82

Copy link
Copy Markdown
Contributor

Summary

Adds support for loading PHP extension YAML files from an external directory instead of from the compiled-in embedded assets. This is Phase 1 of the PHP extension config migration — moving extension version ownership from binary-builder to the php-buildpack.

Motivation

binary-builder is a generic compilation tool and should not own buildpack-specific configuration. Today, bumping a PECL extension version requires a binary-builder commit and recompilation. This change decouples the two by allowing the extension config to be passed in at build time.

Changes

File Change
internal/php/extensions.go Add LoadFromDir(dir, major, minor) that reads YAML from filesystem; extract shared loadFromData()
cmd/binary-builder/main.go Add --extensions-dir flag; thread it to PHPRecipe via buildRegistry()
internal/recipe/php.go Add ExtensionsDir field to PHPRecipe; dispatch to LoadFromDir or Load
internal/php/extensions_test.go 5 new tests for LoadFromDir

Backward compatibility

Fully backward compatible. When --extensions-dir is not set (the default), the embedded assets are used exactly as before. No existing CI pipeline, CLI invocation, or test is affected.

Usage

# Before (uses embedded extension config — still works)
binary-builder build --stack cflinuxfs4 --source-file source/data.json

# After (uses external extension config from php-buildpack)
binary-builder build --stack cflinuxfs4 --source-file source/data.json \
  --extensions-dir php-buildpack/config/extensions

Tests

5 new unit tests:

  • TestLoadFromDir_BaseOnly — loads base file without a patch
  • TestLoadFromDir_WithPatch — applies exclusions and additions from a patch file
  • TestLoadFromDir_MissingBaseFile — returns clear error when base file is missing
  • TestLoadFromDir_MissingPatchIsOK — missing patch file is not an error
  • TestLoadFromDir_MatchesEmbeddedLoad — verifies LoadFromDir on assets/ produces identical results to the embedded Load()

Next steps

This is Phase 1 of the migration plan (see buildpacks-ci/docs/php-extensions-migration-plan.md):

  • Phase 2: Copy extension YAML files to php-buildpack/config/extensions/
  • Phase 3: Update CI pipeline to pass --extensions-dir during PHP builds
  • Phase 4: Add PECL extension version monitoring automation
  • Phase 5: Remove embedded config from binary-builder (cleanup)

Add support for loading PHP extension YAML files from an external
directory instead of from the compiled-in embedded assets. This is the
first step toward moving extension version ownership from binary-builder
to the php-buildpack repository.

Changes:

- Add LoadFromDir(dir, phpMajor, phpMinor) to internal/php/extensions.go.
  Reads base + patch YAML files from a filesystem directory using the
  same naming convention as the embedded assets. Extract shared parsing
  logic into loadFromData() used by both Load() and LoadFromDir().

- Add --extensions-dir CLI flag to cmd/binary-builder/main.go. When set,
  the PHP recipe loads extensions from this directory. When empty
  (default), the embedded assets are used — fully backward compatible.

- Thread ExtensionsDir through PHPRecipe so the Build() method can
  dispatch to LoadFromDir() or Load() as appropriate.

- Add 5 unit tests for LoadFromDir():
  - Base-only (no patch file)
  - Base + patch with exclusions and additions
  - Missing base file returns error
  - Missing patch file is not an error
  - LoadFromDir on the real assets/ directory matches embedded Load()

This is Phase 1 of the PHP extension config migration plan
(docs/php-extensions-migration-plan.md in buildpacks-ci). No existing
behavior is changed — the --extensions-dir flag is entirely optional.
…date --extensions-dir early

Review finding fixes for PR #126:

1. LoadFromDir: distinguish os.IsNotExist from other ReadFile errors on
   patch files. Previously all errors were silently swallowed; now only
   missing files are tolerated. Other errors (permissions, I/O) are
   returned. New test: TestLoadFromDir_PatchFileReadError.

2. PHPRecipe: add ExtensionsDir dispatch tests that verify the recipe
   loads extensions from a custom directory (not embedded defaults) when
   ExtensionsDir is set, and returns a clear error when the directory
   has no base file.

3. loadFromData: replace 'patchData == nil' with 'len(patchData) == 0'
   to make the nil/empty contract explicit and robust against future
   callers passing an empty []byte{} instead of nil.

4. main.go: add os.Stat + IsDir check for --extensions-dir immediately
   after flag parsing, before any expensive build steps. Fails fast with
   a clear error on misconfigured invocations.

5. Add weekly GitHub Actions workflow (check-php-extensions.yml) that
   runs bump-versions.rb in dry-run mode and creates/updates a GitHub
   issue when PECL extensions are outdated.

6. Update AGENTS.md key files table and extensions.go package doc to
   document LoadFromDir and the --extensions-dir flag.
…ML source

Update the weekly check-php-extensions workflow to:

1. Check out php-buildpack alongside binary-builder and buildpacks-ci.
2. Auto-detect the extension YAML directory with fallback chain:
   php-buildpack/config/extensions > internal/php/assets > internal/php/testdata
3. Set EXTENSIONS_DIR (instead of BINARY_BUILDER_DIR) so the scripts
   work correctly across all migration phases, including after Phase 5
   when assets/ is renamed to testdata/.
4. Update the issue body Next Steps to be repo-agnostic.

@ivanovac ivanovac left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm

@tnikolova82
tnikolova82 merged commit 5ce7690 into main Oct 28, 2026
1 check passed
@tnikolova82
tnikolova82 deleted the add-extensions-dir-flag branch October 28, 2026 12:12
tnikolova82 added a commit that referenced this pull request Oct 28, 2026
…se 5)

Remove the go:embed-based extension loading from binary-builder. Extension
YAML files now live exclusively in the php-buildpack repo (config/extensions/)
and must be passed via --extensions-dir during PHP builds.

Changes:

1. Move internal/php/assets/ to internal/php/testdata/. The YAML files
   are now test fixtures only, not compiled into the binary.

2. Remove go:embed infrastructure from extensions.go: the embedded FS,
   init() function, regex matchers, and embeddedBases/embeddedPatches
   maps are all removed. LoadFromDir is the sole production API.

3. Load() now delegates to LoadFromDir("testdata", ...) and is
   documented as a test-only convenience function.

4. PHPRecipe.ExtensionsDir is now required. Build() returns a clear
   error when it is empty: "--extensions-dir is required for PHP builds".

5. All php_test.go tests updated to pass ExtensionsDir. New test
   TestPHPRecipeBuildRequiresExtensionsDir verifies the error path.

6. AGENTS.md updated to reflect the new structure.

DO NOT MERGE until Phase 3 (buildpacks-ci pipeline passing --extensions-dir)
has been running successfully in production for at least one full PHP release
cycle.

Prerequisites:
- binary-builder PR #126 (Phase 1) — merged
- php-buildpack PR #1332 (Phase 2) — merged
- buildpacks-ci Phase 3 PR — merged and validated
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