-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
64 lines (44 loc) · 1.89 KB
/
Copy pathDockerfile
File metadata and controls
64 lines (44 loc) · 1.89 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
64
# syntax=docker/dockerfile:1
# Stage 1: builder — install dependencies via uv
FROM python:3.12-slim AS builder
# Install uv
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
WORKDIR /app
# Copy dependency manifests first for layer caching
COPY pyproject.toml ./
# Copy uv.lock if present (tolerate absence with a conditional COPY)
COPY uv.lock* ./
# Sync production dependencies only (no dev extras)
# CPU-only torch is acceptable here; no GPU support in this base image.
# sentence-transformers will pull in a large torch wheel — this is expected.
RUN uv sync --frozen --no-dev 2>/dev/null || uv sync --no-dev
# Copy source code (pgkg/ may not exist yet if Phase 2a is still in progress)
COPY pgkg/ ./pgkg/
COPY migrations/ ./migrations/
COPY scripts/ ./scripts/
# Stage 2: runtime — lean image with venv + app code only
FROM python:3.12-slim AS runtime
# Create non-root user
RUN useradd --create-home --uid 1000 appuser
WORKDIR /app
# Copy the virtual environment from the builder stage
COPY --from=builder /app/.venv /app/.venv
# Copy application code and migrations
COPY --from=builder /app/pgkg ./pgkg
COPY --from=builder /app/migrations ./migrations
COPY --from=builder /app/scripts ./scripts
# Ensure scripts are executable
RUN chmod +x ./scripts/*.sh 2>/dev/null || true
# Give appuser ownership
RUN chown -R appuser:appuser /app
# HuggingFace model cache — mounted as a named volume at runtime
ENV HF_HOME=/data/hf-cache
ENV PYTHONUNBUFFERED=1
# Add venv to PATH so `uv run` and direct invocations work
ENV PATH="/app/.venv/bin:$PATH"
# Healthcheck polls the /health endpoint every 30 s, allows 60 s startup
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')" || exit 1
USER appuser
EXPOSE 8000
CMD ["uvicorn", "pgkg.api:app", "--host", "0.0.0.0", "--port", "8000"]