Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to store all files in storage #1650

Merged
merged 12 commits into from
Jan 8, 2023
Merged

Allow to store all files in storage #1650

merged 12 commits into from
Jan 8, 2023

Conversation

qwerty287
Copy link
Contributor

@qwerty287 qwerty287 commented Dec 22, 2022

Change storage paths etc. to only require the storage directory to be writable to the web user by default.

Especially migrating them is a bit special and might result in various issues.

public/{uploads,sym} is now in storage/app/public/{uploads,sym}, user.css is in storage/app/public/user.css. These files are linked with a symbolic link to public/storage/ which is the recommended way of Laravel.

TODO:

  • new path for uploads, sym, user.css
  • rename old files
  • link bootstrap/cache to storage
  • change default sqlite location to storage/app/database.sqlite

Advantages

This allows you to only make storage/ writable to the web user which enhances security. In addition, it allows you to easily backup the whole instance: copy storage/app/. Currently, you have to copy multiple paths which makes this pretty hard.

Breaking: the DB path changed, and this must be renamed by the user. Otherwise Laravel won't find the new database file and can't migrate the old one. So, the release notes should contains something like: If you're using SQLite with an empty DB_DATABASE configuration (using default values), please run the following command in your shell to move the database file to the new default location: mv database/database.sqlite storage/app/database.sqlite

@qwerty287 qwerty287 changed the title Only require writable storage Store all files in storage by default Dec 22, 2022
@qwerty287 qwerty287 added this to the 4.7.0 milestone Dec 22, 2022
@codecov
Copy link

codecov bot commented Dec 22, 2022

Codecov Report

Merging #1650 (8bafa8f) into master (ecef28a) will decrease coverage by 0.22%.
The diff coverage is 100.00%.

Additional details and impacted files

@qwerty287 qwerty287 changed the base branch from user-installation to master December 22, 2022 12:44
@qwerty287 qwerty287 marked this pull request as ready for review December 22, 2022 12:46
@d7415
Copy link
Contributor

d7415 commented Dec 23, 2022

Especially migrating them is a bit special and might result in various issues.

Yes. This is likely to break a lot of installations.

This allows you to only make storage/ writable to the web user which enhances security.

This is plainly false, though I get your point.

If you're using SQLite with an empty DB_DATABASE configuration (using default values), please run the following command in your shell to move the database file to the new default location: mv database/database.sqlite storage/app/database.sqlite

I'm not convinced a shell command is a good instruction here. I'd just say "move..."

But yeah, my main concern here is breaking lots. Well, that and cluttering up the Docker scripts with things that are only needed once but will need to be run every time because we don't know the state. It feels like a very small improvement for new installations at the cost of a high risk operation (admittedly of breakage, rather than loss) for all existing users.

@qwerty287
Copy link
Contributor Author

Especially migrating them is a bit special and might result in various issues.

Yes. This is likely to break a lot of installations.

I actually tried to prevent issues, this includes a migration which moves the files. I wasn't sure if there are special setups like S3 storage or something like this which was the main reason for me to write this.

In general, I definitely understand your concerns. My main issue is that Lychee stores everything somewhere else. Maybe, a good idea would be some kind of option in .env that allows you to set all paths to storage by default. This is easy to do and will not break installations: if you want your data in storage, you can enable the option, otherwise, the old paths are used. If you want to migrate, you can move the files and enable the option. I mainly want to make it more consistent where data is stored. Some parts are easy to change here (e.g. database path), others are pretty complex (e.g. user.css).
What do you think about an option in .env that changes all storage paths to the locations I suggested in this PR, but keeps the old ones if it's not enabled?

What you would mainly need to change to support this are symlinks to storage and changed paths to the DB and the filesystem disks.

@d7415
Copy link
Contributor

d7415 commented Dec 23, 2022

What do you think about an option in .env that changes all storage paths to the locations I suggested in this PR, but keeps the old ones if it's not enabled?

That sounds messier. if we're going to do it, we should just do it, but we need to accept that it's a big change, likely a breaking change and needs to be handled accordingly (including being sure that we're not going to do this again). And it needs to be worth it.

I think it's probably a worthwhile change to simplify things, I'm just not sure it's worth the upheaval. I'd be interested how the others feel.

@ildyria
Copy link
Member

ildyria commented Dec 23, 2022

I am not convinced by that change. :( Backup currently is basically just the upload folder in public and the database.
Furthermore why storage/app/public instead of just... storage/public ? :)

@d7415
Copy link
Contributor

d7415 commented Dec 23, 2022

Furthermore why storage/app/public instead of just... storage/public ? :)

I think that was so that all of the backup items (photos, db, etc) were in one place away from unimportant Laravel stuff in storage.

@qwerty287
Copy link
Contributor Author

qwerty287 commented Dec 24, 2022

Yes, also storage/app/ is Laravel's default. storage/app/public is for public stuff which is symlinked to the public folder.

As for the backup: this works as long as you don't use the public/sym folder or user.css. They must be backed up separately, and then we already have 4 folders/files you need to store.

@ildyria
Copy link
Member

ildyria commented Dec 24, 2022

As for the backup: this works as long as you don't use the public/sym folder.

I would not back up those. Does not make much sense, and you can just regenerate them on first use, just need to clean the DB on sym_links. :)

@qwerty287
Copy link
Contributor Author

I see that this will be a very problematic change, so let me suggest a simpler changing only a few files and being fully optional:

  1. let git ignore public/storage to allow using the artisan storage:link command
  2. allow changing storage locations of user.css and public/sym
  3. symlink bootstrap/cache to storage/cache

This will make all moving of files to storage optional while being able to still store everything there. In addition, it's a clean solution.

@qwerty287 qwerty287 removed this from the 4.7.0 milestone Dec 25, 2022
@qwerty287 qwerty287 requested a review from a team December 29, 2022 09:08
@qwerty287 qwerty287 changed the title Store all files in storage by default Allow to store all files in storage Jan 2, 2023
@qwerty287 qwerty287 added this to the 4.7.1 milestone Jan 2, 2023
Copy link
Member

@ildyria ildyria left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quickly tested. LGTM.

@qwerty287 qwerty287 merged commit 490d651 into master Jan 8, 2023
@qwerty287 qwerty287 deleted the only-storage branch January 8, 2023 18:26
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.

3 participants