inventree / InvenTree

Open Source Inventory Management System
https://docs.inventree.org
MIT License
4.29k stars 776 forks source link

Inventree S3 backup options syntax #8151

Closed yoxx closed 1 month ago

yoxx commented 1 month ago

Deployment Method

Describe the problem*

We are trying to deploy inventree in our k8s cluster. We want to store our backups in S3.

Based on your documentation we do not find it clear how to provide a dict to this env variable -> https://docs.inventree.org/en/stable/start/backup/#configuration

Our deployement looks something like this:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: inventree-app
spec:
  template:
    spec:
      initContainers:
        - name: init-migrate
          env:
            - name: INVENTREE_BACKUP_STORAGE
              value: "storages.backends.s3boto3.S3Boto3Storage"
            - name: INVENTREE_BACKUP_OPTIONS
              value: '{"access_key": "xxxx","secret_key": "xxxx","bucket_name": "xxxx","default_acl": "private"}'

When deployed we get an error from the storage class :

TypeError: dbbackup.storage.Storage() argument after ** must be a mapping, not str
  File "/root/.local/lib/python3.11/site-packages/dbbackup/utils.py", line 120, in wrapper
    func(*args, **kwargs)
  File "/root/.local/lib/python3.11/site-packages/dbbackup/management/commands/dbbackup.py", line 80, in handle
    self.storage = get_storage()
                   ^^^^^^^^^^^^^
  File "/root/.local/lib/python3.11/site-packages/dbbackup/storage.py", line 33, in get_storage
    return Storage(path, **options)
           ^^^^^^^^^^^^^^^^^^^^^^^^

Traceback (most recent call last):
  File "/home/inventree/src/backend/InvenTree/manage.py", line 24, in <module>
    main()
  File "/home/inventree/src/backend/InvenTree/manage.py", line 20, in main
    execute_from_command_line(sys.argv)
  File "/root/.local/lib/python3.11/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "/root/.local/lib/python3.11/site-packages/django/core/management/__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)

So it appears it sees our dict as a string, what would be the correct syntax to fix this using enviroment variables?

Steps to Reproduce

  1. use https://docs.inventree.org/en/stable/start/backup/#configuration for external providers which points to django-dbbackup
  2. https://django-dbbackup.readthedocs.io/en/master/storage.html#amazon-s3
  3. Shows a dict in the DBBACKUP_STORAGE_OPTIONS which as far as I understand translates to INVENTREE_BACKUP_OPTIONS in inventree
  4. See above ^

Relevant log output

No response

SchrodingersGat commented 1 month ago

Looks like an issue with the way DBBACKUP_STORAGE_OPTIONS is being loaded.

See fix incoming in https://github.com/inventree/InvenTree/pull/8153