mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-03-30 04:31:49 +02:00
add migration dockerfile
This commit is contained in:
parent
457e7992a4
commit
d744a78e45
32
backend/Dockerfile.migrations
Normal file
32
backend/Dockerfile.migrations
Normal 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"]
|
@ -13,7 +13,7 @@ from danswer.configs.app_configs import MULTI_TENANT
|
|||||||
from danswer.db.engine import build_connection_string
|
from danswer.db.engine import build_connection_string
|
||||||
from danswer.db.models import Base
|
from danswer.db.models import Base
|
||||||
from celery.backends.database.session import ResultModelBase # type: ignore
|
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
|
# Alembic Config object
|
||||||
config = context.config
|
config = context.config
|
||||||
|
@ -38,6 +38,7 @@ from danswer.configs.app_configs import POSTGRES_USER
|
|||||||
from danswer.configs.app_configs import SECRET_JWT_KEY
|
from danswer.configs.app_configs import SECRET_JWT_KEY
|
||||||
from danswer.configs.constants import POSTGRES_DEFAULT_SCHEMA
|
from danswer.configs.constants import POSTGRES_DEFAULT_SCHEMA
|
||||||
from danswer.configs.constants import POSTGRES_UNKNOWN_APP_NAME
|
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 danswer.utils.logger import setup_logger
|
||||||
from shared_configs.configs import current_tenant_id
|
from shared_configs.configs import current_tenant_id
|
||||||
|
|
||||||
@ -188,6 +189,29 @@ class SqlEngine:
|
|||||||
return cls._app_name
|
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(
|
def build_connection_string(
|
||||||
*,
|
*,
|
||||||
db_api: str = ASYNC_DB_API,
|
db_api: str = ASYNC_DB_API,
|
||||||
|
@ -2,7 +2,8 @@ apiVersion: v1
|
|||||||
kind: ConfigMap
|
kind: ConfigMap
|
||||||
metadata:
|
metadata:
|
||||||
name: env-configmap
|
name: env-configmap
|
||||||
data:
|
data:
|
||||||
|
|
||||||
# Auth Setting, also check the secrets file
|
# Auth Setting, also check the secrets file
|
||||||
AUTH_TYPE: "disabled" # Change this for production uses unless Danswer is only accessible behind VPN
|
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
|
ENCRYPTION_KEY_SECRET: "" # This should not be specified directly in the yaml, this is just for reference
|
||||||
|
Loading…
x
Reference in New Issue
Block a user