Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
63 lines (52 loc) · 1.87 KB
/
Copy pathDockerfile
File metadata and controls
63 lines (52 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Dockerfile
#
# Builds the Sentinel AI FastAPI server.
#
# Build:
# docker build -t terminal-ai-assistant .
#
# Run (development):
# docker run -d \
# --name assistant \
# -p 8000:8000 \
# --env-file .env \
# -v $(pwd)/data:/data \
# -e DATABASE_URL=sqlite:////data/assistant.db \
# terminal-ai-assistant
#
# Or use docker-compose:
# docker compose up
#
# Startup sequence (inside the container):
# 1. entrypoint.sh: runs `alembic upgrade head` (auto-migrations)
# 2. entrypoint.sh: starts uvicorn
# 3. FastAPI on_startup: validates env vars + DB health check
#
# The database is stored at DATABASE_URL (default: /data/assistant.db).
# Mount a host directory at /data to persist data between container restarts.
FROM python:3.11-slim
# Keeps Python output unbuffered so logs appear immediately
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1
WORKDIR /app
# Install dependencies first — this layer is cached unless requirements change
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Copy application source
COPY . .
# Create runtime directories that the app may write to
RUN mkdir -p storage backups exports logs /data/storage
# Make the entrypoint executable
RUN chmod +x entrypoint.sh
# The SQLite database lives at DATABASE_URL.
# Default path inside the container is /data/storage/assistant.db.
# Mount /data as a volume to persist data between restarts.
ENV DATABASE_URL=sqlite:////data/storage/assistant.db
VOLUME ["/data"]
EXPOSE 8000
# Health check using the existing /api/v1/health endpoint.
# Starts after 10s, checks every 30s, allows 5s to respond, retries 3x.
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/api/v1/health')" || exit 1
# Run the entrypoint script (migrations → uvicorn)
CMD ["./entrypoint.sh"]