Skip to content

Commit d33374b

Browse files
authored
change: switch to uv-based Docker image for faster startup (#1419)
## Internal ### Updates & Improvements - Speed up start up speeds with `--compile-bytecode` in `uv sync`. - Use `ghcr.io/astral-sh/uv:python3.11-trixie` image instead of `python:3.11.6-bookworm`. - Add `UV_FROZEN=1` and `UV_NO_DEV=1` to simplify docker run commands.
1 parent 354f16c commit d33374b

2 files changed

Lines changed: 15 additions & 13 deletions

File tree

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@ docker.env
3333
__pycache__/
3434
.mypy_cache/
3535
saml/**/certs/*
36+
web/

Dockerfile.srv

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Set up image based on uv / Python3.11
22

3-
FROM python:3.11.6-bookworm
3+
FROM ghcr.io/astral-sh/uv:0.10.4-python3.11-trixie
44

55
RUN apt-get update \
6-
&& apt-get install -y ca-certificates ffmpeg \
6+
&& apt-get install -y ca-certificates ffmpeg --no-install-recommends \
77
&& update-ca-certificates \
88
&& rm -rf /var/lib/apt/lists/*
99

@@ -12,28 +12,29 @@ ARG SENTRY_RELEASE=""
1212
ENV PYTHONFAULTHANDLER=1 \
1313
PYTHONUNBUFFERED=1 \
1414
PYTHONHASHSEED=random \
15-
PIP_NO_CACHE_DIR=off \
16-
PIP_DISABLE_PIP_VERSION_CHECK=on \
17-
PIP_DEFAULT_TIMEOUT=100 \
18-
UV_SYSTEM_PYTHON=true \
15+
NO_COLOR=1 \
16+
UV_COMPILE_BYTECODE=1 \
17+
UV_NO_DEV=1 \
1918
PATH="/code/.venv/bin:$PATH" \
2019
SENTRY_RELEASE=$SENTRY_RELEASE
2120

22-
# Set up uv
23-
RUN pip install uv==0.10.4
24-
2521
WORKDIR /code
2622

23+
# Create runtime user early so COPY --chown can resolve app:app.
24+
RUN useradd --create-home --uid 10001 app
25+
2726
# Copy dependency manifests
2827
COPY uv.lock pyproject.toml /code/
2928

3029
# Install dependencies
31-
RUN uv sync --no-dev --locked --color never
30+
RUN uv sync --locked --color never
31+
RUN chown -R app:app /code/.venv
3232

33-
COPY . /code
33+
# Disable uv's sync lockfile checking,
34+
# since we won't be modifying dependencies in the container.
35+
ENV UV_NO_SYNC=1
3436

35-
RUN useradd --create-home --uid 10001 app \
36-
&& chown -R app:app /code
37+
COPY --chown=app:app . /code
3738
USER app
3839

3940
CMD ["fastapi", "run", "pingpong", "--host", "0.0.0.0", "--port", "8000", "--workers", "4"]

0 commit comments

Comments
 (0)