Skip to content

Commit 0259216

Browse files
committed
feat(python): Use astral.sh Python binary distribution
Signed-off-by: Helio Chissini de Castro <[email protected]>
1 parent cc67c70 commit 0259216

File tree

2 files changed

+54
-38
lines changed

2 files changed

+54
-38
lines changed

.env.versions

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ 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.90.0
2828
SBT_VERSION=1.10.0
2929
SCANCODE_VERSION=32.4.1
3030
SWIFT_VERSION=6.0.3
3131
UBUNTU_VERSION=jammy
32+
UV_VERSION=0.9.3

Dockerfile

Lines changed: 52 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -115,56 +115,53 @@ 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

121-
ARG CONAN_VERSION
122121
ARG CONAN2_VERSION
122+
ARG CONAN_VERSION
123123
ARG PIP_VERSION
124-
ARG PYENV_GIT_TAG
125124
ARG PYTHON_INSPECTOR_VERSION
126125
ARG PYTHON_PIPENV_VERSION
127126
ARG PYTHON_POETRY_PLUGIN_EXPORT_VERSION
128127
ARG PYTHON_POETRY_VERSION
129128
ARG PYTHON_SETUPTOOLS_VERSION
130129
ARG PYTHON_VERSION
131130
ARG SCANCODE_VERSION
131+
ARG UV_VERSION
132132

133133
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
134134

