Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement - Move Redis URL Configuration from config.toml to an Environment Variable #921

Merged
merged 9 commits into from
Nov 22, 2023
2 changes: 0 additions & 2 deletions agenta-backend/agenta_backend/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@
os.environ["DOCKER_HUB_URL"] = toml_config["docker_hub_url"]
os.environ["DOCKER_HUB_REPO_OWNER"] = toml_config["docker_hub_repo_owner"]
os.environ["DOCKER_HUB_REPO_NAME"] = toml_config["docker_hub_repo_name"]
os.environ["REDIS_URL"] = toml_config["redis_url"]
os.environ["DATABASE_MODE"] = os.environ.get("DATABASE_MODE", "v2")


class Settings(BaseSettings):
docker_registry_url: str
registry: str
redis_url: str
database_url: str
docker_hub_url: str
docker_hub_repo_owner: str
Expand Down
1 change: 0 additions & 1 deletion agenta-backend/agenta_backend/config.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
docker_registry_url="registry:5001"
registry="agentaai"
database_url="sqlite:////db/deploy.db"
redis_url="redis://redis:6379/0"
docker_hub_url="https://hub.docker.com/v2/repositories/{}/{}"
docker_hub_repo_owner="agentaai"
docker_hub_repo_name="templates_v2"
2 changes: 1 addition & 1 deletion agenta-backend/agenta_backend/services/app_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
deployment_manager,
) # noqa pylint: disable-all
else:
from agenta_backend.services import deployment_manage
from agenta_backend.services import deployment_manager

if os.environ["FEATURE_FLAG"] in ["cloud", "ee"]:
from agenta_backend.cloud.services import (
Expand Down
19 changes: 13 additions & 6 deletions agenta-backend/agenta_backend/utils/redis_utils.py
aybruhm marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import os
import redis
from agenta_backend.config import settings
from redis.exceptions import ConnectionError


def redis_connection() -> redis.Redis:
"""Returns a Redis client object connected to a Redis server specified
by the `redis_url` setting.
"""Returns a client object for connecting to a Redis service specified \
by the REDIS_URL environment variable.

Returns:
A Redis client object.
:return: a Redis client object.
"""

redis_client = redis.from_url(url=settings.redis_url)
try:
redis_client = redis.from_url(url=os.environ.get("REDIS_URL", None))
except ConnectionRefusedError:
raise ConnectionRefusedError(
"Refuse connecting to redis service. Kindly check redis url."
)
except ConnectionError:
raise ConnectionError("Could not connect to redis service.")
return redis_client
1 change: 1 addition & 0 deletions docker-compose.gh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ services:
image: ghcr.io/agenta-ai/agenta-backend
environment:
- MONGODB_URI=mongodb://username:password@mongo:27017
- REDIS_URL=redis://redis:6379/0
- ENVIRONMENT=development
- BARE_DOMAIN_NAME=${BARE_DOMAIN_NAME:-localhost}
- DOMAIN_NAME=${DOMAIN_NAME:-http://localhost}
Expand Down
1 change: 1 addition & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ services:
build: ./agenta-backend
environment:
- MONGODB_URI=mongodb://username:password@mongo:27017
- REDIS_URL=redis://redis:6379/0
- ALLOW_ORIGINS=${ALLOW_ORIGINS}
- ENVIRONMENT=production
- FEATURE_FLAG=oss
Expand Down
1 change: 1 addition & 0 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ services:
container_name: agenta-backend-test
environment:
- MONGODB_URI=mongodb://username:password@mongo:27017/
- REDIS_URL=redis://redis:6379/0
- ENVIRONMENT=development
- DATABASE_MODE=test
- FEATURE_FLAG=oss
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ services:
build: ./agenta-backend
environment:
- MONGODB_URI=mongodb://username:password@mongo:27017
- REDIS_URL=redis://redis:6379/0
- ENVIRONMENT=development
- DATABASE_MODE=v2
- BARE_DOMAIN_NAME=localhost
Expand Down
Loading