Dockerize chat_backend + Ollama LAN + DB file storage (#6) (#7)
Unit Tests / test (push) Successful in 13s

## Summary

Implements [chat_backend#6](#6) Part A:

- **uv** packaging (`pyproject.toml` + `uv.lock`), Docker/compose (dev + prod), entrypoint/validate-env, Gitea unit-test + auto-deploy workflows (mirror `scha`)
- Env-driven Django settings (`DJANGO_*`, `DATABASE_URL`, CSRF/CORS)
- **`OLLAMA_BASE_URL`** wired through all Ollama/LangChain clients (prod → `http://10.0.0.128:11434`)
- **DatabaseStorage** — prompt/document file blobs in Postgres (`StoredFile`), not container FS; RAG materializes temp paths for loaders
- ASGI via `gunicorn` + `UvicornWorker` (HTTP + WebSockets)

Companion server-infra PR registers `app_catalog` / `host_apps` (port **8003**).

## Test plan

- [ ] `uv sync && cd llm_be && SKIP_RAG_INIT=1 uv run python manage.py test`
- [ ] `docker compose build && docker compose up` against bundled Postgres
- [ ] Confirm Ollama calls use `OLLAMA_BASE_URL` (not hardcoded localhost)
- [ ] Upload a document / prompt file → row in `chat_backend_storedfile`, no disk under `media/`
- [ ] After server-infra merge + secret/Postgres/NPM: deploy via `deploy.sh --app chat_backend --env prod`Reviewed-on: #7
This commit was merged in pull request #7.
This commit is contained in:
2026-07-25 05:23:33 -07:00
parent 77d7edd0dc
commit d1660792ad
31 changed files with 6079 additions and 528 deletions
+24 -4
View File
@@ -2,11 +2,11 @@ from django.db import models
from django.contrib.auth.models import AbstractUser
from django.utils import timezone
from autoslug import AutoSlugField
from django.core.files.storage import FileSystemStorage
from chat_backend.storage import DatabaseStorage
# Create your models here.
FILE_STORAGE = FileSystemStorage(location="prompt_files")
DB_FILE_STORAGE = DatabaseStorage()
class TimeInfoBase(models.Model):
@@ -169,7 +169,11 @@ class Prompt(TimeInfoBase):
"Conversation", on_delete=models.CASCADE, blank=True, null=True
)
file = models.FileField(
upload_to=FILE_STORAGE, blank=True, null=True, help_text="file for the prompt"
upload_to="prompt_files/",
storage=DB_FILE_STORAGE,
blank=True,
null=True,
help_text="file for the prompt (stored in database)",
)
file_type = models.CharField(
max_length=16,
@@ -232,7 +236,23 @@ class DocumentWorkspace(TimeInfoBase):
class Document(TimeInfoBase):
workspace = models.ForeignKey(DocumentWorkspace, on_delete=models.CASCADE)
file = models.FileField(upload_to="documents/")
file = models.FileField(
upload_to="documents/",
storage=DB_FILE_STORAGE,
help_text="uploaded document bytes (stored in database)",
)
uploaded_at = models.DateTimeField(auto_now_add=True)
processed = models.BooleanField(default=False)
active = models.BooleanField(default=False)
class StoredFile(TimeInfoBase):
"""Blob store for DatabaseStorage — prompt attachments and documents."""
name = models.CharField(max_length=512, unique=True, db_index=True)
content = models.BinaryField()
size = models.PositiveBigIntegerField(default=0)
content_type = models.CharField(max_length=255, blank=True, default="")
def __str__(self):
return self.name