build(docker): add API and ingestion worker stack
Add container builds and Compose services for PostgreSQL/pgvector, migrations, API, and a separate worker with persistent storage.
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
# Git
|
||||
.git/
|
||||
.gitignore
|
||||
.gitattributes
|
||||
|
||||
# Python cache & virtual environments
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
.venv/
|
||||
venv/
|
||||
env/
|
||||
.pytest_cache/
|
||||
rag_technical_docs_assistant.egg-info/
|
||||
build/
|
||||
dist/
|
||||
|
||||
# IDE & agent metadata
|
||||
.vscode/
|
||||
.idea/
|
||||
.agents/
|
||||
|
||||
# Testing and temp files
|
||||
tests/
|
||||
.coverage
|
||||
htmlcov/
|
||||
*.log
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
FROM python:3.11-slim
|
||||
|
||||
# Set environment variables for Python
|
||||
ENV PYTHONUNBUFFERED=1 \
|
||||
PYTHONDONTWRITEBYTECODE=1 \
|
||||
PIP_NO_CACHE_DIR=1 \
|
||||
PIP_DISABLE_PIP_VERSION_CHECK=1
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Install system dependencies
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
curl \
|
||||
build-essential \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Copy dependency configuration
|
||||
COPY pyproject.toml /app/
|
||||
|
||||
# Stub package to leverage Docker layer caching for pip dependencies
|
||||
RUN mkdir -p /app/app && touch /app/app/__init__.py \
|
||||
&& pip install --no-cache-dir -e ".[prototype,embedding]"
|
||||
|
||||
# Copy application source code and migrations
|
||||
COPY app/ /app/app/
|
||||
COPY migrations/ /app/migrations/
|
||||
COPY alembic.ini /app/
|
||||
COPY data/ /app/data/
|
||||
|
||||
# Reinstall editable package to ensure all entry points and modules are bound
|
||||
RUN pip install --no-deps -e .
|
||||
|
||||
# Expose default API port
|
||||
EXPOSE 8000
|
||||
|
||||
# Default command: FastAPI API server
|
||||
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
|
||||
@@ -0,0 +1,90 @@
|
||||
services:
|
||||
db:
|
||||
image: pgvector/pgvector:pg16
|
||||
container_name: rag-postgres
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
POSTGRES_DB: ${POSTGRES_DB:-rag}
|
||||
POSTGRES_USER: ${POSTGRES_USER:-rag}
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-rag_password}
|
||||
ports:
|
||||
- "${POSTGRES_PORT:-5432}:5432"
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-rag} -d ${POSTGRES_DB:-rag}"]
|
||||
interval: 5s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
start_period: 5s
|
||||
|
||||
migrations:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
container_name: rag-migrations
|
||||
restart: "no"
|
||||
command: alembic upgrade head
|
||||
env_file:
|
||||
- .env
|
||||
environment:
|
||||
- INGEST_DATABASE_URL=postgresql+psycopg://${POSTGRES_USER:-rag}:${POSTGRES_PASSWORD:-rag_password}@db:5432/${POSTGRES_DB:-rag}
|
||||
- INGEST_EMBEDDING_ENDPOINT=${INGEST_EMBEDDING_ENDPOINT:-http://host.docker.internal:11434/v1}
|
||||
extra_hosts:
|
||||
- "host.docker.internal:host-gateway"
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
|
||||
api:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
container_name: rag-api
|
||||
restart: unless-stopped
|
||||
command: uvicorn app.main:app --host 0.0.0.0 --port 8000
|
||||
ports:
|
||||
- "${API_PORT:-8080}:8000"
|
||||
env_file:
|
||||
- .env
|
||||
environment:
|
||||
- INGEST_DATABASE_URL=postgresql+psycopg://${POSTGRES_USER:-rag}:${POSTGRES_PASSWORD:-rag_password}@db:5432/${POSTGRES_DB:-rag}
|
||||
- INGEST_EMBEDDING_ENDPOINT=${INGEST_EMBEDDING_ENDPOINT:-http://host.docker.internal:11434/v1}
|
||||
extra_hosts:
|
||||
- "host.docker.internal:host-gateway"
|
||||
volumes:
|
||||
- ./data/documents:/app/data/documents
|
||||
- ./data/vector_db:/app/data/vector_db
|
||||
- ./data/originals:/app/data/originals
|
||||
- ./data/extractions:/app/data/extractions
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
migrations:
|
||||
condition: service_completed_successfully
|
||||
|
||||
worker:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
container_name: rag-worker
|
||||
restart: unless-stopped
|
||||
command: python -m app.worker
|
||||
env_file:
|
||||
- .env
|
||||
environment:
|
||||
- INGEST_DATABASE_URL=postgresql+psycopg://${POSTGRES_USER:-rag}:${POSTGRES_PASSWORD:-rag_password}@db:5432/${POSTGRES_DB:-rag}
|
||||
- INGEST_EMBEDDING_ENDPOINT=${INGEST_EMBEDDING_ENDPOINT:-http://host.docker.internal:11434/v1}
|
||||
extra_hosts:
|
||||
- "host.docker.internal:host-gateway"
|
||||
volumes:
|
||||
- ./data/originals:/app/data/originals
|
||||
- ./data/extractions:/app/data/extractions
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
migrations:
|
||||
condition: service_completed_successfully
|
||||
|
||||
volumes:
|
||||
postgres_data:
|
||||
Reference in New Issue
Block a user