Skip to content

Commit fd608c1

Browse files
chore: refactor dockerfile to use uv lock file (#1470)
1 parent 24c792c commit fd608c1

4 files changed

Lines changed: 100 additions & 24 deletions

File tree

‎dockerfiles/Dockerfile‎

Lines changed: 60 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,65 @@
11
ARG PYTHON_VERSION=3.14
22

3-
FROM python:${PYTHON_VERSION}
4-
RUN apt update && apt upgrade -y \
5-
&& apt install curl -y \
6-
&& rm -rf /var/lib/apt/lists/*
7-
8-
# Ensure root certificates are always updated at evey container build
9-
# and curl is using the latest version of them
10-
# RUN mkdir /usr/local/share/ca-certificates/cacert.org
11-
# RUN cd /usr/local/share/ca-certificates/cacert.org && curl -k -O https://www.cacert.org/certs/root.crt
12-
# RUN cd /usr/local/share/ca-certificates/cacert.org && curl -k -O https://www.cacert.org/certs/class3.crt
13-
# ENV CURL_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt
14-
RUN update-ca-certificates
15-
16-
RUN python -m pip install -U pip
17-
RUN python -m pip install uvicorn uvicorn-worker gunicorn
18-
19-
COPY src/titiler/ /tmp/titiler/
20-
RUN python -m pip install /tmp/titiler/core /tmp/titiler/extensions["cogeo,stac"] /tmp/titiler/mosaic["mosaicjson"] /tmp/titiler/xarray /tmp/titiler/application --no-cache-dir --upgrade
21-
RUN rm -rf /tmp/titiler
3+
FROM python:${PYTHON_VERSION} AS builder
4+
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"
10+
11+
# Set environment variables
12+
ENV PYTHONUNBUFFERED=1 \
13+
PYTHONDONTWRITEBYTECODE=1
14+
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/*
20+
21+
# Install uv
22+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /usr/local/bin/
23+
24+
# Configure uv-managed virtual environment
25+
ENV UV_LINK_MODE=copy \
26+
UV_PROJECT_ENVIRONMENT=/opt/venv \
27+
PATH="/opt/venv/bin:${PATH}"
28+
29+
WORKDIR /tmp
30+
31+
# Copy project metadata and code
32+
COPY pyproject.toml uv.lock README.md LICENSE ./
33+
COPY src/titiler/ ./src/titiler/
34+
RUN uv sync --frozen --no-dev --no-editable --group server
35+
RUN uv pip install --no-deps --no-editable .
36+
37+
# Runtime stage
38+
FROM python:${PYTHON_VERSION}-slim
39+
40+
# Set runtime labels
41+
LABEL org.opencontainers.image.source="https://github.com/developmentseed/titiler"
42+
LABEL org.opencontainers.image.description="TiTiler"
43+
LABEL org.opencontainers.image.licenses="MIT"
44+
45+
# Set environment variables
46+
ENV PYTHONUNBUFFERED=1 \
47+
PYTHONDONTWRITEBYTECODE=1 \
48+
PATH="/opt/venv/bin:$PATH"
49+
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
57+
COPY --from=builder /opt/venv /opt/venv
58+
59+
RUN groupadd -g 1000 user && \
60+
useradd -u 1000 -g user -s /bin/bash -m user
61+
62+
USER user
2263

2364
###################################################
2465
# For compatibility (might be removed at one point)

‎dockerfiles/Dockerfile.xarray‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ COPY src/titiler/ /tmp/titiler/
2020
RUN python -m pip install /tmp/titiler/core["telemetry"] /tmp/titiler/xarray --no-cache-dir --upgrade
2121
RUN rm -rf /tmp/titiler
2222

23+
LABEL deprecated=TRUE
24+
2325
###################################################
2426
# For compatibility (might be removed at one point)
2527
ENV MODULE_NAME=titiler.xarray.main

‎pyproject.toml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ docs = [
7777
"mkdocstrings[python]>=0.25.1",
7878
]
7979
server = [
80-
"uvicorn",
80+
"uvicorn[standard]>=0.12.0",
81+
"uvicorn-worker",
82+
"gunicorn",
8183
]
8284

8385
[project.urls]

‎uv.lock‎

Lines changed: 35 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)