Skip to content

Commit 034ddf9

Browse files
committed
use comp python
1 parent 8a35209 commit 034ddf9

File tree

1 file changed

+32
-35
lines changed

1 file changed

+32
-35
lines changed

packages/sandbox/Dockerfile

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -58,41 +58,33 @@ RUN --mount=type=cache,target=/root/.npm \
5858
npm ci --production
5959

6060
# ============================================================================
61-
# Stage 4: Build Python 3.11.11 from source
61+
# Stage 4: Download pre-built Python 3.11.14
6262
# ============================================================================
6363
FROM ubuntu:22.04 AS python-builder
6464

6565
# Prevent interactive prompts during package installation
6666
ENV DEBIAN_FRONTEND=noninteractive
6767

68-
# Install build dependencies for Python
68+
# Install minimal dependencies for downloading
6969
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
7070
--mount=type=cache,target=/var/lib/apt,sharing=locked \
7171
rm -f /etc/apt/apt.conf.d/docker-clean && \
7272
echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' >/etc/apt/apt.conf.d/keep-cache && \
7373
apt-get update && apt-get install -y --no-install-recommends \
74-
build-essential ccache wget ca-certificates \
75-
libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev \
76-
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev \
77-
libffi-dev liblzma-dev
74+
wget ca-certificates
7875

79-
# Download and build Python 3.11.11 with ccache
76+
# Download and extract pre-built Python 3.11.14 from python-build-standalone
77+
# Using PGO+LTO optimized builds for better performance
8078
RUN --mount=type=cache,target=/tmp/python-cache \
81-
--mount=type=cache,target=/root/.ccache \
82-
export PATH="/usr/lib/ccache:$PATH" && \
83-
export CCACHE_DIR=/root/.ccache && \
8479
cd /tmp/python-cache && \
85-
wget -nc https://www.python.org/ftp/python/3.11.11/Python-3.11.11.tar.xz && \
80+
wget -nc https://github.com/indygreg/python-build-standalone/releases/download/20251028/cpython-3.11.14+20251028-aarch64-unknown-linux-gnu-install_only.tar.gz && \
8681
cd /tmp && \
87-
cp /tmp/python-cache/Python-3.11.11.tar.xz . && \
88-
tar -xf Python-3.11.11.tar.xz && \
89-
cd Python-3.11.11 && \
90-
./configure --prefix=/usr/local && \
91-
make -j$(nproc) && \
92-
make altinstall && \
93-
ccache --show-stats && \
94-
cd / && \
95-
rm -rf /tmp/Python-3.11.11*
82+
tar -xzf /tmp/python-cache/cpython-3.11.14+20251028-aarch64-unknown-linux-gnu-install_only.tar.gz && \
83+
mv python /usr/local/ && \
84+
# Create symlinks for standard Python locations
85+
ln -s /usr/local/python/bin/python3.11 /usr/local/bin/python3.11 && \
86+
ln -s /usr/local/python/lib /usr/local/lib/python && \
87+
rm -rf /tmp/cpython-*
9688

9789
# ============================================================================
9890
# Stage 5: Runtime - Ubuntu 22.04 with only runtime dependencies
@@ -119,33 +111,38 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
119111
libncursesw6 libtinfo6 libxml2 libxmlsec1 libffi8 liblzma5 libtk8.6 && \
120112
update-ca-certificates
121113

122-
# Copy compiled Python from python-builder stage
123-
COPY --from=python-builder /usr/local/bin/python3.11 /usr/local/bin/python3.11
124-
COPY --from=python-builder /usr/local/lib/python3.11 /usr/local/lib/python3.11
114+
# Copy pre-built Python from python-builder stage
115+
COPY --from=python-builder /usr/local/python /usr/local/python
116+
117+
# Create symlinks and update shared library cache
118+
RUN ln -s /usr/local/python/bin/python3.11 /usr/local/bin/python3.11 && \
119+
ln -s /usr/local/python/bin/python3 /usr/local/bin/python3 && \
120+
echo "/usr/local/python/lib" > /etc/ld.so.conf.d/python.conf && \
121+
ldconfig
125122

126123
# Set Python 3.11 as default python3, install pip, and clean up
127124
RUN update-alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3.11 1 && \
128125
/usr/local/bin/python3.11 -m ensurepip && \
129126
/usr/local/bin/python3.11 -m pip install --no-cache-dir --upgrade pip && \
130127
# Remove unnecessary Python files to reduce image size
131-
find /usr/local/lib/python3.11 -type d -name "test" -exec rm -rf {} + 2>/dev/null || true && \
132-
find /usr/local/lib/python3.11 -type d -name "tests" -exec rm -rf {} + 2>/dev/null || true && \
133-
find /usr/local/lib/python3.11 -name "*.pyc" -delete && \
134-
find /usr/local/lib/python3.11 -name "*.pyo" -delete && \
135-
find /usr/local/lib/python3.11 -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true && \
136-
# Strip debug symbols from Python binary
137-
strip /usr/local/bin/python3.11 || true
128+
find /usr/local/python/lib -type d -name "test" -exec rm -rf {} + 2>/dev/null || true && \
129+
find /usr/local/python/lib -type d -name "tests" -exec rm -rf {} + 2>/dev/null || true && \
130+
find /usr/local/python/lib -name "*.pyc" -delete && \
131+
find /usr/local/python/lib -name "*.pyo" -delete && \
132+
find /usr/local/python/lib -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true && \
133+
# Strip debug symbols from Python binary (already stripped in pre-built)
134+
strip /usr/local/python/bin/python3.11 2>/dev/null || true
138135

139136
# Install Python packages and clean up
140137
RUN --mount=type=cache,target=/root/.cache/pip \
141138
pip3 install --no-cache-dir matplotlib numpy pandas ipython && \
142139
# Remove test files and caches from installed packages
143-
find /usr/local/lib/python3.11/site-packages -type d -name "test" -exec rm -rf {} + 2>/dev/null || true && \
144-
find /usr/local/lib/python3.11/site-packages -type d -name "tests" -exec rm -rf {} + 2>/dev/null || true && \
145-
find /usr/local/lib/python3.11/site-packages -name "*.pyc" -delete && \
146-
find /usr/local/lib/python3.11/site-packages -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true && \
140+
find /usr/local/python/lib/python3.11/site-packages -type d -name "test" -exec rm -rf {} + 2>/dev/null || true && \
141+
find /usr/local/python/lib/python3.11/site-packages -type d -name "tests" -exec rm -rf {} + 2>/dev/null || true && \
142+
find /usr/local/python/lib/python3.11/site-packages -name "*.pyc" -delete && \
143+
find /usr/local/python/lib/python3.11/site-packages -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true && \
147144
# Strip debug symbols from .so files
148-
find /usr/local/lib/python3.11/site-packages -name "*.so" -exec strip {} \; 2>/dev/null || true && \
145+
find /usr/local/python/lib/python3.11/site-packages -name "*.so" -exec strip {} \; 2>/dev/null || true && \
149146
# Remove binutils after stripping
150147
apt-get remove -y binutils && apt-get autoremove -y
151148

0 commit comments

Comments
 (0)