separate redis from src

This commit is contained in:
FuzzyGrim
2024-03-04 18:56:30 +01:00
parent ab64598a98
commit 67dc4a8af1
10 changed files with 39 additions and 31 deletions

View File

@@ -5,5 +5,3 @@ __pycache__
venv
src/staticfiles
src/db/db.sqlite3
src/db/redis.db
src/db/redis.db.settings

2
.gitignore vendored
View File

@@ -5,5 +5,3 @@ __pycache__
venv
src/staticfiles
src/db/db.sqlite3
src/db/redis.db
src/db/redis.db.settings

View File

@@ -6,9 +6,9 @@ ENV PYTHONUNBUFFERED=1
COPY ./requirements.txt /requirements.txt
RUN apt-get update \
&& apt-get install -y --no-install-recommends g++ build-essential gosu \
&& apt-get install -y --no-install-recommends g++ gosu \
&& pip install --no-cache-dir -r /requirements.txt \
&& apt-get -y autoremove --purge g++ build-essential \
&& apt-get -y autoremove --purge g++ \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*

View File

@@ -38,6 +38,7 @@ Alternatively, if you need a PostgreSQL database, you can use the `docker-compos
| --------------- | ------ | ----------------------------- | ----------- | -------- | --------------------------------------------------------------------------------------------------- |
| 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 |
| REDIS_URL | String | Redis URL | Recommended | None | Required if using Redis |
| SECRET | String | Django secret key | Recommended | "secret" | [SECRET_KEY](https://docs.djangoproject.com/en/stable/ref/settings/#secret-key) |
| ALLOWED_HOSTS | List | Base IP / Domain | No | "\*" | [ALLOWED_HOSTS](https://docs.djangoproject.com/en/stable/ref/settings/#allowed-hosts) |
| REGISTRATION | Bool | User registration | No | True | |

View File

@@ -6,9 +6,11 @@ services:
restart: unless-stopped
depends_on:
- db
- redis
environment:
- TMDB_API=TMDB_API_KEY
- MAL_API=MAL_API_KEY
- REDIS_URL=redis://redis:6379
- DB_HOST=db
- DB_NAME=yamtrack
- DB_USER=yamtrack
@@ -24,8 +26,17 @@ services:
- POSTGRES_DB=yamtrack
- POSTGRES_USER=yamtrack
- POSTGRES_PASSWORD=yamtrack
- TZ=Europe/Madrid
- PGTZ=Europe/Madrid
volumes:
- ./db:/var/lib/postgresql/data
restart: unless-stopped
redis:
container_name: yamtrack-redis
image: redis:7-alpine
restart: unless-stopped
volumes:
- redis_data:/data
volumes:
redis_data:

View File

@@ -4,10 +4,23 @@ services:
container_name: yamtrack
image: ghcr.io/fuzzygrim/yamtrack
restart: unless-stopped
depends_on:
- redis
environment:
- TMDB_API=TMDB_API_KEY
- MAL_API=MAL_API_KEY
- REDIS_URL=redis://redis:6379
volumes:
- ./db:/yamtrack/db
ports:
- "8000:8000"
redis:
container_name: yamtrack-redis
image: redis:7-alpine
restart: unless-stopped
volumes:
- redis_data:/data
volumes:
redis_data:

View File

@@ -11,7 +11,7 @@ Pillow==10.2.0
psycopg-binary==3.1.18
python-decouple==3.8
pytz==2024.1
redislite==6.2.912183
redis[hiredis]==5.0.2
requests==2.31.0
unidecode==1.3.8
whitenoise[brotli]==6.6.0

View File

@@ -1,13 +1,11 @@
"""Django settings for Yamtrack project."""
import atexit
import warnings
from pathlib import Path
import pytz
from decouple import Csv, config
from django.core.cache import CacheKeyWarning
from redislite import Redis
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
@@ -114,22 +112,19 @@ else:
# Cache
# https://docs.djangoproject.com/en/stable/topics/cache/
RDB = Redis(BASE_DIR / "db" / "redis.db")
CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.redis.RedisCache",
"LOCATION": f"unix://{RDB.socket_file}",
"TIMEOUT": 21600,
},
}
# use redis if available, otherwise use django default which is local memory
if config("REDIS_URL", default=None):
CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.redis.RedisCache",
"LOCATION": config("REDIS_URL"),
},
}
# not using Memcached, ignore CacheKeyWarning
# https://docs.djangoproject.com/en/stable/topics/cache/#cache-key-warnings
warnings.simplefilter("ignore", CacheKeyWarning)
# cleanly shutdown the Redis server when the app is closed
atexit.register(RDB.shutdown)
# Session
# https://docs.djangoproject.com/en/stable/topics/http/sessions/

View File

@@ -1,7 +0,0 @@
from .settings import * # noqa: F403
CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",
},
}

View File

@@ -6,8 +6,7 @@ import sys
def main():
"""Run administrative tasks."""
settings = "config.test_settings" if "test" in sys.argv else "config.settings"
os.environ.setdefault("DJANGO_SETTINGS_MODULE", settings)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc: