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.
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:
Add some random file (other than .gitignore) in 'storage/framework/views' before deploying to make sure the directory is available during build.
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.
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.
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.
Related
Dear Sparkers/Laravellers
I am transforming an old Spark project (i believe version 6) to the latest version 11.
To make some changes in the Spark PHP files, I've copied the files under vendor/laravel/spark-aurelius to a newly created folder named spark. Next, I've changed in the composer.json:
"repositories": [
{
"type": "composer",
"url": "https://spark-satis.laravel.com"
}
]
to
"repositories": [
{
"type": "path",
"url": "./spark"
}
]
Thereby notifying Laravel/Spark that it should use the files in the spark folder. Also, I've changed
"laravel/spark-aurelius": "~11.0",
to
"laravel/spark-aurelius": "*#dev",
Since that was something that was done in my original older Spark installation.
Next, I performed a composer update (lots of changes) until it finished.
However, when I make some test changes to the routes.php in Spark/src/Http/routes.php and save them it's not working. The old routes are still used.
I've also cleared cache:
php artisan optimize:clear
php artisan route:clear
php artisan config:clear
php artisan cache:clear
php artisan view:clear
Any other tips?
Well, there was only step missing (not mentioned in the original documentation!). So it appears we need to remove the complete vendor folder before doing composer update.
If you perform this task, and then go to the vendor/laravel folder and do ls -al you'll discover that the spark folder is now nicely referenced to the one that was provided:
spark-aurelius -> ../../spark
I have created new package and i want to avoid publish command separately and i need to include publish command inside package composer.json file. So when package is install it should move the files according to service provider path.
I tried below method but assets/files are not published.
"scripts": {
"post-install-cmd": [
"php artisan vendor:publish --provider=\"<vendorname>\\<packagename>\\<Serviceprovider>\" --tag=public --force",
"php artisan migrate"
],
"post-update-cmd": [
"php artisan vendor:publish --provider=\"<vendorname>\\<packagename>\\<Serviceprovider>\" --tag=public --force",
"php artisan migrate"
]
}
But it works fine when directly run the command like below
php artisan vendor:publish --provider="<vendorname>\<packagename>\<Serviceprovider>"
Please provide solution for it.
Did you try with below code manually. If it returns the thing you need, then you are on the right track. Else some typo is on command of script.
composer run-script post-install-cmd
Composer does not support automatically running scripts other than those at root level. This is somewhat contested, but doesn't look like it's going to change any time soon.
Your best bet is probably to manually run the command / instruct users to manually run the command in your readme: composer run-script post-install-cmd -d ./vendor/[name]/[package]
Maybe you should try to use # before command, and also I suggesting to you to try write command in "post-autoload-dump" section. It is work for me.
"scripts": {
"post-autoload-dump": [
"#php artisan vendor:publish --provider='<vendorname>\\<packagename>\\<Serviceprovider>' --tag=public --force",
"#php artisan migrate"
]
}
Lets say my project has following structure
project\
templates\
web\assets\
composer.json
When running the composer update by default symlink to my project is created in vendor/ directory. I would like to create a custom post-install-cmd script that would create symlink to templates\ and web\assets\ folder in a different location.
Since my team is working on Windows/Mac/Linux I planned in running a simple php commands to make this happen. I can't seem to figure out where to start ...
The thing is, I can't figure out where is my current location when starting a php script? I've tried creating an empty file to see where it creates it, but it doesn't even create it.
This is what I wish to get working
"scripts": {
"post-install-cmd": [
"php -r \"symlink('/vendor/project/templates', '/templates/project');\"",
"php -r \"symlink('/vendor/project/web/assets', '/web/project/assets');\""
]
}
You should probably remove leading slashes from paths - at least on unix it will be interpreted as absolute path and definitely will not point to your project.
"scripts": {
"post-install-cmd": [
"php -r \"symlink('vendor/project/templates', 'templates/project');\"",
"php -r \"symlink('vendor/project/web/assets', 'web/project/assets');\""
]
}
If you want a bulletproof solution, you should probably create PHP helper class and use __DIR__ lub composer API to define correct paths. See examples in documentation.
I have a package and my ServiceProvider copies the migrations. This works fine after php artisan migrate. But now i want to execute the package migration when i do composer update name/name-package.
So, php artisan update name/packagename and directly automaticly migrate.
How can i achieve that?
$this->publishes([
__DIR__ . '/database/migrations' => $this->app->databasePath() . '/migrations'
], 'migrations');
in application (not package) composer.json
"scripts": {
"post-update-cmd": [
"php artisan optimize",
"php artisan migrate"
]
}
the order of commands is up to you. Also, you may create a command or use php artisan vendor:publish --provider=... to move the migrations
i followed these , laravel virsion 5.4.16
https://www.youtube.com/watch?v=bqkt6eSsRZs&t=29s
You need to regenerate namespaces autoload
composer dump-autoload
"php artisan make:auth" produces all the authentication scaffolding required for the authentication process.
Type "php artisan make:auth" in your terminal right in the directory of your project. You will need to tidy up your install by deleting the "layouts folder" folder within the "resources folder", and also change the "#extends('layouts.app')" to "#extends('main')" in the login.blade.php and register.blade.php views within the "resources/views/auth" folder. Also you should then run "php artisan route:list" to see the names and locations of the auth routes.
I hope this helps