Skip to content

Conversation

@ramonskie
Copy link
Contributor

Summary

This PR removes the runtime rewrite binary and replaces it with build-time placeholder replacement, fixing critical issues with multi-buildpack deployments and git URL buildpack usage. It also adds comprehensive documentation, vendor symlink support, and improves test infrastructure.

Changes

1. Remove Runtime Rewrite Binary (Commit 1)

Problem: The rewrite binary (copied from v4.x Python buildpack) caused multiple issues:

  • Failed when buildpack was deployed via git URL
  • Compilation errors in multi-buildpack scenarios
  • Security concerns with runtime config rewriting
  • Performance overhead at container startup

Solution: Replace with build-time placeholder replacement in finalize phase.

Build-Time Placeholders: @{HOME}, @{DEPS_DIR}, @{WEBDIR}, @{LIBDIR}, @{PHP_FPM_LISTEN}, @{TMPDIR}, @{PHP_EXTENSIONS}, @{ZEND_EXTENSIONS}

Files Removed:

  • bin/rewrite
  • src/php/rewrite/cli/main.go

Bug Fix - php.ini.d Context: Fixed critical bug where php.ini.d was processed with deps context instead of app context. The php.ini.d configs typically reference application paths (include_path, open_basedir, etc.) and should use @{HOME} = /home/vcap/app, not /home/vcap/deps/{idx}.

2. Add Vendor Symlink Feature (Commit 2)

Creates htdocs/vendor -> ../lib/vendor symlink for apps that reference vendor/autoload.php from web root, maintaining backward compatibility while keeping vendor outside web directory for security.

Also fixes placeholder syntax: #{LIBDIR} -> @{LIBDIR}

3. Improve Test Infrastructure (Commit 3)

  • Fix integration test regex patterns
  • Skip custom extensions test (not yet supported in v5.x)
  • Add buildpack cleanup to prevent disk space issues in CI

4. Add Comprehensive Documentation (Commit 4)

80K of documentation across 6 files:

  • USER_GUIDE.md (15K) - Complete end-user guide
  • FEATURES.md (11K) - Developer reference with test coverage verification
  • BUILDPACK_COMPARISON.md (12K) - Cross-buildpack analysis (Go, Java, Ruby, Python)
  • VCAP_SERVICES_USAGE.md (12K) - Service binding patterns
  • REWRITE_MIGRATION.md (27K) - v4.x to v5.x migration guide
  • README.md (7K) - Navigation hub

Key Insights

  1. VCAP_SERVICES IS available during staging - Extensions and Go code can read it; only @{VCAP_SERVICES} config placeholders are not supported
  2. PHP v5.x aligns with CF standards - Follows same patterns as Go, Java, Ruby, Python buildpacks
  3. v4.x runtime rewrite was PHP-unique - Removed for ecosystem alignment
  4. 95%+ test coverage - 30+ features with explicit test verification

Testing

All integration tests pass. The changes are backward compatible except for:

  • Custom @{PLACEHOLDER} variables no longer supported (use environment variables instead)
  • Requires restage (not just restart) when service bindings change

Breaking Changes

None for standard usage. Only affects apps using custom @{PLACEHOLDER} variables (not documented in v4.x).

Migration Guide

See docs/REWRITE_MIGRATION.md for detailed migration instructions.


Closes issues related to:

  • Multi-buildpack failures
  • Git URL buildpack compilation errors
  • Runtime config rewriting security concerns
  • php.ini.d context bugs

Related: This supersedes the original fix-rewrite-binary-compilation branch which evolved beyond its original scope.

This commit removes the runtime rewrite binary and replaces it with build-time
placeholder replacement, fixing multiple issues with multi-buildpack deployments
and git URL buildpack usage. It also fixes a critical bug where php.ini.d
configs were processed with the wrong HOME context.

## Rewrite Binary Removal

The rewrite binary was originally copied from the v4.x Python buildpack and used
to replace template variables in configuration files at runtime. This approach
had several issues:
- Failed when buildpack was deployed via git URL
- Compilation errors in multi-buildpack scenarios
- Security concerns with runtime config rewriting
- Performance overhead at container startup

This commit completes the migration to build-time placeholder replacement that
provides better security, performance, and multi-buildpack compatibility.

### Changes:
- Remove bin/rewrite shell wrapper script
- Remove src/php/rewrite/cli/main.go (entire rewrite implementation)
- Remove rewrite binary compilation from bin/finalize
- Remove bin/rewrite from manifest.yml include_files
- Remove /bin/rewrite-compiled from .gitignore
- Update ARCHITECTURE.md to remove rewrite binary documentation

## Build-Time Placeholder Replacement

Add ProcessConfigs() method to finalize phase that replaces @{VAR} placeholders
with actual values during staging:

- @{HOME} - App or dependency directory path
- @{DEPS_DIR} - Dependencies directory (/home/vcap/deps)
- @{WEBDIR} - Web document root (default: htdocs)
- @{LIBDIR} - Library directory (default: lib)
- @{PHP_FPM_LISTEN} - PHP-FPM socket/TCP address
- @{TMPDIR} - Converted to ${TMPDIR} for runtime expansion
- @{PHP_EXTENSIONS} - Extension directives
- @{ZEND_EXTENSIONS} - Zend extension directives

## Placeholder Syntax Unification

Unify all template variables to use @{VAR} syntax consistently across all
config files (httpd, nginx, php-fpm, php.ini).

## Multi-Buildpack Fixes

