|
| 1 | +FROM cgr.dev/chainguard/wolfi-base:latest@sha256:3754b6da0e1ccdab0fe46abfdd7bbbba994b593c28149f6659fa6597f2261aeb AS base |
| 2 | + |
1 | 3 | ARG PYTHON_VERSION=3.14 |
2 | 4 |
|
3 | | -FROM python:${PYTHON_VERSION} AS builder |
| 5 | +ENV PYTHONUNBUFFERED=1 |
4 | 6 |
|
5 | | -# Set build labels |
6 | | -LABEL stage=builder |
7 | | -LABEL org.opencontainers.image.source="https://github.com/developmentseed/titiler" |
8 | | -LABEL org.opencontainers.image.description="TiTiler" |
9 | | -LABEL org.opencontainers.image.licenses="MIT" |
| 7 | +# Install runtime dependencies. Versions deliberately unpinned: Wolfi rolls |
| 8 | +# forward and garbage-collects old versions, so an "=<version>" pin breaks the |
| 9 | +# build within days. The guardrails are the version-scoped names plus the |
| 10 | +# digest above. No pip: uv (below) installs everything. |
| 11 | +# libstdc++ NOT optional: the rasterio/pyproj/duckdb manylinux wheels list |
| 12 | +# libstdc++.so.6 in DT_NEEDED and auditwheel does not vendor it. |
| 13 | +# bash, tzdata, curl parity with the old Debian base: /bin/sh is busybox, |
| 14 | +# Wolfi ships no /usr/share/zoneinfo, curl is for in-pod debugging. |
| 15 | +RUN apk add --no-cache \ |
| 16 | + python-${PYTHON_VERSION} \ |
| 17 | + libstdc++ bash tzdata curl libexpat1 |
| 18 | + |
| 19 | +# uv as a pass-through stage rather than a direct COPY --from=<image>: |
| 20 | +# Dependabot only parses FROM lines (dependabot/dependabot-core#5103), so this |
| 21 | +# keeps the version pinned *and* auto-updated by the docker ecosystem. |
| 22 | +FROM ghcr.io/astral-sh/uv:0.12.5@sha256:e85be844203885286c60ffad8a858d48afb6c5a5c237ca0e67f12e74b8f174b1 AS uv |
10 | 23 |
|
11 | | -# Set environment variables |
12 | | -ENV PYTHONUNBUFFERED=1 \ |
13 | | - PYTHONDONTWRITEBYTECODE=1 |
| 24 | +# Build stage |
| 25 | +FROM base AS builder |
14 | 26 |
|
15 | | -# Install build dependencies |
16 | | -RUN apt-get update && \ |
17 | | - apt-get install -y --no-install-recommends \ |
18 | | - libexpat1 curl && \ |
19 | | - rm -rf /var/lib/apt/lists/* |
| 27 | +ARG PYTHON_VERSION |
20 | 28 |
|
21 | 29 | # Install uv |
22 | | -COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /usr/local/bin/ |
| 30 | +COPY --from=uv /uv /uvx /usr/local/bin/ |
23 | 31 |
|
24 | 32 | # Configure uv-managed virtual environment |
| 33 | +# UV_PYTHON: the apk python's version, but resolved by uv (not the apk |
| 34 | +# binary itself: Wolfi's rolling python-3.14 build has repeatedly required |
| 35 | +# a newer glibc than the glibc package available in the same repo snapshot, |
| 36 | +# making /usr/bin/python3.14 unable to import stdlib extension modules). |
| 37 | +# uv instead downloads its own self-contained, statically-linked build. |
| 38 | +# UV_PYTHON_INSTALL_DIR: put that managed interpreter next to /opt/venv (both |
| 39 | +# get copied into the runtime stage below) — otherwise it lands under |
| 40 | +# /root/.local/share/uv, which never reaches the runtime stage, leaving |
| 41 | +# /opt/venv/bin/python (and every venv script's shebang, eg uvicorn) a |
| 42 | +# dangling symlink: `exec .../uvicorn: no such file or directory`. |
| 43 | +# UV_COMPILE_BYTECODE: .pyc at install time, as pip did, so cold starts |
| 44 | +# don't pay the compile on first import |
25 | 45 | ENV UV_LINK_MODE=copy \ |
26 | 46 | UV_PROJECT_ENVIRONMENT=/opt/venv \ |
| 47 | + UV_PYTHON=${PYTHON_VERSION} \ |
| 48 | + UV_PYTHON_INSTALL_DIR=/opt/uv-python \ |
| 49 | + UV_COMPILE_BYTECODE=1 \ |
27 | 50 | PATH="/opt/venv/bin:${PATH}" |
28 | 51 |
|
29 | | -WORKDIR /tmp |
| 52 | +WORKDIR /tmp/app |
30 | 53 |
|
31 | | -# Copy project metadata and code |
| 54 | +# Copy project metadata and dependencies |
32 | 55 | COPY pyproject.toml uv.lock README.md LICENSE ./ |
33 | 56 | COPY src/titiler/ ./src/titiler/ |
| 57 | + |
| 58 | +# Install project dependencies into the uv-managed virtual environment. |
| 59 | +# --no-editable: the runtime stage only copies /opt/venv (and /opt/uv-python), |
| 60 | +# not this /tmp/app source tree, so editable installs (.pth files pointing |
| 61 | +# back at /tmp/app) would leave `import titiler...` broken at runtime. |
34 | 62 | RUN uv sync --frozen --no-dev --no-editable --group server |
35 | 63 | RUN uv pip install --no-deps --no-editable . |
36 | 64 |
|
| 65 | +# uv skips downloading its own managed interpreter when the apk python already |
| 66 | +# satisfies UV_PYTHON, leaving UV_PYTHON_INSTALL_DIR absent. Make sure it |
| 67 | +# exists (even empty) so the unconditional COPY below never fails. |
| 68 | +RUN mkdir -p /opt/uv-python |
| 69 | + |
37 | 70 | # Runtime stage |
38 | | -FROM python:${PYTHON_VERSION}-slim |
| 71 | +FROM base |
39 | 72 |
|
40 | 73 | # Set runtime labels |
41 | 74 | LABEL org.opencontainers.image.source="https://github.com/developmentseed/titiler" |
42 | 75 | LABEL org.opencontainers.image.description="TiTiler" |
43 | 76 | LABEL org.opencontainers.image.licenses="MIT" |
44 | 77 |
|
45 | | -# Set environment variables |
46 | | -ENV PYTHONUNBUFFERED=1 \ |
47 | | - PYTHONDONTWRITEBYTECODE=1 \ |
48 | | - PATH="/opt/venv/bin:$PATH" |
| 78 | +# The chart execs `command: ["uvicorn"]` — a bare binary, resolved against the |
| 79 | +# image's PATH. |
| 80 | +ENV PATH="/opt/venv/bin:${PATH}" |
49 | 81 |
|
50 | | -# Install runtime dependencies |
51 | | -RUN apt-get update && \ |
52 | | - apt-get install -y --no-install-recommends \ |
53 | | - libexpat1 curl && \ |
54 | | - rm -rf /var/lib/apt/lists/* |
55 | | - |
56 | | -# Copy virtual environment from builder |
| 82 | +# Copy virtual environment and its interpreter from builder |
57 | 83 | COPY --from=builder /opt/venv /opt/venv |
| 84 | +COPY --from=builder /opt/uv-python /opt/uv-python |
58 | 85 |
|
59 | | -RUN groupadd -g 1000 user && \ |
60 | | - useradd -u 1000 -g user -s /bin/bash -m user |
| 86 | +WORKDIR /tmp |
61 | 87 |
|
62 | | -USER user |
| 88 | +# Run as the wolfi-base nonroot user (uid 65532). On Kubernetes the chart sets |
| 89 | +# the net.ipv4.ip_unprivileged_port_start sysctl per pod. |
| 90 | +# Other deployments must allow unprivileged low ports the same way, |
| 91 | +# or override PORT to something >=1024. |
| 92 | +USER nonroot |
63 | 93 |
|
64 | 94 | ################################################### |
65 | 95 | # For compatibility (might be removed at one point) |
|
0 commit comments