Skip to content

fix: read Redis URL from environment variables for Docker deployment (fixes #385)#469

Open
octo-patch wants to merge 1 commit intoFosowl:mainfrom
octo-patch:fix/issue-385-redis-url-env-var
Open

fix: read Redis URL from environment variables for Docker deployment (fixes #385)#469
octo-patch wants to merge 1 commit intoFosowl:mainfrom
octo-patch:fix/issue-385-redis-url-env-var

Conversation

@octo-patch
Copy link
Copy Markdown
Contributor

Fixes #385

Problem

The Celery broker and backend URLs were hardcoded to redis://localhost:6379/0 in api.py:

celery_app = Celery("tasks", broker="redis://localhost:6379/0", backend="redis://localhost:6379/0")

When running in Docker, the Redis service is reachable at redis://redis:6379/0 (via the Docker network using the service name), not localhost. The docker-compose.yml already correctly passes REDIS_URL=${REDIS_BASE_URL:-redis://redis:6379/0} as an environment variable to the backend container, but the code was ignoring it entirely.

This causes the backend container to silently fail to connect to Redis during startup, resulting in the symptom reported in #385: the container shows Device set to use cpu and then never reaches the Uvicorn startup logs.

Solution

Read the Redis URL from environment variables before falling back to localhost:

  1. REDIS_URL — set by docker-compose.yml for Docker deployments
  2. REDIS_BASE_URL — the user-facing variable name documented in .env.example
  3. redis://localhost:6379/0 — fallback for local (non-Docker) development
_redis_url = os.environ.get("REDIS_URL", os.environ.get("REDIS_BASE_URL", "redis://localhost:6379/0"))
celery_app = Celery("tasks", broker=_redis_url, backend=_redis_url)

Testing

  • Local development: no change in behaviour (falls back to localhost)
  • Docker deployment: REDIS_URL=redis://redis:6379/0 is picked up from the environment, matching the existing docker-compose.yml configuration

…ixes Fosowl#385)

Celery broker and backend URLs were hardcoded to redis://localhost:6379/0,
which prevents connection to the Redis container in Docker deployments.
The docker-compose.yml already passes REDIS_URL=${REDIS_BASE_URL:-redis://redis:6379/0}
to the backend container, but the code was ignoring it.

Now reads REDIS_URL first (set by docker-compose), falls back to REDIS_BASE_URL
(user-facing env var name in .env.example), then falls back to localhost for
non-Docker development use.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Backend container starts but doesn't complete startup - no Uvicorn server logs

1 participant