fix env vars overwritten by system

This commit is contained in:
FuzzyGrim
2024-01-31 18:37:08 +01:00
parent b0eb746799
commit 934e825815
8 changed files with 39 additions and 45 deletions

View File

@@ -24,7 +24,6 @@ It uses [The Movie Database](https://www.themoviedb.org/) and [MyAnimeList](http
Copy the default `docker-compose.yml` file from the repository and set the environment variables. This would use a SQlite database, which is enough for most use cases.
To start the containers run:
```bash
@@ -35,29 +34,28 @@ Alternatively, if you need a PostgreSQL database, you can use the `docker-compos
### Environment variables
| Name | Type | Description | Required | Default | Notes |
|-----------------|--------|----------------------------|-------------|----------|----------------------------------------------|
| TMDB_API | String | The Movie Database API key | Yes | None | Required for movies and tv shows |
| MAL_API | String | MyAnimeList API key | Yes | None | Required for anime and manga |
| SECRET | String | Django secret key | Recommended | "secret" | [SECRET_KEY](https://docs.djangoproject.com/en/4.2/ref/settings/#secret-key) |
| ALLOWED_HOSTS | List | Base IP / Domain | No | "*" | [ALLOWED_HOSTS](https://docs.djangoproject.com/en/4.1/ref/settings/#allowed-hosts) |
| PUID | Int | User ID | No | 1000 | |
| PGID | Int | Group ID | No | 1000 | |
| TZ | String | Timezone | No | UTC | |
| HTTPS_COOKIES | Bool | Cookies over HTTPS | No | False | [SESSION_COOKIE_SECURE](https://docs.djangoproject.com/en/4.1/ref/settings/#std-setting-SESSION_COOKIE_SECURE) and [CSRF_COOKIE_SECURE](https://docs.djangoproject.com/en/4.1/ref/settings/#std-setting-CSRF_COOKIE_SECURE) |
| REGISTRATION | Bool | User registration | No | True | |
| WEB_CONCURRENCY | Int | Number of worker processes | No | 1 | [(2 x num cores) + 1](https://docs.gunicorn.org/en/latest/design.html#how-many-workers) recommended|
| DEBUG | Bool | Django debug mode | No | False | |
| Name | Type | Description | Required | Default | Notes |
| ---------------------- | ------ | -------------------------- | ----------- | -------- | --------------------------------------------------------------------------------------------------- |
| YAMTRACK_TMDB_API | String | The Movie Database API key | Yes | None | Required for movies and tv shows |
| YAMTRACK_MAL_API | String | MyAnimeList API key | Yes | None | Required for anime and manga |
| YAMTRACK_SECRET | String | Django secret key | Recommended | "secret" | [SECRET_KEY](https://docs.djangoproject.com/en/stable/ref/settings/#secret-key) |
| YAMTRACK_ALLOWED_HOSTS | List | Base IP / Domain | No | "\*" | [ALLOWED_HOSTS](https://docs.djangoproject.com/en/stable/ref/settings/#allowed-hosts) |
| YAMTRACK_REGISTRATION | Bool | User registration | No | True | |
| YAMTRACK_DEBUG | Bool | Django debug mode | No | False | |
| PUID | Int | User ID | No | 1000 | |
| PGID | Int | Group ID | No | 1000 | |
| TZ | String | Timezone | No | UTC | |
| WEB_CONCURRENCY | Int | Number of worker processes | No | 1 | [(2 x num cores) + 1](https://docs.gunicorn.org/en/latest/design.html#how-many-workers) recommended |
### Environment variables for PostgreSQL
| Name | Type | Description | Required | Default | Notes |
|-------------|--------|-------------------|----------|------------|------------------------------|
| DB_HOST | String | Database host | No | None | When not set, sqlite is used |
| DB_PORT | Int | Database port | No | 5432 | |
| DB_NAME | String | Database name | No | "yamtrack" | |
| DB_USER | String | Database user | No | "yamtrack" | |
| DB_PASSWORD | String | Database password | No | "yamtrack" | |
| Name | Type | Description | Required | Default | Notes |
| -------------------- | ------ | ----------------- | -------- | ---------- | ---------------------------- |
| YAMTRACK_DB_HOST | String | Database host | No | None | When not set, sqlite is used |
| YAMTRACK_DB_PORT | Int | Database port | No | 5432 | |
| YAMTRACK_DB_NAME | String | Database name | No | "yamtrack" | |
| YAMTRACK_DB_USER | String | Database user | No | "yamtrack" | |
| YAMTRACK_DB_PASSWORD | String | Database password | No | "yamtrack" | |
## Local development
@@ -86,4 +84,4 @@ python src/manage.py migrate
python src/manage.py runserver
```
Go to: http://localhost:8000
Go to: http://localhost:8000

View File

@@ -8,6 +8,6 @@ from django.http import HttpRequest
def export_vars(request: HttpRequest) -> dict: # noqa: ARG001
"""Export variables to templates."""
return {
"REGISTRATION": config("REGISTRATION", default=True, cast=bool),
"REGISTRATION": config("YAMTRACK_REGISTRATION", default=True, cast=bool),
"IMG_NONE": settings.IMG_NONE,
}

View File

@@ -2,8 +2,8 @@ import requests
from decouple import config
from django.conf import settings
TMDB_API = config("TMDB_API", default=None)
MAL_API = config("MAL_API", default=None)
TMDB_API = config("YAMTRACK_TMDB_API", default=None)
MAL_API = config("YAMTRACK_MAL_API", default=None)
def get_media_metadata(media_type: str, media_id: str) -> dict:

View File

@@ -6,8 +6,8 @@ from django.conf import settings
logger = logging.getLogger(__name__)
TMDB_API = config("TMDB_API", default=None)
MAL_API = config("MAL_API", default=None)
TMDB_API = config("YAMTRACK_TMDB_API", default=None)
MAL_API = config("YAMTRACK_MAL_API", default=None)
def tmdb(media_type: str, query: str) -> list:

View File

@@ -20,25 +20,22 @@ BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/
# See https://docs.djangoproject.com/en/stable/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = config("SECRET", default="secret")
SECRET_KEY = config("YAMTRACK_SECRET", default="secret")
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = config("DEBUG", default=False, cast=bool)
DEBUG = config("YAMTRACK_DEBUG", default=False, cast=bool)
INTERNAL_IPS = ["127.0.0.1"]
ALLOWED_HOSTS = config("ALLOWED_HOSTS", default="*", cast=Csv())
ALLOWED_HOSTS = config("YAMTRACK_ALLOWED_HOSTS", default="*", cast=Csv())
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
# Global default, can be overwritten at CustomLoginView
SESSION_EXPIRE_AT_BROWSER_CLOSE = True
if config("HTTPS_COOKIES", default=False, cast=bool):
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
# Application definition
INSTALLED_APPS = [
@@ -111,15 +108,15 @@ requests_cache.install_cache(
) # 6 hours
if config("DB_HOST", default=None):
if config("YAMTRACK_DB_HOST", default=None):
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"HOST": config("DB_HOST"),
"NAME": config("DB_NAME", default="yamtrack"),
"USER": config("DB_USER", default="yamtrack"),
"PASSWORD": config("DB_PASSWORD", default="yamtrack"),
"PORT": config("DB_PORT", default="5432"),
"HOST": config("YAMTRACK_DB_HOST"),
"NAME": config("YAMTRACK_DB_NAME", default="yamtrack"),
"USER": config("YAMTRACK_DB_USER", default="yamtrack"),
"PASSWORD": config("YAMTRACK_DB_PASSWORD", default="yamtrack"),
"PORT": config("YAMTRACK_DB_PORT", default="5432"),
},
}
else:

View File

@@ -8,7 +8,7 @@ from decouple import config
from django.conf import settings
from users.models import User
MAL_API = config("MAL_API", default="")
MAL_API = config("YAMTRACK_MAL_API", default="")
logger = logging.getLogger(__name__)

View File

@@ -1,6 +1,5 @@
from __future__ import annotations
import asyncio
import datetime
import logging
from csv import DictReader
@@ -16,7 +15,7 @@ if TYPE_CHECKING:
from users.models import User
TMDB_API = config("TMDB_API", default="")
TMDB_API = config("YAMTRACK_TMDB_API", default="")
logger = logging.getLogger(__name__)

View File

@@ -10,5 +10,5 @@ urlpatterns = [
path("logout", auth_views.LogoutView.as_view(), name="logout"),
]
if config("REGISTRATION", default=True, cast=bool):
if config("YAMTRACK_REGISTRATION", default=True, cast=bool):
urlpatterns.append(path("register/", views.register, name="register"))