grocy-docker icon indicating copy to clipboard operation
grocy-docker copied to clipboard

Multiple users with own household

Open Poldi1977 opened this issue 2 years ago • 3 comments

Hello

I have read here that it is possible to use multiple databases with one instance by setting the environment variable GROCY_DATAPATH. I use Apache as a reverse proxy and Grocy runs in a docker container.

How do I need to configure Apache to manage multiple households with one Grocy instance?

I told a friend about Grocy and she wants to use it for her household. Since we have separate households, adding her as a user is not enough.

But I also don't want to run multiple Grocy instances (if it can be avoided).

I am grateful for tips and suggestions.

Many greetings Tim

Poldi1977 avatar Aug 27 '22 10:08 Poldi1977

Hi @Poldi1977! - my apologies for the delayed response here.

I think I understand your use case - you'd like to continue running a single instance of containerized grocy, and to store your own data and your friend's data in separate compartments within that -- as supported by the GROCY_DATAPATH feature.

A few questions to help provide guidance:

  • Can you check/confirm whether you're running linuxserver/grocy-based or grocy/...-based images within docker?
  • Are you running grocy by using a docker-compose.yml file?
  • How comfortable are you with modifying and maintaining a few changes to the "official" images in order to support this case?

And something that you may already have considered, but that I'll mention anyway: how to maintain and share backups is likely worth thinking about.

jayaddison avatar Sep 17 '22 16:09 jayaddison

Hello @jayaddison

Thank you for your answer.

  • I use the grocy/ based docker image
  • Exactly, I use a docker-compose.yml file
  • I think I should be able to manage this

I create backups of grocy on a daily basis.

Poldi1977 avatar Sep 17 '22 16:09 Poldi1977

Ok, thanks! This could be an incomplete guide, so please let me know if you find problems when attempting it, but this is my evaluation & recommendation so far:

Background

With any approach, it's recommended to:

  1. Fork a copy of this repository because some configuration changes will be required
  2. Take a recent backup of data from your volume, because there is a risk of problems while attempting the changes

Option 1 (single-grocy)

  1. Choose directory names for yourself and your friend -- perhaps usernames
  2. Stop the running grocy container
  3. Consider taking Apache (or the site(s) forwarding to your grocy instance within Apache) offline
  4. Locate and edit the app-db volume
  5. Move your data into a subdirectory, using your selected directory name
  6. Configure fastcgi_param GROCY_DATAPATH ... within the nginx configuration
    • This step will have to be somewhat customized for your situation - either the URL, hostname, headers, or some other Apache configuration is going to need to communicate the input that decides how to select the relevant datapath directory name.
  7. Rebuild the grocy containers using docker-compose build
  8. Start the containers and test connectivity outside Apache
    • For example, using curl or similar to send the appropriate request URLs / headers / auth details that your custom nginx configuration expects
    • This might create a few empty / test directories depending on how you do it, so you may want to restore-from-backup after testing
  9. Restore connectivity from Apache

There is some interesting overlap with the functionality discussed in https://github.com/grocy/grocy#1746. If there were a reliable way to have a $user variable provided to nginx then this could be included in the default configuration -- but until then we have the challenge that authentication tends to be different in almost every environment.

Option 2 (multi-grocy) If you run remove the single-instance requirement, and use multiple instances of grocy, there are some benefits and drawbacks.

On the plus side:

  • Custom image builds should not be required (since no nginx customization is taking place)
  • Co-ordination between Apache and nginx might be easier (map to a destination port, instead of potentially providing other selection criteria that an nginx configuration can read)

However, some editing of this repository's contents would still be required:

  • Editing docker-compose.yml to run and expose ports for multiple instances of the application -- and to define at least one extra volume
  • Checking/editing your backup solution to ensure that both backend data volumes are included

Disclaimer / Feedback I haven't attempted this myself, so "your mileage may vary" - please be careful with any changes!

If you find a way to achieve this that is opt-in and generalizes to other users, I'll be happy to take a look at that (either as a pull request or in a branch) and to consider bringing the changes into here "upstream" for others and to reduce your maintenance.

jayaddison avatar Sep 17 '22 17:09 jayaddison

Closing as maybe-resolved; please feel free to reopen if there's more to figure out here. Would be great to hear your feedback (here / blog post!) if you managed to get a multi-household system deployed, too.

jayaddison avatar Sep 15 '23 08:09 jayaddison