Use redis with password in dev

This commit is contained in:
Mouse Reeve 2022-01-05 08:27:39 -08:00
parent 629140cad4
commit bebb2c167e
5 changed files with 28 additions and 14 deletions

View file

@ -26,15 +26,15 @@ POSTGRES_HOST=db
MAX_STREAM_LENGTH=200 MAX_STREAM_LENGTH=200
REDIS_ACTIVITY_HOST=redis_activity REDIS_ACTIVITY_HOST=redis_activity
REDIS_ACTIVITY_PORT=6379 REDIS_ACTIVITY_PORT=6379
#REDIS_ACTIVITY_PASSWORD=redispassword345 REDIS_ACTIVITY_PASSWORD=redispassword345
# Redis as celery broker # Redis as celery broker
REDIS_BROKER_PORT=6379 REDIS_BROKER_PORT=6379
#REDIS_BROKER_PASSWORD=redispassword123 REDIS_BROKER_PASSWORD=redispassword123
FLOWER_PORT=8888 FLOWER_PORT=8888
#FLOWER_USER=mouse FLOWER_USER=mouse
#FLOWER_PASSWORD=changeme FLOWER_PASSWORD=changeme
EMAIL_HOST=smtp.mailgun.org EMAIL_HOST=smtp.mailgun.org
EMAIL_PORT=587 EMAIL_PORT=587

View file

@ -5,10 +5,12 @@ import redis
from bookwyrm import settings from bookwyrm import settings
r = redis.Redis( r = redis.Redis(
host=settings.REDIS_ACTIVITY_HOST, port=settings.REDIS_ACTIVITY_PORT, db=0 host=settings.REDIS_ACTIVITY_HOST,
port=settings.REDIS_ACTIVITY_PORT,
password=settings.REDIS_ACTIVITY_PASSWORD,
db=0,
) )
class RedisStore(ABC): class RedisStore(ABC):
"""sets of ranked, related objects, like statuses for a user's feed""" """sets of ranked, related objects, like statuses for a user's feed"""

View file

@ -3,12 +3,13 @@
# pylint: disable=unused-wildcard-import # pylint: disable=unused-wildcard-import
from bookwyrm.settings import * from bookwyrm.settings import *
CELERY_BROKER_URL = "redis://:{}@redis_broker:{}/0".format( REDIS_BROKER_PASSWORD = requests.utils.quote(env("REDIS_BROKER_PASSWORD", None))
requests.utils.quote(env("REDIS_BROKER_PASSWORD", "")), env("REDIS_BROKER_PORT") REDIS_BROKER_HOST = env("REDIS_BROKER_HOST", "redis_broker")
) REDIS_BROKER_PORT = env("REDIS_BROKER_PORT", 6379)
CELERY_RESULT_BACKEND = "redis://:{}@redis_broker:{}/0".format(
requests.utils.quote(env("REDIS_BROKER_PASSWORD", "")), env("REDIS_BROKER_PORT") # pylint: disable=line-too-long
) CELERY_BROKER_URL = f"redis://:{REDIS_BROKER_PASSWORD}@{REDIS_BROKER_HOST}:{REDIS_BROKER_PORT}/0"
CELERY_RESULT_BACKEND = f"redis://:{REDIS_BROKER_PASSWORD}@{REDIS_BROKER_HOST}:{REDIS_BROKER_PORT}/0"
CELERY_DEFAULT_QUEUE = "low_priority" CELERY_DEFAULT_QUEUE = "low_priority"

View file

@ -38,16 +38,17 @@ services:
- 8000:8000 - 8000:8000
redis_activity: redis_activity:
image: redis image: redis
command: ["redis-server", "--appendonly", "yes"] command: redis-server --requirepass ${REDIS_ACTIVITY_PASSWORD} --appendonly yes --port ${REDIS_ACTIVITY_PORT}
env_file: .env env_file: .env
networks: networks:
- main - main
restart: on-failure restart: on-failure
volumes: volumes:
- ./redis.conf:/etc/redis/redis.conf
- redis_activity_data:/data - redis_activity_data:/data
redis_broker: redis_broker:
image: redis image: redis
command: ["redis-server", "--appendonly", "yes"] command: redis-server --requirepass ${REDIS_BROKER_PASSWORD} --appendonly yes --port ${REDIS_BROKER_PORT}
env_file: .env env_file: .env
ports: ports:
- 6379:6379 - 6379:6379
@ -55,6 +56,7 @@ services:
- main - main
restart: on-failure restart: on-failure
volumes: volumes:
- ./redis.conf:/etc/redis/redis.conf
- redis_broker_data:/data - redis_broker_data:/data
celery_worker: celery_worker:
env_file: .env env_file: .env

9
redis.conf Normal file
View file

@ -0,0 +1,9 @@
bind 127.0.0.1 ::1
protected-mode yes
port 6379
rename-command FLUSHDB ""
rename-command FLUSHALL ""
rename-command DEBUG ""
rename-command CONFIG ""
rename-command SHUTDOWN ""