11# syntax=docker/dockerfile:1
2+
3+ # Define arguments in the global scope
24ARG PYTHON_VERSION="3.11.9"
5+ ARG UV_VERSION="0.4"
6+ FROM ghcr.io/astral-sh/uv:${UV_VERSION} AS uv_build
7+ # we docker image is built based on debian
38FROM python:${PYTHON_VERSION}-slim-bookworm AS base
49
510LABEL maintainer=pcrespov
@@ -38,12 +43,13 @@ ENV LANG=C.UTF-8
3843# Turns off writing .pyc files; superfluous on an ephemeral container.
3944ENV PYTHONDONTWRITEBYTECODE=1 \
4045 VIRTUAL_ENV=/home/scu/.venv
46+ # https://docs.astral.sh/uv/guides/integration/docker/#compiling-bytecode
47+ ENV UV_COMPILE_BYTECODE=1
4148
4249# Ensures that the python and pip executables used
4350# in the image will be those from our virtualenv.
4451ENV PATH="${VIRTUAL_ENV}/bin:$PATH"
4552
46-
4753# -------------------------- Build stage -------------------
4854
4955FROM base AS build
@@ -55,15 +61,14 @@ RUN --mount=type=cache,target=/var/cache/apt,mode=0755,sharing=private \
5561 && apt-get install -y --no-install-recommends \
5662 build-essential
5763
58- # NOTE: install https://github.com/astral-sh/uv ultra-fast rust-based pip replacement
59- RUN --mount=type=cache,mode=0755,target=/root/.cache/pip \
60- pip install uv~=0.2
64+ # install UV https://docs.astral.sh/uv/guides/integration/docker/#installing-uv
65+ COPY --from=uv_build /uv /uvx /bin/
6166
6267# NOTE: python virtualenv is used here such that installed
6368# packages may be moved to production image easily by copying the venv
6469RUN uv venv "${VIRTUAL_ENV}"
6570
66- RUN --mount=type=cache,mode=0755, target=/root/.cache/uv \
71+ RUN --mount=type=cache,target=/root/.cache/uv \
6772 uv pip install --upgrade \
6873 pip~=24.0 \
6974 wheel \
@@ -74,7 +79,7 @@ WORKDIR /build/packages/service-integration
7479RUN \
7580 --mount=type=bind,source=packages,target=/build/packages,rw \
7681 --mount=type=bind,source=packages/service-integration,target=/build/packages/service-integration,rw \
77- --mount=type=cache,mode=0755, target=/root/.cache/uv \
82+ --mount=type=cache,target=/root/.cache/uv \
7883 uv pip install \
7984 --requirement requirements/prod.txt \
8085 && uv pip list
@@ -86,8 +91,6 @@ FROM base AS development
8691# NOTE: this is necessary to allow to build development images but is the same as production here
8792FROM base AS production
8893
89- ENV PYTHONOPTIMIZE=TRUE
90-
9194WORKDIR /home/scu
9295# ensure home folder is read/writable for user scu
9396RUN chown -R scu /home/scu
0 commit comments