-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
143 lines (125 loc) · 5.22 KB
/
Copy pathDockerfile
File metadata and controls
143 lines (125 loc) · 5.22 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# syntax=docker/dockerfile:1
# Multi-stage build for fastretrieval
# Python 3.13 + SearXNG + Playwright chromium
# All-in-one: no external Docker or services needed
# ========================
# Stage 1: Builder
# ========================
# Use python:3.13-slim (Debian bookworm) which tracks the latest 3.13 patch
# (currently 3.13.13). The astral-sh/uv Docker image still pins an older
# build with uv 0.9.30 + Python 3.13.11, which does not satisfy
# requires-python = ">=3.13.13" from web-core 1.3.5.
# Copy the uv binary from the standalone uv image (always latest).
FROM python:3.13-slim-bookworm@sha256:bb73517d48bd32016e15eade0c009b2724ec3a025a9975b5cd9b251d0dcadb33 AS builder
COPY --from=ghcr.io/astral-sh/uv:latest@sha256:bca7f6959666f3524e0c42129f9d8bbcfb0c180d847f5187846b98ff06125ead /uv /uvx /usr/local/bin/
ENV UV_COMPILE_BYTECODE=1 \
UV_LINK_MODE=copy \
UV_PYTHON_DOWNLOADS=never
WORKDIR /app
# Install git (required by SearXNG build system for version detection)
RUN apt-get update && apt-get install -y --no-install-recommends git \
&& rm -rf /var/lib/apt/lists/*
# Install dependencies first (cached when deps don't change)
# Strip [tool.uv.sources] local path overrides so uv resolves from PyPI
COPY pyproject.toml uv.lock ./
RUN sed -i '/^\[tool\.uv\.sources\]/,/^$/d' pyproject.toml && \
cp uv.lock /tmp/uv.lock.docker
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --no-install-project --no-dev
# Copy application code and install the project
COPY . /app
RUN sed -i '/^\[tool\.uv\.sources\]/,/^$/d' pyproject.toml && \
cp /tmp/uv.lock.docker uv.lock
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --no-dev
# Install SearXNG from GitHub (zip archive + no-build-isolation for speed)
# Then patch version_frozen.py (zip has no .git for version detection)
RUN --mount=type=cache,target=/root/.cache/uv \
uv pip install --quiet msgspec setuptools wheel pyyaml \
&& uv pip install --quiet --no-build-isolation \
https://github.com/searxng/searxng/archive/refs/heads/master.zip \
&& uv run python -c "\
import importlib.util; from pathlib import Path; \
spec = importlib.util.find_spec('searx'); \
vf = Path(spec.submodule_search_locations[0]) / 'version_frozen.py'; \
vf.write_text('VERSION_STRING = \"0.0.0\"\nVERSION_TAG = \"v0.0.0\"\nDOCKER_TAG = \"\"\nGIT_URL = \"https://github.com/searxng/searxng\"\nGIT_BRANCH = \"master\"\n'); \
print(f'Created {vf}')"
# Install Playwright chromium browser
ENV PLAYWRIGHT_BROWSERS_PATH=/opt/playwright
RUN uv run python -m playwright install chromium
# ========================
# Stage 2: Runtime base (shared by stdio + http targets)
# ========================
# Multi-target Dockerfile per spec
# `~/projects/.superpower/mcp-core/specs/2026-04-30-multi-mode-stdio-http-architecture.md`
# section D6. Build stdio: `docker buildx build --target stdio -t <repo>:stdio .`
# Build http: `docker buildx build --target http -t <repo>:http .`
# Build latest (= http): `docker buildx build --target http -t <repo>:latest .`
FROM python:3.13-slim-bookworm@sha256:bb73517d48bd32016e15eade0c009b2724ec3a025a9975b5cd9b251d0dcadb33 AS runtime
LABEL org.opencontainers.image.source="https://github.com/n24q02m/fastretrieval"
LABEL io.modelcontextprotocol.server.name="io.github.n24q02m/fastretrieval"
WORKDIR /app
# Install Playwright runtime dependencies (system libs for chromium)
RUN apt-get update && apt-get install -y --no-install-recommends \
# Playwright chromium dependencies
libnss3 \
libnspr4 \
libatk1.0-0 \
libatk-bridge2.0-0 \
libcups2 \
libdrm2 \
libdbus-1-3 \
libxkbcommon0 \
libatspi2.0-0 \
libxcomposite1 \
libxdamage1 \
libxfixes3 \
libxrandr2 \
libgbm1 \
libpango-1.0-0 \
libcairo2 \
libasound2 \
libwayland-client0 \
# D-Bus daemon (required by Chromium headless)
dbus \
# Additional Chromium dependencies
libxshmfence1 \
libx11-xcb1 \
# SearXNG dependencies
libxml2 \
libxslt1.1 \
# General
fonts-liberation \
&& rm -rf /var/lib/apt/lists/*
# Copy virtual environment and Playwright browsers from builder
COPY --from=builder /app/.venv /app/.venv
COPY --from=builder /app/src /app/src
COPY --from=builder /opt/playwright /opt/playwright
# Set environment variables
ENV PATH="/app/.venv/bin:$PATH" \
PYTHONPATH=/app/src \
PLAYWRIGHT_BROWSERS_PATH=/opt/playwright \
CACHE_DIR=/data \
DOWNLOAD_DIR=/data/downloads \
DBUS_SESSION_BUS_ADDRESS=disabled:
# Create non-root user and set permissions
RUN groupadd -r appuser && useradd -r -g appuser -d /home/appuser -m appuser \
&& mkdir -p /data/downloads /home/appuser/.fastretrieval \
&& touch /home/appuser/.fastretrieval/.setup-complete \
&& chown -R appuser:appuser /app /data /home/appuser /opt/playwright
VOLUME /data
USER appuser
# ========================
# Stage 3a: stdio target (default for plugin marketplace & uvx-style usage)
# ========================
FROM runtime AS stdio
ENV MCP_TRANSPORT=stdio
ENTRYPOINT ["python", "-m", "fastretrieval"]
# ========================
# Stage 3b: http target (multi-user remote daemon)
# ========================
FROM runtime AS http
ENV MCP_TRANSPORT=http \
MCP_PORT=8080
EXPOSE 8080
ENTRYPOINT ["python", "-m", "fastretrieval"]