- Fix PHP-FPM PID file path to use deps directory for multi-buildpack scenarios
- Fix nginx configuration for Unix socket and runtime variable expansion
- Update supply buildpack integration tests

## php.ini.d Context Bug Fix

Fix critical bug where php.ini.d directory was processed with deps context
(@{HOME} = /home/vcap/deps/{idx}) instead of app context (@{HOME} =
/home/vcap/app).

The php.ini.d directory contains user-provided PHP configurations that typically
reference application paths (include_path, open_basedir, etc.), similar to fpm.d
configs. Processing with deps context caused the buildpack-created
include-path.ini and user configs to reference incorrect paths.

### Changes:
- Process php.ini.d separately (like fpm.d) with app-context replacements
- Update supply.go comments to clarify php.ini.d context behavior
- Add fixture test for @{HOME} placeholder in php.ini.d configs
- Enhance modules integration test to verify placeholder replacement

Both fpm.d and php.ini.d now use app HOME context while other PHP configs
(php.ini, php-fpm.conf) use deps HOME context.

Fixes issues with:
- Buildpack-created include-path.ini referencing wrong directory
- User-provided php.ini.d configs using @{HOME} placeholders
- Include paths not resolving to application lib directory
Create a symlink from WEBDIR/vendor to the actual vendor directory during
Composer compilation. This allows apps to use relative require paths like
`require 'vendor/autoload.php'` from their web root (e.g., htdocs).

The symlink is only created when:
- WEBDIR exists (e.g., htdocs directory)
- Vendor directory is not already inside WEBDIR
- No existing vendor directory or symlink exists in WEBDIR
- Actual vendor directory exists after Composer installation

Example: If composer.json specifies vendor-dir as "lib/vendor" and WEBDIR is
"htdocs", this creates htdocs/vendor -> ../lib/vendor

This maintains backward compatibility for apps that reference vendor/autoload.php
from their web-accessible directory while keeping the actual vendor directory
outside the web root for security.

Also fixes placeholder syntax: #{LIBDIR} -> @{LIBDIR} to match the unified
@{VAR} syntax used throughout the buildpack.
This commit improves the integration test infrastructure with better cleanup,
more robust regex matching, and proper handling of unsupported features.

Changes:
- Fix integration test regex patterns for more reliable matching
- Skip custom extensions test (feature not yet supported in v5.x)
- Cleanup buildpack files after integration tests to prevent disk space issues

Test Infrastructure Improvements:
- Add buildpack cleanup in init_test.go to remove uploaded buildpacks after tests
- Refactor default_test.go regex patterns for better readability
- Add explicit skip for custom extensions with clear explanation

These changes improve test reliability and reduce CI/CD resource usage by
properly cleaning up test artifacts.
Add 80K of comprehensive documentation covering architecture, features, migration,
and service binding patterns for both end users and developers/maintainers.

Documentation Structure:
- docs/USER_GUIDE.md (15K, 865 lines) - Complete end-user guide
- docs/FEATURES.md (11K, 696 lines) - Developer reference with test coverage
- docs/BUILDPACK_COMPARISON.md (12K) - Cross-buildpack architectural analysis
- docs/VCAP_SERVICES_USAGE.md (12K) - Service binding patterns and best practices
- docs/REWRITE_MIGRATION.md (27K) - v4.x to v5.x migration guide
- docs/README.md (7K) - Navigation hub with best practices

USER_GUIDE.md (For End Users):
- Getting started (deploy in 2 commands)
- Web server configuration (Apache, Nginx, FPM-only)
- PHP configuration (versions, ini files, FPM pools)
- PHP extensions installation
- Composer and dependency management
- APM integration (NewRelic, AppDynamics, Dynatrace)
- Session storage (Redis, Memcached)
- Framework guides (Laravel, CakePHP, Symfony, Laminas)
- Advanced features (multi-buildpack, preprocess commands)
- Troubleshooting section

FEATURES.md (For Developers/Maintainers):
- 30+ features with explicit integration test references
- Test locations (file:line numbers)
- Fixture paths for each feature
- Implementation details and code snippets
- Test coverage analysis matrix
- Identification of features needing explicit tests
- Cross-references to integration tests

BUILDPACK_COMPARISON.md:
- Proves PHP v5.x follows same patterns as Go, Java, Ruby, Python buildpacks
- Documents VCAP_SERVICES availability during staging
- Explains why v4.x runtime rewrite was PHP-unique, not a CF standard
- Shows alignment with Cloud Foundry buildpack ecosystem

VCAP_SERVICES_USAGE.md:
- Clarifies VCAP_SERVICES IS available during staging (for extensions and Go code)
- Documents that @{VCAP_SERVICES} config file placeholders are not supported
- Provides service binding patterns and examples
- Migration strategies from v4.x
- Best practices and anti-patterns

REWRITE_MIGRATION.md:
- Comprehensive v4.x to v5.x migration guide
- Breaking changes in rewrite system
- Placeholder syntax changes
- User-provided config handling
- Corrects misconceptions about VCAP_SERVICES availability

Key Documentation Insights:
- VCAP_SERVICES IS available during staging in Go code (not just runtime)
- PHP v5.x aligns with all other CF buildpacks (Go, Java, Ruby, Python)
- v4.x runtime rewrite was PHP-unique, removed for CF standards alignment
- 95%+ test coverage verification for documented features
- Separate docs for end users vs developers/maintainers

The documentation demonstrates comprehensive feature coverage and provides
clear guidance for both buildpack users and maintainers.
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