2

I upgraded a Laravel project from version 7 to 8. When I attempt to deploy it on App Engine, it fails saying "Please provide a valid cache path":

Updating service [***]...failed.
ERROR: (gcloud.app.deploy) Error Response: [9] Cloud build [***] status: FAILURE
Error type: UNKNOWN

[...]

> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi

In Compiler.php line 36:

  Please provide a valid cache path.

Part of my composer.json:

"scripts": {
    "post-autoload-dump": [
        "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
        "@php artisan package:discover --ansi",
        "@php artisan vendor:publish --force --tag=livewire:assets --ansi"
    ],
    "post-create-project-cmd": [
        "@php artisan key:generate --ansi"
    ],
    "post-update-cmd": [
        "Illuminate\\Foundation\\ComposerScripts::postUpdate",
        "@php artisan ide-helper:generate",
        "@php artisan ide-helper:meta"
    ],
    "post-install-cmd": [
        "composer dump-autoload",
        "php artisan config:clear",
        "php artisan cache:clear",
        "php artisan view:clear",
        "php artisan cache:clear",
        "php artisan optimize:clear"
    ]

A snippet from app.yaml:

env_variables:
  APP_STORAGE: /tmp
  VIEW_COMPILED_PATH: /tmp
  APP_SERVICES_CACHE: /tmp/services.php
  APP_PACKAGES_CACHE: /tmp/packages.php
  APP_CONFIG_CACHE: /tmp/config.php
  APP_ROUTES_CACHE: /tmp/routes.php
  CACHE_DRIVER: database
  SESSION_DRIVER: database

I do have /storage/framework/views folder along with the other standard folders under /storage as well as bootstrap/cache.

If I remove this line from composer.json (under "post-autoload-dump"):

"@php artisan vendor:publish --force --tag=livewire:assets --ansi"

I am able to deploy the app but it fails on pages that use Livewire components with the following error:

The /workspace/bootstrap/cache directory must be present and writable. (View: /workspace/resources/views/users/edit.blade.php)
ErrorException
in /workspace/vendor/livewire/livewire/src/LivewireComponentsFinder.php (line 58)
in /workspace/vendor/livewire/livewire/src/CompilerEngine.php -> handleViewException (line 41)
in /workspace/vendor/laravel/framework/src/Illuminate/View/Engines/PhpEngine.php -> handleViewException (line 60)
in /workspace/vendor/livewire/livewire/src/LivewireViewCompilerEngine.php -> evaluatePath (line 36)
in /workspace/vendor/laravel/framework/src/Illuminate/View/Engines/CompilerEngine.php -> evaluatePath (line 61)
in /workspace/vendor/laravel/framework/src/Illuminate/View/View.php -> get (line 139)

This happens even though I added the following line to bootstrap/app.php:

$app->useStoragePath(env('APP_STORAGE', base_path() . '/storage'));

following the guide.

Prior to upgrading Laravel, I had no problems deploying the app on App Engine.

Mateusz
  • 2,340
  • 25
  • 24

3 Answers3

2

This is a really annoying error. It happened every now and then and I still haven't found a fix. I'm sure that there is something weird happening in Cloud Build, I just don't know what. Anyone have any ideas other that the mentioned above please share.


Edit

I believe the issue lies complied views path as explained here

Now, setting VIEW_COMPILED_PATH to /tmp is necessary for the app to run BUT, the error occurs during build. During build, the compiled views cache path is read not from app.yaml but from the config/view.php or maybe .env where the value usually is realpath(storage_path('framework/views')). Now, that is absolutely fine under normal circumstances. The last piece of the puzzle is gcloud app deploy which will for some reason neglect to deploy empty directories or directories with only .gitignore in them, hence, storage/framework/views will not be deployed and during build the error will occur.

Possible fixes:

  1. Add some random file (other than .gitignore) in 'storage/framework/views' before deploying to make sure the directory is available during build.

  2. Change the default value in config/views to a directory that is present during build.

Any other way to ensure that storage/framework/views is not ignored (present during build) should do.

zjbarg
  • 680
  • 3
  • 16
2

My working solution was to edit config/view.php:

   'compiled' => env(
        'VIEW_COMPILED_PATH',
        isset($_SERVER['GAE_SERVICE']) ?
            '/tmp'
            : realpath(storage_path('framework/views'))
    ),

This will make sure that the default location for compiled views when the app is running on GAE machine is located to /tmp directory instead of storage/framework/views.

Nurul Huda
  • 1,438
  • 14
  • 12
0

The solution was to update the Livewire dependency.

Before:

"livewire/livewire": "^1.1",

After:

"livewire/livewire": "^2.1",

Any version beginning with 2.0 seems to work.

Mateusz
  • 2,340
  • 25
  • 24