diff --git a/dev/.env.docker-compose b/dev/.env.docker-compose index 3e0b1d1c..f9dc8107 100644 --- a/dev/.env.docker-compose +++ b/dev/.env.docker-compose @@ -7,5 +7,6 @@ DJANGO_MINIO_STORAGE_SECRET_KEY=minioSecretKey DJANGO_STORAGE_BUCKET_NAME=django-storage DJANGO_MINIO_STORAGE_MEDIA_URL=http://localhost:9000/django-storage DJANGO_ISIC_ELASTICSEARCH_URI=http://elastic:elastic@elasticsearch:9200 +DJANGO_ISIC_REDIS_URL=redis://localhost:6379 DJANGO_ISIC_DATACITE_USERNAME="fakeuser" DJANGO_ISIC_DATACITE_PASSWORD="fakepassword" diff --git a/dev/.env.docker-compose-native b/dev/.env.docker-compose-native index 6909a701..d1546580 100644 --- a/dev/.env.docker-compose-native +++ b/dev/.env.docker-compose-native @@ -6,5 +6,6 @@ DJANGO_MINIO_STORAGE_ACCESS_KEY=minioAccessKey DJANGO_MINIO_STORAGE_SECRET_KEY=minioSecretKey DJANGO_STORAGE_BUCKET_NAME=django-storage DJANGO_ISIC_ELASTICSEARCH_URI=http://elastic:elastic@localhost:9200 +DJANGO_ISIC_REDIS_URL=redis://localhost:6379 DJANGO_ISIC_DATACITE_USERNAME="fakeuser" DJANGO_ISIC_DATACITE_PASSWORD="fakepassword" diff --git a/docker-compose.yml b/docker-compose.yml index 005109fd..88eef066 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -44,3 +44,14 @@ services: ZS_LISTFILE_BASIC_AUTH: "insecurezipdownloadauthtoken" ports: - 4008:4008 + + redis: + image: redis:latest + ports: + - ${DOCKER_REDIS_PORT-6379}:6379 + + + redisinsight: + image: redis/redisinsight:latest + ports: + - ${DOCKER_REDIS_INSIGHT_PORT-5540}:5540 diff --git a/isic/settings.py b/isic/settings.py index d9040870..d5242ae6 100644 --- a/isic/settings.py +++ b/isic/settings.py @@ -10,6 +10,7 @@ TestingBaseConfiguration, ) from configurations import values +from django_cache_url import BACKENDS def _oauth2_pkce_required(client_id): @@ -22,6 +23,19 @@ def _oauth2_pkce_required(client_id): return oauth_application.client_type != OAuth2Application.CLIENT_CONFIDENTIAL +# This is an unfortunate monkeypatching of django_cache_url to support an old version +# of django-redis on a newer version of django. +# See https://github.com/noripyt/django-cachalot/issues/222 for fixing this. +BACKENDS["redis"] = BACKENDS["rediss"] = "django_redis.cache.RedisCache" + + +class CacheURLValue(values.DictBackendMixin, values.CastingMixin, values.Value): + caster = "django_cache_url.parse" + message = "Cannot interpret cache URL value {0!r}" + environ_name = "CACHE_URL" + late_binding = True + + class IsicMixin(ConfigMixin): WSGI_APPLICATION = "isic.wsgi.application" ROOT_URLCONF = "isic.urls" @@ -122,6 +136,8 @@ def mutate_configuration(configuration: ComposedConfiguration) -> None: ISIC_SANDBOX_BANNER = values.BooleanValue(False) ISIC_PLACEHOLDER_IMAGES = values.BooleanValue(False) + CACHES = CacheURLValue(environ_name="ISIC_REDIS_URL", environ_prefix="DJANGO_") + ISIC_ELASTICSEARCH_URI = values.SecretValue() ISIC_ELASTICSEARCH_INDEX = "isic" ISIC_GUI_URL = "https://www.isic-archive.com/" @@ -243,11 +259,17 @@ def mutate_configuration(configuration: ComposedConfiguration): # use md5 in testing for quicker user creation configuration.PASSWORD_HASHERS.insert(0, "django.contrib.auth.hashers.MD5PasswordHasher") + configuration.CACHES = { + "default": {"BACKEND": "django.core.cache.backends.dummy.DummyCache"}, + } + class HerokuProductionConfiguration(IsicMixin, HerokuProductionBaseConfiguration): ISIC_DATACITE_DOI_PREFIX = "10.34970" ISIC_ELASTICSEARCH_URI = values.SecretValue(environ_name="SEARCHBOX_URL", environ_prefix=None) + CACHES = CacheURLValue(environ_name="STACKHERO_REDIS_URL_TLS", environ_prefix=None) + AWS_CLOUDFRONT_KEY = values.SecretValue() AWS_CLOUDFRONT_KEY_ID = values.Value() AWS_S3_CUSTOM_DOMAIN = values.Value() diff --git a/setup.py b/setup.py index a3c80a60..6313be7a 100644 --- a/setup.py +++ b/setup.py @@ -72,6 +72,9 @@ "pydantic", "pymongo", "pyparsing", + "redis", + "hiredis", + "django-redis", "python-magic", "requests", "sentry-sdk[pure_eval]", diff --git a/tox.ini b/tox.ini index b44c823a..a3a0f2d0 100644 --- a/tox.ini +++ b/tox.ini @@ -64,6 +64,7 @@ passenv = DJANGO_MINIO_STORAGE_ENDPOINT DJANGO_MINIO_STORAGE_SECRET_KEY DJANGO_ISIC_ELASTICSEARCH_URI + DJANGO_ISIC_REDIS_URL extras = dev deps = @@ -91,6 +92,7 @@ passenv = DJANGO_MINIO_STORAGE_ENDPOINT DJANGO_MINIO_STORAGE_SECRET_KEY DJANGO_ISIC_ELASTICSEARCH_URI + DJANGO_ISIC_REDIS_URL extras = dev install_command = pip install --find-links https://girder.github.io/large_image_wheels {opts} {packages}