Skip to content

PHP - Composer Autoload incorrect due to caching layer #492

@rlweb

Description

@rlweb

Describe the bug

Composer Autoloader files are not re-created on a cached build.

On the initial build the following command is ran composer install --no-dev --no-progress --no-interaction --optimize-autoloader. This triggers a Generating optimized autoload files which includes all classes which exist in the workspace including any composer dependencies.

On the next build using a cache, this existing composer autoloader files are used which may not contain updates to the local workspace i.e. removed or added classes. Added classes are not an issue since the autoloader falls back to searching the file system but removed classes are attempted to be loaded on system startup which causes the warning shown at the bottom.

I've added a PR which runs composer dump-autoload --optimize to resolve this (untested, see comment).

Additional context
How are you using GCP buildpacks?

  • pack and the gcr.io/buildpacks/builder
  • Cloud Functions
  • Cloud Run
  • Cloud Build
  • App Engine Standard
  • App Engine Flex
  • Firebase App Hosting

Did this used to work?

No

What language is your project primarily written in?

PHP

Steps To Reproduce

Steps to reproduce the behavior:

  1. Run an appengine PHP build (try using a example repo such laravel)
  2. Delete a PHP class
  3. Rerun an appengine PHP build (which should use the composer cache)
  4. A - Explore the container image and view the vendor/composer/autoload_classmap.php file which contains the missing file
  5. B - Whilst hitting with requests you should notice the below warning

Expected behavior

No warning thrown / existing autoloader does not contain files which no longer exist.

Actual behavior

The below error is triggered due to the composer autoloader listing files which no longer exist.

E_WARNING: include(/workspace/vendor/composer/../../www/Internal files/Purchase.php): Failed to open stream: No such file or directory

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions