|
1 | | -# Use slim Python base instead of full Playwright image (saves ~300-400 MB) |
2 | | -# Only Chromium is installed, not Firefox/WebKit |
3 | | -FROM python:3.14-slim-bookworm@sha256:55e465cb7e50cd1d7217fcb5386aa87d0356ca2cd790872142ef68d9ef6812b4 |
| 1 | +# -- Stage 1: Build virtual environment -- |
| 2 | +FROM python:3.14-slim-bookworm@sha256:55e465cb7e50cd1d7217fcb5386aa87d0356ca2cd790872142ef68d9ef6812b4 AS builder |
4 | 3 |
|
5 | | -# Install uv package manager |
6 | 4 | COPY --from=ghcr.io/astral-sh/uv:latest@sha256:90bbb3c16635e9627f49eec6539f956d70746c409209041800a0280b93152823 /uv /uvx /bin/ |
7 | 5 |
|
8 | | -# Create non-root user first (matching original pwuser from Playwright image) |
9 | | -RUN useradd -m -s /bin/bash pwuser |
10 | | - |
11 | | -# Set working directory and ownership |
12 | 6 | WORKDIR /app |
13 | | -RUN chown pwuser:pwuser /app |
| 7 | +COPY pyproject.toml uv.lock README.md ./ |
| 8 | +RUN uv sync --frozen --no-install-project --no-dev --no-editable --compile-bytecode |
14 | 9 |
|
15 | | -# Copy project files with correct ownership |
16 | | -COPY --chown=pwuser:pwuser . /app |
| 10 | +COPY . . |
| 11 | +RUN uv sync --frozen --no-dev --no-editable --compile-bytecode |
17 | 12 |
|
18 | | -# Install git (needed for git-based dependencies in pyproject.toml) |
19 | | -RUN apt-get update && apt-get install -y --no-install-recommends git && rm -rf /var/lib/apt/lists/* |
20 | 13 |
|
21 | | -# Set browser install location (Patchright reads PLAYWRIGHT_BROWSERS_PATH internally) |
| 14 | +# -- Stage 2: Production runtime -- |
| 15 | +FROM python:3.14-slim-bookworm@sha256:55e465cb7e50cd1d7217fcb5386aa87d0356ca2cd790872142ef68d9ef6812b4 |
| 16 | + |
| 17 | +RUN useradd -m -s /bin/bash pwuser |
| 18 | + |
| 19 | +WORKDIR /app |
| 20 | + |
| 21 | +COPY --from=builder /app/.venv /app/.venv |
| 22 | +ENV PATH="/app/.venv/bin:$PATH" |
22 | 23 | ENV PLAYWRIGHT_BROWSERS_PATH=/opt/patchright |
23 | | -# Install dependencies, system libs for Chromium, and patched Chromium binary |
24 | | -RUN uv sync --frozen && \ |
25 | | - uv run patchright install-deps chromium && \ |
26 | | - uv run patchright install chromium && \ |
27 | | - chmod -R 755 /opt/patchright |
28 | 24 |
|
29 | | -# Fix ownership of app directory (venv created by uv) |
30 | | -RUN chown -R pwuser:pwuser /app |
| 25 | +RUN patchright install-deps chromium && \ |
| 26 | + patchright install chromium && \ |
| 27 | + chmod -R 755 /opt/patchright && \ |
| 28 | + rm -rf /var/lib/apt/lists/* |
31 | 29 |
|
32 | | -# Switch to non-root user |
33 | 30 | USER pwuser |
34 | 31 |
|
35 | | -# Set entrypoint and default arguments |
36 | | -ENTRYPOINT ["uv", "run", "-m", "linkedin_mcp_server"] |
| 32 | +ENTRYPOINT ["python", "-m", "linkedin_mcp_server"] |
37 | 33 | CMD [] |
0 commit comments