From 31deb36c853536c4ddd9537304d63476ff534fb5 Mon Sep 17 00:00:00 2001 From: bcj Date: Sun, 23 May 2021 23:49:12 -0500 Subject: [PATCH] URL-Encode password in broker_url Needed to prevent connection errors if the password contains non-urlsafe characters. Dockerfile change because all the services using it are mirroring ./ in /app now anyway. Flower needs because it needs bookwyrm in order to read the celerywyrm config (because flower only allows overwriting broker_url from the command line and we want to do it in Python so we have access to a urlencode function). --- .env.dev.example | 4 +--- .env.prod.example | 2 -- Dockerfile | 2 -- bookwyrm/settings.py | 8 ++++++-- celerywyrm/settings.py | 4 ++-- docker-compose.yml | 6 +++--- 6 files changed, 12 insertions(+), 14 deletions(-) diff --git a/.env.dev.example b/.env.dev.example index 2f24378c6..03e6ef258 100644 --- a/.env.dev.example +++ b/.env.dev.example @@ -34,10 +34,8 @@ REDIS_ACTIVITY_PORT=6379 #REDIS_ACTIVITY_PASSWORD=redispassword345 # Redis as celery broker -#REDIS_BROKER_PORT=6379 +REDIS_BROKER_PORT=6379 #REDIS_BROKER_PASSWORD=redispassword123 -CELERY_BROKER=redis://redis_broker:6379/0 -CELERY_RESULT_BACKEND=redis://redis_broker:6379/0 FLOWER_PORT=8888 #FLOWER_USER=mouse diff --git a/.env.prod.example b/.env.prod.example index a82499a32..dd15fbb79 100644 --- a/.env.prod.example +++ b/.env.prod.example @@ -36,8 +36,6 @@ REDIS_ACTIVITY_PASSWORD=redispassword345 # Redis as celery broker REDIS_BROKER_PORT=6379 REDIS_BROKER_PASSWORD=redispassword123 -CELERY_BROKER=redis://:${REDIS_BROKER_PASSWORD}@redis_broker:${REDIS_BROKER_PORT}/0 -CELERY_RESULT_BACKEND=redis://:${REDIS_BROKER_PASSWORD}@redis_broker:${REDIS_BROKER_PORT}/0 FLOWER_PORT=8888 FLOWER_USER=mouse diff --git a/Dockerfile b/Dockerfile index 0f10015c6..1892ae234 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,5 +9,3 @@ WORKDIR /app COPY requirements.txt /app/ RUN pip install -r requirements.txt --no-cache-dir RUN apt-get update && apt-get install -y gettext libgettextpo-dev && apt-get clean - -COPY ./bookwyrm ./celerywyrm /app/ diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index d694e33fd..19d84c7f1 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -14,8 +14,12 @@ PAGE_LENGTH = env("PAGE_LENGTH", 15) DEFAULT_LANGUAGE = env("DEFAULT_LANGUAGE", "English") # celery -CELERY_BROKER = env("CELERY_BROKER") -CELERY_RESULT_BACKEND = env("CELERY_RESULT_BACKEND") +CELERY_BROKER = "redis://:{}@redis_broker:{}/0".format( + requests.utils.quote(env("REDIS_BROKER_PASSWORD", "")), env("REDIS_BROKER_PORT") +) +CELERY_RESULT_BACKEND = "redis://:{}@redis_broker:{}/0".format( + requests.utils.quote(env("REDIS_BROKER_PASSWORD", "")), env("REDIS_BROKER_PORT") +) CELERY_ACCEPT_CONTENT = ["application/json"] CELERY_TASK_SERIALIZER = "json" CELERY_RESULT_SERIALIZER = "json" diff --git a/celerywyrm/settings.py b/celerywyrm/settings.py index e4fa73ca2..63a6e9409 100644 --- a/celerywyrm/settings.py +++ b/celerywyrm/settings.py @@ -1,10 +1,10 @@ """ bookwyrm settings and configuration """ from bookwyrm.settings import * -CELERY_BROKER_URL = env("CELERY_BROKER") +CELERY_BROKER_URL = CELERY_BROKER CELERY_ACCEPT_CONTENT = ["json"] CELERY_TASK_SERIALIZER = "json" -CELERY_RESULT_BACKEND = "redis" +FLOWER_PORT = env("FLOWER_PORT") INSTALLED_APPS = INSTALLED_APPS + [ "celerywyrm", diff --git a/docker-compose.yml b/docker-compose.yml index 18f836502..49d02e706 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -74,10 +74,10 @@ services: restart: on-failure flower: build: . - command: flower --port=${FLOWER_PORT} + command: flower -A celerywyrm env_file: .env - environment: - - CELERY_BROKER_URL=${CELERY_BROKER} + volumes: + - .:/app networks: - main depends_on: