mdshack / shotshare

Open source image sharing application
https://demo.shotshare.dev/
MIT License
137 stars 10 forks source link

Missing directories/files are not created if needed #31

Closed EmberHeartshine closed 6 months ago

EmberHeartshine commented 9 months ago

On a whim, and to see if I could keep things on my host machine, instead of creating a Docker volume with -v shotshare_data:/app/storage I created a directory under my host machine's ShotShare stuff, chown'd to 82:82 and mounted it with --mount type=bind,source=/shotshare/data,target=/app/storage. This threw a 500 error (from caddy, not from nginx) so I went digging. It looks like the logger will create /app/storage/logs/ if needed, but if the empty directories already present in the Docker image aren't there as expected then ShotShare won't create them. Namely:

Interestingly, an exception to this is /app/storage/app/uploads/, which gets created on first upload just fine.

mdshack commented 9 months ago

Hey @EmberHeartshine, for this pattern, I would actually just mount the /app/storage/app/uploads folder, that way you don't interfere with any of the framework native directories, while still being able to mount your shots to a directory. For ex. -v /shotshare/uploads:/app/storage/app/uploads.

EmberHeartshine commented 9 months ago

In this instance I specifically made a bind mount because I wanted the files to be on the host filesystem instead of obfuscated away in Docker's volume tree.

mdshack commented 9 months ago

In this instance I specifically made a bind mount because I wanted the files to be on the host filesystem instead of obfuscated away in Docker's volume tree.

So you should be able to use -v to accomplish this, if you specify a path before the colon it will use a path from your host file system, if you just use a string it will be a named volume.

-v /shotshare/uploads:/app/storage/app/uploads should mount /shotshare/uploads on your host to /app/storage/app/uploads in your container.

EmberHeartshine commented 9 months ago

Regardless of the syntax, I feel like the directories should be created if they're missing for whatever reason to avoid 500 errors.

mdshack commented 6 months ago

Updated the docs to point to the correct directory (app/storage/app/uploads), I plan to revisit setup process for further simplifications. Additionally, this change will not be backwards compatible (it will only work for new installations where their shotshare_data volume is empty), to fix this you will need to

  1. Create a new mount at the new path (not shotshare_data)
  2. Move the old mount elsewhere (ex. /tmp/shotshare_data)
  3. Manually copy the files from tmp to new volume (cp /tmp/shotshare_data/* /app/storage/app/uploads)
  4. Drop the old volume

https://github.com/mdshack/shotshare?tab=readme-ov-file#run-in-https-mode

EmberHeartshine commented 6 months ago

As noted, however, if you have the entire /app/storage directory mounted external to the docker image you don't have to change anything.