Skip to content

Commit 1182d2f

Browse files
committed
Streamline Dockerfiles into one for the whole project. Modify compose file accordingly
1 parent 1105ae9 commit 1182d2f

16 files changed

Lines changed: 58 additions & 103 deletions

.env.docker.example

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
DMR_BASE_URL=
21
DMR_API_KEY=
2+
API_BASE_URL=
33
MODEL_ID=
4-
API_BASE_URL=
4+
5+
# Docker Model Runner env variables will be automatically created based on the names
6+
# given in the compose file
7+
# DMR_BASE_URL

Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM python:3.12-slim
2+
3+
WORKDIR /app
4+
5+
ENV PYTHONDONTWRITEBYTECODE=1 \
6+
PYTHONUNBUFFERED=1 \
7+
PYTHONPATH=/app
8+
9+
RUN apt-get update && apt-get install -y build-essential curl && rm -rf /var/lib/apt/lists/*
10+
11+
COPY requirements.txt .
12+
RUN pip install -r requirements.txt
13+
14+
COPY backend ./backend
15+
COPY frontend ./frontend
16+

backend/Dockerfile

Lines changed: 0 additions & 23 deletions
This file was deleted.

backend/external/llm_client.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
import json
44
from typing import Any, AsyncGenerator
55
from backend.schemas.chat import LLMRequest
6-
from backend.settings import get_settings
7-
8-
settings = get_settings()
6+
from backend.settings import settings
97

108
HEADERS = {
119
"Content-Type": "application/json",

backend/routers/health.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from fastapi.routing import APIRouter
2-
from backend.settings import get_settings
3-
4-
settings = get_settings()
2+
from backend.settings import settings
53

64
router = APIRouter()
75

backend/schemas/structured.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
from typing import Literal, Any
2-
from pydantic import BaseModel, Field
1+
from pydantic import BaseModel
32

43

54
class Recipe(BaseModel):

backend/settings.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
from functools import lru_cache
22
from pydantic_settings import BaseSettings, SettingsConfigDict
3-
from pydantic import AnyHttpUrl
43

54

65
class Settings(BaseSettings):
7-
DMR_BASE_URL: AnyHttpUrl
6+
DMR_BASE_URL: str
87
DMR_API_KEY: str
98
MODEL_ID: str
10-
API_BASE_URL: AnyHttpUrl | None = None
9+
API_BASE_URL: str | None = None
1110

1211
model_config = SettingsConfigDict(env_file=".env", extra="ignore")
1312

@@ -16,3 +15,5 @@ class Settings(BaseSettings):
1615
def get_settings() -> Settings:
1716
"""Load settings from environment (cached for process lifetime)."""
1817
return Settings() # pyright: ignore[reportCallIssue]
18+
19+
settings = get_settings()

compose.yaml

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
11
services:
22
api:
3-
build: ./backend
4-
container_name: smolchat-api
3+
build: .
54
env_file: .env.docker
65
environment:
7-
PYTHONPATH: /app # parent of "backend" is on the path
8-
PORT: 8000
9-
working_dir: /app
6+
- MODEL_ID=${MODEL_ID}
107
command: uvicorn backend.main:app --host 0.0.0.0 --port 8000
11-
volumes:
12-
- ./backend:/app/backend # <-- mount under /app/backend
138
ports:
149
- "8000:8000"
15-
networks: [appnet]
10+
healthcheck:
11+
test: [ "CMD", "curl", "-f", "http://api:8000/healthz" ]
12+
interval: 10s
13+
timeout: 3s
14+
retries: 5
15+
models:
16+
llm:
17+
endpoint_var: DMR_BASE_URL
1618

1719
ui:
18-
build: ./frontend
19-
container_name: smolchat-ui
20+
build: .
2021
env_file: .env.docker
22+
environment:
23+
- MODEL_ID=${MODEL_ID}
24+
command: streamlit run frontend/app.py --server.address=0.0.0.0 --server.port=8501
2125
ports:
2226
- "8501:8501"
2327
depends_on:
2428
- api
25-
networks: [appnet]
26-
volumes:
27-
- ./frontend:/app
2829

29-
networks:
30-
appnet:
31-
driver: bridge
30+
models:
31+
llm:
32+
model: ${MODEL_ID}
33+
context_size: 8192

frontend/Dockerfile

Lines changed: 0 additions & 34 deletions
This file was deleted.

frontend/chat.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def _on_n_change() -> None:
168168
payload["stop"] = None if not s else [w.strip() for w in s.split(",") if w.strip()]
169169

170170
if st.session_state.stream:
171-
url = f"{API_BASE_URL}chat/stream"
171+
url = f"{API_BASE_URL}/chat/stream"
172172
running_text = ""
173173
try:
174174
with httpx.stream("POST", url, json=payload, timeout=None) as r:
@@ -183,7 +183,7 @@ def _on_n_change() -> None:
183183
except Exception as e:
184184
st.error(f"Streaming error: {e}")
185185
else:
186-
url = f"{API_BASE_URL}chat"
186+
url = f"{API_BASE_URL}/chat"
187187
try:
188188
with httpx.Client(timeout=60.0) as client:
189189
r = client.post(url=url, json=payload)

0 commit comments

Comments
 (0)