algolia / scout-extended

Scout Extended: The Full Power of Algolia in Laravel
https://www.algolia.com/doc/framework-integration/laravel/getting-started/introduction-to-scout-extended/
MIT License
393 stars 85 forks source link

Sync Read-only Filesystem Error #322

Open blhylton opened 1 year ago

blhylton commented 1 year ago

Description

You cannot run the scout:sync command on Laravel Vapor if the settings on Algolia have been changed independently.

🔎 Analysing settings from: [App\Event]
Downloading remote settings...

In Filesystem.php line 205:

file_put_contents(/var/task/config/scout-prod-events-8827424.php): Failed to open stream: Read-only file system

When attempting to run the command, I get stuck on this model because some things were updated in Algolia, and it's trying to sync the server settings to the file. Vapor does not have writable storage like this.

Steps To Reproduce

This is a little guesswork on my part as to "why this model?" but I feel reasonably confident that it is because sync is attempting to write to local storage explicitly instead of just allowing whatever the default is to take over. Laravel Vapor doesn't really have local storage other than a small amount of incidental temporary space.

DevinCodes commented 1 year ago

Hi @blhylton ,

As far as I can tell, this is the expected behaviour for the scout:sync command: if settings have been changed in Algolia, it will synchronise them to the settings file in your config. You should therefore only synchronise on a system where you have write access. You can, for example, run the command locally to ensure it's up to date with Algolia. Then, any changes to the settings that need to be made can be made in the settings file directly and be applied in a read-only environment by syncing from your app to Algolia, and not the other way around.

I hope that helps, let me know if anything is unclear! 🙂

blhylton commented 1 year ago

Hi @DevinCodes

I understand what you're saying, but the issue is that this stops the command from running entirely. Even if flagged as --keep local, it will still attempt to download the file to the unwritable storage. After some testing, this is also an issue if you have a searchable model that you don't want to be synced to Algolia, so you don't have Algolia indexes set up for it (we have two different Scout engines being used in this particular project for different purposes).

Ideally, I would be able to skip updating server -> local and skip the run of scout:optimize so that I can run this from production without writing to the code and ensure that the production Algolia index is in sync with the production schema.

The issue with running it locally is that I have different indexes for production, staging, local, etc.; swapping them out would be manual and annoyingly error-prone.

DevinCodes commented 1 year ago

Hey @blhylton ,

Thank you for the explanation of your use case, it makes a lot of sense. I definitely see value in adding an option that would skip updating server settings to local to circumvent this issue, and would be open to review a PR that addresses this 🙂