add migration dockerfile

This commit is contained in:
pablodanswer 2024-10-18 13:02:29 -07:00
parent 457e7992a4
commit d744a78e45
4 changed files with 59 additions and 2 deletions

View File

@ -0,0 +1,32 @@
FROM python:3.11.7-slim-bookworm
# Set environment variables and labels as needed
ENV DANSWER_RUNNING_IN_DOCKER="true"
# Install system dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends \
libpq-dev \
gcc && \
rm -rf /var/lib/apt/lists/*
# Install Python dependencies
COPY ./requirements/default.txt /tmp/requirements.txt
COPY ./requirements/ee.txt /tmp/ee-requirements.txt
RUN pip install --no-cache-dir -r /tmp/requirements.txt -r /tmp/ee-requirements.txt
# Copy Alembic and application files
WORKDIR /app
COPY ./danswer /app/danswer
COPY ./alembic /app/alembic
COPY ./alembic_tenants /app/alembic_tenants
COPY ./alembic.ini /app/alembic.ini
COPY ./danswer/configs /app/danswer/configs
COPY ./danswer/utils /app/danswer/utils
COPY shared_configs /app/shared_configs
# Set PYTHONPATH
ENV PYTHONPATH=/app
# The entrypoint for the migration job
ENTRYPOINT ["alembic"]

View File

@ -13,7 +13,7 @@ from danswer.configs.app_configs import MULTI_TENANT
from danswer.db.engine import build_connection_string
from danswer.db.models import Base
from celery.backends.database.session import ResultModelBase # type: ignore
from danswer.background.celery.celery_app import get_all_tenant_ids
from danswer.db.engine import get_all_tenant_ids
# Alembic Config object
config = context.config

View File

@ -38,6 +38,7 @@ from danswer.configs.app_configs import POSTGRES_USER
from danswer.configs.app_configs import SECRET_JWT_KEY
from danswer.configs.constants import POSTGRES_DEFAULT_SCHEMA
from danswer.configs.constants import POSTGRES_UNKNOWN_APP_NAME
from danswer.configs.constants import TENANT_ID_PREFIX
from danswer.utils.logger import setup_logger
from shared_configs.configs import current_tenant_id
@ -188,6 +189,29 @@ class SqlEngine:
return cls._app_name
def get_all_tenant_ids() -> list[str] | list[None]:
if not MULTI_TENANT:
return [None]
with get_session_with_tenant(tenant_id="public") as session:
result = session.execute(
text(
"""
SELECT schema_name
FROM information_schema.schemata
WHERE schema_name NOT IN ('pg_catalog', 'information_schema', 'public')"""
)
)
tenant_ids = [row[0] for row in result]
valid_tenants = [
tenant
for tenant in tenant_ids
if tenant is None or tenant.startswith(TENANT_ID_PREFIX)
]
return valid_tenants
def build_connection_string(
*,
db_api: str = ASYNC_DB_API,

View File

@ -2,7 +2,8 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: env-configmap
data:
data:
# Auth Setting, also check the secrets file
AUTH_TYPE: "disabled" # Change this for production uses unless Danswer is only accessible behind VPN
ENCRYPTION_KEY_SECRET: "" # This should not be specified directly in the yaml, this is just for reference