Skip to content

Commit 392d2a9

Browse files
committed
feat(python): Use uv Python binary distribution
Signed-off-by: Helio Chissini de Castro <[email protected]>
1 parent 68867a5 commit 392d2a9

File tree

2 files changed

+42
-38
lines changed

2 files changed

+42
-38
lines changed

.env.versions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ PYTHON_PIPENV_VERSION=2023.12.1
2222
PYTHON_POETRY_VERSION=2.1.3
2323
PYTHON_POETRY_PLUGIN_EXPORT_VERSION=1.9.0
2424
PYTHON_SETUPTOOLS_VERSION=74.1.3
25-
PYTHON_VERSION=3.13.5
25+
PYTHON_VERSION=3.13.7
2626
RUBY_VERSION=3.4.4
2727
RUST_VERSION=1.87.0
2828
SBT_VERSION=1.10.0

Dockerfile

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -115,33 +115,36 @@ WORKDIR $HOME
115115
ENTRYPOINT [ "/bin/bash" ]
116116

117117
#------------------------------------------------------------------------
118-
# PYTHON - Build Python as a separate component with pyenv
119-
FROM base AS pythonbuild
118+
# PYTHON - Install Python binaries from astral-sh
119+
FROM base AS python_install
120120

121121
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
122122

123+
ARG PYTHON_VERSION
124+
125+
ENV PYTHON_INSTALL_ROOT=/opt/python
126+
ENV PATH=$PATH:$PYTHON_INSTALL_ROOT/bin:$PYTHON_INSTALL_ROOT/conan2/bin
127+
128+
RUN ARCH=$(arch | sed s/aarch64/arm64/) \
129+
&& astral_release="20250918" \
130+
&& download_url="https://github.com/astral-sh/python-build-standalone/releases/download/${astral_release}" \
131+
&& mkdir -p $PYTHON_INSTALL_ROOT \
132+
&& arch="x86_64" \
133+
&& if [ "$ARCH" == "arm64" ]; then \
134+
arch="aarch64"; \
135+
fi \
136+
&& curl -L "${download_url}/cpython-${PYTHON_VERSION}+${astral_release}-${arch}-unknown-linux-gnu-install_only_stripped.tar.gz" | tar -C /opt -xz
137+
138+
# This is required mostly because scancode-mini requirements
123139
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
124140
--mount=type=cache,target=/var/lib/apt,sharing=locked \
125141
sudo apt-get update -qq \
126142
&& DEBIAN_FRONTEND=noninteractive sudo apt-get install -y --no-install-recommends \
127-
libreadline-dev \
128-
libgdbm-dev \
129-
libsqlite3-dev \
130-
libssl-dev \
131-
libbz2-dev \
132-
liblzma-dev \
133-
tk-dev \
143+
libicu-dev \
144+
pkg-config \
145+
clang \
134146
&& sudo rm -rf /var/lib/apt/lists/*
135147

136-
ARG PYTHON_VERSION
137-
ARG PYENV_GIT_TAG
138-
139-
ENV PYENV_ROOT=/opt/python
140-
ENV PATH=$PATH:$PYENV_ROOT/shims:$PYENV_ROOT/bin:$PYENV_ROOT/conan2/bin
141-
RUN curl -kSs https://pyenv.run | bash \
142-
&& pyenv install -v $PYTHON_VERSION \
143-
&& pyenv global $PYTHON_VERSION
144-
145148
ARG CONAN_VERSION
146149
ARG CONAN2_VERSION
147150
ARG PYTHON_INSPECTOR_VERSION
@@ -153,19 +156,12 @@ ARG PIP_VERSION
153156
ARG SCANCODE_VERSION
154157

155158
RUN ARCH=$(arch | sed s/aarch64/arm64/) \
156-
&& if [ "$ARCH" == "arm64" ]; then \
159+
&& if [ "$ARCH" == "arm64" ]; then \
157160
pip install -U scancode-toolkit-mini==$SCANCODE_VERSION; \
158161
else \
159-
curl -Os https://raw.githubusercontent.com/nexB/scancode-toolkit/v$SCANCODE_VERSION/requirements.txt; \
160-
pip install -U --constraint requirements.txt scancode-toolkit==$SCANCODE_VERSION setuptools==$PYTHON_SETUPTOOLS_VERSION; \
161-
rm requirements.txt; \
162+
pip install -U scancode-toolkit==$SCANCODE_VERSION; \
162163
fi
163164

164-
# Extract ScanCode license texts to a directory.
165-
RUN scancode-license-data --path /opt/scancode-license-data \
166-
&& find /opt/scancode-license-data -type f -not -name "*.LICENSE" -exec rm -f {} + \
167-
&& rm -rf /opt/scancode-license-data/static
168-
169165
RUN pip install --no-cache-dir -U \
170166
pip=="$PIP_VERSION" \
171167
wheel \
@@ -177,18 +173,26 @@ RUN pip install --no-cache-dir -U \
177173
poetry-plugin-export=="$PYTHON_POETRY_PLUGIN_EXPORT_VERSION" \
178174
python-inspector=="$PYTHON_INSPECTOR_VERSION" \
179175
setuptools=="$PYTHON_SETUPTOOLS_VERSION"
180-
RUN mkdir /tmp/conan2 && cd /tmp/conan2 \
181-
&& wget https://github.com/conan-io/conan/releases/download/$CONAN2_VERSION/conan-$CONAN2_VERSION-linux-x86_64.tgz \
182-
&& tar -xvf conan-$CONAN2_VERSION-linux-x86_64.tgz\
176+
177+
# # Extract ScanCode license texts to a directory.
178+
# RUN ARCH=$(arch | sed s/aarch64/arm64/) \
179+
# if [ "$ARCH" == "arm64" ]; then \
180+
# echo "Not av ailable for Arm due distutils problem";
181+
# else \
182+
# scancode-license-data --path /opt/scancode-license-data; \
183+
# find /opt/scancode-license-data -type f -not -name "*.LICENSE" -exec rm -f {} + \; \
184+
# fi
185+
186+
RUN mkdir -p $PYTHON_INSTALL_ROOT/conan2 \
187+
&& curl -L https://github.com/conan-io/conan/releases/download/$CONAN2_VERSION/conan-$CONAN2_VERSION-linux-x86_64.tgz | tar -C $PYTHON_INSTALL_ROOT/conan2 -zvx bin \
183188
# Rename the Conan 2 executable to "conan2" to be able to call both Conan version from the package manager.
184-
&& mkdir $PYENV_ROOT/conan2 && mv /tmp/conan2/bin $PYENV_ROOT/conan2/ \
185-
&& mv $PYENV_ROOT/conan2/bin/conan $PYENV_ROOT/conan2/bin/conan2
189+
&& mv $PYTHON_INSTALL_ROOT/conan2/bin/conan $PYTHON_INSTALL_ROOT/conan2/bin/conan2
186190

187191
FROM scratch AS python
188-
COPY --from=pythonbuild /opt/python /opt/python
192+
COPY --from=python_install /opt/python /opt/python
189193

190194
FROM scratch AS scancode-license-data
191-
COPY --from=pythonbuild /opt/scancode-license-data /opt/scancode-license-data
195+
COPY --from=python_install /opt/scancode-license-data /opt/scancode-license-data
192196

193197
#------------------------------------------------------------------------
194198
# NODEJS - Build NodeJS as a separate component with nvm
@@ -482,9 +486,9 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
482486
&& sudo rm -rf /var/lib/apt/lists/*
483487

484488
# Python
485-
ENV PYENV_ROOT=/opt/python
486-
ENV PATH=$PATH:$PYENV_ROOT/shims:$PYENV_ROOT/bin:$PYENV_ROOT/conan2/bin
487-
COPY --from=python --chown=$USER:$USER $PYENV_ROOT $PYENV_ROOT
489+
ENV PYTHON_INSTALL_ROOT=/opt/python
490+
ENV PATH=$PATH:$PYTHON_INSTALL_ROOT/shims:$PYTHON_INSTALL_ROOT/bin:$PYTHON_INSTALL_ROOT/conan2/bin
491+
COPY --from=python --chown=$USER:$USER $PYTHON_INSTALL_ROOT $PYTHON_INSTALL_ROOT
488492

489493
# NodeJS
490494
ARG NODEJS_VERSION

0 commit comments

Comments
 (0)