forked from HKUDS/OpenSpace
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
83 lines (64 loc) · 3.05 KB
/
Copy pathDockerfile
File metadata and controls
83 lines (64 loc) · 3.05 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
# ============================================
# OpenSpace Multi-Stage Dockerfile
# ============================================
# Build: docker build -t openspace .
# Run: docker run -p 8000:8000 --env-file .env openspace
#
# Environment variables (see .env.example):
# OPENSPACE_MCP_HOST, OPENSPACE_MCP_PORT, OPENSPACE_MCP_TRANSPORT,
# OPENSPACE_LOG_LEVEL, OPENSPACE_SHUTDOWN_TIMEOUT,
# OPENSPACE_METRICS_ENABLED, OPENROUTER_API_KEY, etc.
# ============================================
# ── Stage 1: Build ──────────────────────────────────────────────────
FROM python:3.13-slim AS builder
WORKDIR /build
# Install build dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends gcc && \
rm -rf /var/lib/apt/lists/*
# Copy dependency files first (layer caching — code changes don't bust this)
COPY pyproject.toml requirements.txt ./
# Install Python dependencies (cached unless requirements change)
RUN pip install --no-cache-dir --prefix=/install -r requirements.txt
# Copy application code (separate layer — changes more often)
COPY openspace/ openspace/
# Install the package itself
RUN pip install --no-cache-dir --prefix=/install --no-deps .
# ── Stage 2: Runtime ────────────────────────────────────────────────
FROM python:3.13-slim AS runtime
LABEL org.opencontainers.image.title="OpenSpace" \
org.opencontainers.image.description="AI Agent Framework with MCP Server" \
org.opencontainers.image.source="https://github.com/Deepfreezechill/OpenSpace"
# Create non-root user
RUN groupadd --gid 1001 openspace && \
useradd --uid 1001 --gid openspace --shell /bin/bash --create-home openspace
# Copy installed packages from builder
COPY --from=builder /install /usr/local
# Copy application code
WORKDIR /app
COPY openspace/ openspace/
COPY pyproject.toml ./
# Create directories for runtime data
RUN mkdir -p /app/skills /app/logs && \
chown -R openspace:openspace /app
# Switch to non-root user
USER openspace
# Default environment
ENV OPENSPACE_MCP_HOST=0.0.0.0 \
OPENSPACE_MCP_PORT=8000 \
OPENSPACE_MCP_TRANSPORT=streamable-http \
OPENSPACE_LOG_LEVEL=INFO \
OPENSPACE_SHUTDOWN_TIMEOUT=8 \
OPENSPACE_METRICS_ENABLED=true \
OPENSPACE_SKILL_STORE_PATH=/app/skills \
PYTHONUNBUFFERED=1
EXPOSE 8000
# Health check: hits the real /health endpoint (unauthenticated)
# Default transport is streamable-http, so HTTP check works.
# For stdio transport, override with HEALTHCHECK NONE in docker-compose.
HEALTHCHECK --interval=30s --timeout=10s --start-period=15s --retries=3 \
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')" || exit 1
# Graceful shutdown: Docker sends SIGTERM, handler drains in-flight tasks
STOPSIGNAL SIGTERM
ENTRYPOINT ["python", "-m", "openspace.mcp_server"]
CMD ["--transport", "streamable-http", "--host", "0.0.0.0", "--port", "8000"]