Add Redis support / make database location and provider selectable in setup (#180)

This commit is contained in:
Marc Ole Bulling
2024-07-07 22:13:51 +02:00
committed by GitHub
parent f7ba24913d
commit b56970bf88
66 changed files with 3326 additions and 966 deletions

View File

@@ -57,41 +57,45 @@ Available environment variables
==================================
+-----------------------------+-------------------------------------------------------------------------------------+-----------------+-----------------------------+
| Name | Action | Persistent [*]_ | Default |
+=============================+=====================================================================================+=================+=============================+
| GOKAPI_CHUNK_SIZE_MB | Sets the size of chunks that are uploaded in MB | Yes | 45 |
+-----------------------------+-------------------------------------------------------------------------------------+-----------------+-----------------------------+
| GOKAPI_CONFIG_DIR | Sets the directory for the config file | No | config |
+-----------------------------+-------------------------------------------------------------------------------------+-----------------+-----------------------------+
| GOKAPI_CONFIG_FILE | Sets the name of the config file | No | config.json |
+-----------------------------+-------------------------------------------------------------------------------------+-----------------+-----------------------------+
| GOKAPI_DATA_DIR | Sets the directory for the data | Yes | data |
+-----------------------------+-------------------------------------------------------------------------------------+-----------------+-----------------------------+
| GOKAPI_DB_NAME | Sets the name for the database file | No | gokapi.sqlite |
+-----------------------------+-------------------------------------------------------------------------------------+-----------------+-----------------------------+
| GOKAPI_LENGTH_ID | Sets the length of the download IDs. Value needs to be 5 or more | Yes | 15 |
+-----------------------------+-------------------------------------------------------------------------------------+-----------------+-----------------------------+
| GOKAPI_MAX_FILESIZE | Sets the maximum allowed file size in MB | Yes | 102400 (100GB) |
+-----------------------------+-------------------------------------------------------------------------------------+-----------------+-----------------------------+
| GOKAPI_MAX_MEMORY_UPLOAD | Sets the amount of RAM in MB that can be allocated for an upload chunk or file | Yes | 50 |
| | | | |
| | Any chunk or file with a size greater than that will be written to a temporary file | | |
+-----------------------------+-------------------------------------------------------------------------------------+-----------------+-----------------------------+
| GOKAPI_MAX_PARALLEL_UPLOADS | Set the amount of chunks that are uploaded in parallel for a single file | Yes | 4 |
+-----------------------------+-------------------------------------------------------------------------------------+-----------------+-----------------------------+
| GOKAPI_PORT | Sets the webserver port | Yes | 53842 |
+-----------------------------+-------------------------------------------------------------------------------------+-----------------+-----------------------------+
| GOKAPI_DISABLE_CORS_CHECK | Disables the CORS check on startup and during setup, if set to true | No | false |
+-----------------------------+-------------------------------------------------------------------------------------+-----------------+-----------------------------+
| GOKAPI_LOG_STDOUT | Also outputs all log file entries to the console output | No | false |
+-----------------------------+-------------------------------------------------------------------------------------+-----------------+-----------------------------+
| DOCKER_NONROOT | Docker only: Runs the binary in the container as a non-root user, if set to true | No | false |
+-----------------------------+-------------------------------------------------------------------------------------+-----------------+-----------------------------+
| TMPDIR | Sets the path which contains temporary files | No | Non-Docker: Default OS path |
| | | | |
| | | | Docker: [DATA_DIR] |
+-----------------------------+-------------------------------------------------------------------------------------+-----------------+-----------------------------+
+-------------------------------+-------------------------------------------------------------------------------------+-----------------+--------------------------------------+
| Name | Action | Persistent [*]_ | Default |
+===============================+=====================================================================================+=================+======================================+
| GOKAPI_CHUNK_SIZE_MB | Sets the size of chunks that are uploaded in MB | Yes | 45 |
+-------------------------------+-------------------------------------------------------------------------------------+-----------------+--------------------------------------+
| GOKAPI_CONFIG_DIR | Sets the directory for the config file | No | config |
+-------------------------------+-------------------------------------------------------------------------------------+-----------------+--------------------------------------+
| GOKAPI_CONFIG_FILE | Sets the name of the config file | No | config.json |
+-------------------------------+-------------------------------------------------------------------------------------+-----------------+--------------------------------------+
| GOKAPI_DATA_DIR | Sets the directory for the data | Yes | data |
+-------------------------------+-------------------------------------------------------------------------------------+-----------------+--------------------------------------+
| GOKAPI_DATABASE_URL | Sets the type and location of the database. See :ref:`Databases` | Yes | sqlite://[data folder]/gokapi.sqlite |
+-------------------------------+-------------------------------------------------------------------------------------+-----------------+--------------------------------------+
| GOKAPI_LENGTH_ID | Sets the length of the download IDs. Value needs to be 5 or more | Yes | 15 |
+-------------------------------+-------------------------------------------------------------------------------------+-----------------+--------------------------------------+
| GOKAPI_MAX_FILESIZE | Sets the maximum allowed file size in MB | Yes | 102400 (100GB) |
+-------------------------------+-------------------------------------------------------------------------------------+-----------------+--------------------------------------+
| GOKAPI_MAX_MEMORY_UPLOAD | Sets the amount of RAM in MB that can be allocated for an upload chunk or file | Yes | 50 |
| | | | |
| | Any chunk or file with a size greater than that will be written to a temporary file | | |
+-------------------------------+-------------------------------------------------------------------------------------+-----------------+--------------------------------------+
| GOKAPI_MAX_PARALLEL_UPLOADS | Set the amount of chunks that are uploaded in parallel for a single file | Yes | 4 |
+-------------------------------+-------------------------------------------------------------------------------------+-----------------+--------------------------------------+
| GOKAPI_PORT | Sets the webserver port | Yes | 53842 |
+-------------------------------+-------------------------------------------------------------------------------------+-----------------+--------------------------------------+
| GOKAPI_DISABLE_CORS_CHECK | Disables the CORS check on startup and during setup, if set to "true" | No | false |
+-------------------------------+-------------------------------------------------------------------------------------+-----------------+--------------------------------------+
| GOKAPI_LOG_STDOUT | Also outputs all log file entries to the console output | No | false |
+-------------------------------+-------------------------------------------------------------------------------------+-----------------+--------------------------------------+
| DOCKER_NONROOT | Docker only: Runs the binary in the container as a non-root user, if set to "true" | No | false |
+-------------------------------+-------------------------------------------------------------------------------------+-----------------+--------------------------------------+
| TMPDIR | Sets the path which contains temporary files | No | Non-Docker: Default OS path |
| | | | |
| | | | Docker: [DATA_DIR] |
+-------------------------------+-------------------------------------------------------------------------------------+-----------------+--------------------------------------+
| GOKAPI_DB_NAME *(deprecated)* | Sets the name for the database file. | No | gokapi.sqlite |
| | | | |
| | *Deprecated: Only used during update. Will be removed with v1.10.0* | | |
+-------------------------------+-------------------------------------------------------------------------------------+-----------------+--------------------------------------+
.. [*] Variables that are persistent must be submitted during the first start when Gokapi creates a new config file. They can be omitted afterwards. Non-persistent variables need to be set on every start.
@@ -123,6 +127,85 @@ All values that are described in :ref:`cloudstorage` can be passed as environmen
+---------------------------+-----------------------------------------+-----------------------------+
.. _databases:
********************************
Databases
********************************
By default, Gokapi uses an SQLite database for data storage, which should suffice for most use cases. Additionally, Redis is available as an experimental option.
Migrating to a different database
=================================
To switch to a different database, Gokapi provides a migration tool. By running:
::
gokapi --migrate [old Database URL] [new Database URL]
all existing data, except for user sessions, will be transferred to the new database. After the migration, you will need to rerun the setup and specify the new database location. For details on the correct database URL format, refer to the section :ref:`databaseUrl`.
For Docker users, the command is:
::
docker run --rm -v gokapi-data:/app/data f0rc3/gokapi:latest /app/run.sh [old Database URL] [new Database URL]
.. _databaseUrl:
Database URL format
---------------------------------
Database URLs must start with either ``sqlite://`` or ``redis://``.
For SQLite, the path to the database follows the prefix. No additional options are allowed.
For Redis, the URL can include authentication credentials (username and password), an optional prefix for keys, and parameter to use SSL.
Redis URL Format
^^^^^^^^^^^^^^^^^^^^^^^^^^
A Redis URL has the following structure:
::
redis://[username:password@]host[:port][?options]
* username: (optional) The username for authentication.
* password: (optional) The password for authentication.
* host: (required) The address of the Redis server.
* port: (optional) The port of the Redis server (default is 6379).
* options: (optional) Additional options such as SSL (``ssl=true``) and key prefix (``prefix=``).
Examples
---------------------------------
Migrating SQLite (``/app/data/gokapi.sqlite``) to Redis (``127.0.0.1:6379``):
::
gokapi --migrate sqlite:///app/data/gokapi.sqlite redis://127.0.0.1:6379
Migrating SQLite (``/app/data/gokapi.sqlite``) to SQLite (``./data/gokapi.sqlite``):
::
gokapi --migrate sqlite:///app/data/gokapi.sqlite sqlite://./data/gokapi.sqlite
Migrating Redis (``127.0.0.1:6379, User: test, Password: 1234, Prefix: gokapi_, using SSL``) to SQLite (``./data/gokapi.sqlite``):
::
gokapi --migrate "redis://test:1234@127.0.0.1:6379?prefix=gokapi_&ssl=true" sqlite://./data/gokapi.sqlite
.. _api:

View File

@@ -86,6 +86,23 @@ During the first start, a new configuration file will be created and you will be
Database
""""""""""""""
By default, Gokapi stores its data in a database located in the ``data`` directory. You can specify a different database location in this menu. If no changes are needed, you can proceed as is. Experimental Redis support is also available.
You can configure the following settings:
- **Type of database** Choose either SQLite or Redis.
- **Database location** Specify the path to the SQLite database.
- **Database host** Provide the host and port number for the Redis database.
- **Key prefix (optional)** This prefix will be added to all keys to prevent conflicts if the database is shared with other applications.
- **Username (optional)** Enter the username for database connection.
- **Password (optional)** Enter the password for database connection.
- **Use SSL** Select this option to establish an SSL connection.
.. warning::
The Redis password will be stored in plain text and can be viewed when re-running the setup.
Webserver
""""""""""""""