135+
ENV PYTHON_INSTALL_ROOT=/opt/python
136+
ENV PATH=$PATH:$PYTHON_INSTALL_ROOT/bin:$PYTHON_INSTALL_ROOT/conan2/bin
137+
138+
RUN ARCH=$(arch | sed s/aarch64/arm64/) \
139+
&& astral_release="20250918" \
140+
&& download_url="https://github.com/astral-sh/python-build-standalone/releases/download/${astral_release}" \
141+
&& mkdir -p $PYTHON_INSTALL_ROOT \
142+
&& arch="x86_64" \
143+
&& if [ "$ARCH" == "arm64" ]; then \
144+
arch="aarch64"; \
145+
fi \
146+
&& curl -L "${download_url}/cpython-${PYTHON_VERSION}+${astral_release}-${arch}-unknown-linux-gnu-install_only_stripped.tar.gz" | tar -C /opt -xz
147+
148+
# This is required mostly because scancode-mini requirements
135149
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
136150
--mount=type=cache,target=/var/lib/apt,sharing=locked \
137151
sudo apt-get update -qq \
138152
&& DEBIAN_FRONTEND=noninteractive sudo apt-get install -y --no-install-recommends \
139-
libreadline-dev \
140-
libgdbm-dev \
141-
libsqlite3-dev \
142-
libssl-dev \
143-
libbz2-dev \
144-
liblzma-dev \
145-
tk-dev \
153+
libicu-dev \
154+
pkg-config \
155+
clang \
146156
&& sudo rm -rf /var/lib/apt/lists/*
147157

148-
ENV PYENV_ROOT=/opt/python
149-
ENV PATH=$PATH:$PYENV_ROOT/shims:$PYENV_ROOT/bin:$PYENV_ROOT/conan2/bin
150-
RUN curl -kSs https://pyenv.run | bash \
151-
&& pyenv install -v $PYTHON_VERSION \
152-
&& pyenv global $PYTHON_VERSION
153-
154158
RUN ARCH=$(arch | sed s/aarch64/arm64/) \
155-
&& if [ "$ARCH" == "arm64" ]; then \
159+
&& if [ "$ARCH" == "arm64" ]; then \
156160
pip install -U scancode-toolkit-mini==$SCANCODE_VERSION; \
157161
else \
158-
curl -Os https://raw.githubusercontent.com/nexB/scancode-toolkit/v$SCANCODE_VERSION/requirements.txt; \
159-
pip install -U --constraint requirements.txt scancode-toolkit==$SCANCODE_VERSION setuptools==$PYTHON_SETUPTOOLS_VERSION; \
160-
rm requirements.txt; \
162+
pip install -U scancode-toolkit==$SCANCODE_VERSION; \
161163
fi
162164

163-
# Extract ScanCode license texts to a directory.
164-
RUN scancode-license-data --path /opt/scancode-license-data \
165-
&& find /opt/scancode-license-data -type f -not -name "*.LICENSE" -exec rm -f {} + \
166-
&& rm -rf /opt/scancode-license-data/static
167-
168165
RUN pip install --no-cache-dir -U \
169166
pip=="$PIP_VERSION" \
170167
wheel \
@@ -175,19 +172,37 @@ RUN pip install --no-cache-dir -U \
175172
poetry=="$PYTHON_POETRY_VERSION" \
176173
poetry-plugin-export=="$PYTHON_POETRY_PLUGIN_EXPORT_VERSION" \
177174
python-inspector=="$PYTHON_INSPECTOR_VERSION" \
178-
setuptools=="$PYTHON_SETUPTOOLS_VERSION"
179-
RUN mkdir /tmp/conan2 && cd /tmp/conan2 \
180-
&& wget https://github.com/conan-io/conan/releases/download/$CONAN2_VERSION/conan-$CONAN2_VERSION-linux-x86_64.tgz \
181-
&& tar -xvf conan-$CONAN2_VERSION-linux-x86_64.tgz\
175+
setuptools=="$PYTHON_SETUPTOOLS_VERSION" \
176+
uv="$UV_VERSION"
177+
178+
# # Extract ScanCode license texts to a directory.
179+
# RUN ARCH=$(arch | sed s/aarch64/arm64/) \
180+
# if [ "$ARCH" == "arm64" ]; then \
181+
# echo "Not av ailable for Arm due distutils problem";
182+
# else \
183+
# scancode-license-data --path /opt/scancode-license-data; \
184+
# find /opt/scancode-license-data -type f -not -name "*.LICENSE" -exec rm -f {} + \; \
185+
# fi
186+
187+
# # Extract ScanCode license texts to a directory.
188+
# RUN ARCH=$(arch | sed s/aarch64/arm64/) \
189+
# if [ "$ARCH" == "arm64" ]; then \
190+
# echo "Not av ailable for Arm due distutils problem";
191+
# else \
192+
# scancode-license-data --path /opt/scancode-license-data; \
193+
# find /opt/scancode-license-data -type f -not -name "*.LICENSE" -exec rm -f {} + \; \
194+
# fi
195+
196+
RUN mkdir -p $PYTHON_INSTALL_ROOT/conan2 \
197+
&& 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 \
182198
# Rename the Conan 2 executable to "conan2" to be able to call both Conan version from the package manager.
183-
&& mkdir $PYENV_ROOT/conan2 && mv /tmp/conan2/bin $PYENV_ROOT/conan2/ \
184-
&& mv $PYENV_ROOT/conan2/bin/conan $PYENV_ROOT/conan2/bin/conan2
199+
&& mv $PYTHON_INSTALL_ROOT/conan2/bin/conan $PYTHON_INSTALL_ROOT/conan2/bin/conan2
185200

186201
FROM scratch AS python
187-
COPY --from=pythonbuild /opt/python /opt/python
202+
COPY --from=python_install /opt/python /opt/python
188203

189204
FROM scratch AS scancode-license-data
190-
COPY --from=pythonbuild /opt/scancode-license-data /opt/scancode-license-data
205+
COPY --from=python_install /opt/scancode-license-data /opt/scancode-license-data
191206

192207
#------------------------------------------------------------------------
193208
# NODEJS - Build NodeJS as a separate component with nvm
@@ -483,9 +498,9 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
483498
&& sudo rm -rf /var/lib/apt/lists/*
484499

485500
# Python
486-
ENV PYENV_ROOT=/opt/python
487-
ENV PATH=$PATH:$PYENV_ROOT/shims:$PYENV_ROOT/bin:$PYENV_ROOT/conan2/bin
488-
COPY --from=python --chown=$USER:$USER $PYENV_ROOT $PYENV_ROOT
501+
ENV PYTHON_INSTALL_ROOT=/opt/python
502+
ENV PATH=$PATH:$PYTHON_INSTALL_ROOT/shims:$PYTHON_INSTALL_ROOT/bin:$PYTHON_INSTALL_ROOT/conan2/bin
503+
COPY --from=python --chown=$USER:$USER $PYTHON_INSTALL_ROOT $PYTHON_INSTALL_ROOT
489504

490505
# NodeJS
491506
ENV NVM_DIR=/opt/nvm

0 commit comments

Comments
 (0)