-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDockerfile
More file actions
106 lines (83 loc) · 3.6 KB
/
Dockerfile
File metadata and controls
106 lines (83 loc) · 3.6 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# syntax=docker/dockerfile:1
# Multi-stage build for horde-model-reference PRIMARY server
FROM python:3.12-slim AS builder
RUN apt-get update && apt-get install -y --no-install-recommends \
git=1:2.47.3-0+deb13u1 \
&& rm -rf /var/lib/apt/lists/*
# Install uv for faster dependency management
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
# Set environment variables for Python and uv
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
UV_COMPILE_BYTECODE=1 \
UV_LINK_MODE=copy
# Set working directory
WORKDIR /app
# Install dependencies using cache and bind mounts for optimal performance
ARG EXTRA_DEPS=""
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
if [ -n "$EXTRA_DEPS" ]; then \
uv sync --frozen --no-dev --no-editable --no-install-project --extra service --extra "$EXTRA_DEPS"; \
else \
uv sync --frozen --no-dev --no-editable --no-install-project --extra service; \
fi
# Copy the project source code
COPY . .
# Install the project itself
# Note: setuptools-scm requires git metadata which is excluded in .dockerignore
# We set SETUPTOOLS_SCM_PRETEND_VERSION to work around this
ARG VERSION=0.0.0+docker
ENV SETUPTOOLS_SCM_PRETEND_VERSION_FOR_HORDE_MODEL_REFERENCE=${VERSION}
RUN --mount=type=cache,target=/root/.cache/uv \
if [ -n "$EXTRA_DEPS" ]; then \
uv sync --frozen --no-dev --no-editable --extra service --extra "$EXTRA_DEPS"; \
else \
uv sync --frozen --no-dev --no-editable --extra service; \
fi
# Final stage
FROM python:3.12-slim AS final
# Add image labels for metadata
LABEL org.opencontainers.image.title="Horde Model Reference" \
org.opencontainers.image.description="Model reference service for AI Horde" \
org.opencontainers.image.source="https://github.com/Haidra-Org/horde-model-reference"
# Install runtime dependencies
# Note: git is required for the GitHub sync service
# hadolint ignore=DL3008 -- curl is unpinned to avoid repeated CI breakage from Debian repo churn
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
git=1:2.47.3-0+deb13u1 \
&& rm -rf /var/lib/apt/lists/*
# Create non-root user and data directory
RUN useradd --system --no-log-init -m -u 1000 horde && \
mkdir -p /data/horde_model_reference && \
chown -R horde:horde /data
# Set working directory
WORKDIR /app
# Copy the virtualenv from the builder and ensure it is owned by the runtime user
# NOTE: using --chown requires a recent Docker; fallback below included in case of incompatibility
COPY --from=builder --chown=horde:horde /app/.venv /app/.venv
# Copy source with ownership set to horde
COPY --chown=horde:horde src ./src
# Copy scripts directory (needed for GitHub sync service)
COPY --chown=horde:horde scripts ./scripts
# Ensure logs dir exists and that /app is owned and writable by horde
RUN mkdir -p /app/logs && \
chown -R horde:horde /app && \
chmod -R u+rwX /app
# Switch to non-root user
USER horde
# Create data directory volumes
VOLUME ["/data"]
# Expose port
EXPOSE 19800
# Environment variables
ENV HORDE_MODEL_REFERENCE_REPLICATE_MODE=PRIMARY \
AIWORKER_CACHE_HOME=/data \
PYTHONUNBUFFERED=1
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD curl -f http://localhost:19800/api/heartbeat || exit 1
# Start the FastAPI application using JSON array format for proper signal handling
CMD ["/app/.venv/bin/fastapi", "run", "src/horde_model_reference/service/app.py", "--host", "0.0.0.0", "--port", "19800"]