@@ -58,7 +58,49 @@ RUN --mount=type=cache,target=/root/.npm \
5858 npm ci --production
5959
6060# ============================================================================
61- # Stage 4: Runtime - Ubuntu 22.04 with only runtime dependencies
61+ # Stage 4: Download pre-built Python 3.11.14
62+ # ============================================================================
63+ FROM ubuntu:22.04 AS python-builder
64+
65+ # Prevent interactive prompts during package installation
66+ ENV DEBIAN_FRONTEND=noninteractive
67+
68+ # Accept architecture from Docker BuildKit (for multi-arch builds)
69+ ARG TARGETARCH
70+
71+ # Install minimal dependencies for downloading
72+ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
73+ --mount=type=cache,target=/var/lib/apt,sharing=locked \
74+ rm -f /etc/apt/apt.conf.d/docker-clean && \
75+ echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' >/etc/apt/apt.conf.d/keep-cache && \
76+ apt-get update && apt-get install -y --no-install-recommends \
77+ wget ca-certificates
78+
79+ # Download and extract pre-built Python 3.11.14 from python-build-standalone
80+ # Using PGO+LTO optimized builds for better performance
81+ # Supports multi-arch: amd64 (x86_64) and arm64 (aarch64)
82+ RUN --mount=type=cache,target=/tmp/python-cache \
83+ # Map Docker TARGETARCH to python-build-standalone arch naming
84+ if [ "$TARGETARCH" = "amd64" ]; then \
85+ PYTHON_ARCH="x86_64-unknown-linux-gnu" ; \
86+ EXPECTED_SHA256="edd8d11aa538953d12822fab418359a692fd1ee4ca2675579fbf0fa31e3688f1" ; \
87+ elif [ "$TARGETARCH" = "arm64" ]; then \
88+ PYTHON_ARCH="aarch64-unknown-linux-gnu" ; \
89+ EXPECTED_SHA256="08141d31f95d86a23f23e4c741b726de0055f12f83200d1d4867b4e8e6e967c5" ; \
90+ else \
91+ echo "Unsupported architecture: $TARGETARCH" && exit 1; \
92+ fi && \
93+ cd /tmp/python-cache && \
94+ wget -nc https://github.com/indygreg/python-build-standalone/releases/download/20251028/cpython-3.11.14+20251028-${PYTHON_ARCH}-install_only.tar.gz && \
95+ # Verify SHA256 checksum for security
96+ echo "${EXPECTED_SHA256} cpython-3.11.14+20251028-${PYTHON_ARCH}-install_only.tar.gz" | sha256sum -c - && \
97+ cd /tmp && \
98+ tar -xzf /tmp/python-cache/cpython-3.11.14+20251028-${PYTHON_ARCH}-install_only.tar.gz && \
99+ mv python /usr/local/ && \
100+ rm -rf /tmp/cpython-*
101+
102+ # ============================================================================
103+ # Stage 5: Runtime - Ubuntu 22.04 with only runtime dependencies
62104# ============================================================================
63105FROM ubuntu:22.04 AS runtime
64106
@@ -71,44 +113,43 @@ ENV DEBIAN_FRONTEND=noninteractive
71113# Set the sandbox version as an environment variable for version checking
72114ENV SANDBOX_VERSION=${SANDBOX_VERSION}
73115
74- # Install essential runtime packages with cache mounts
116+ # Install runtime packages and Python runtime libraries
75117RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
76118 --mount=type=cache,target=/var/lib/apt,sharing=locked \
77119 rm -f /etc/apt/apt.conf.d/docker-clean && \
78120 echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' >/etc/apt/apt.conf.d/keep-cache && \
79121 apt-get update && apt-get install -y --no-install-recommends \
80- curl \
81- wget \
82- ca-certificates \
83- python3.11 \
84- python3-pip \
85- python3.11-venv \
86- procps \
87- git \
88- unzip \
89- zip \
90- jq \
91- file
122+ ca-certificates curl wget procps git unzip zip jq file \
123+ libssl3 zlib1g libbz2-1.0 libreadline8 libsqlite3-0 \
124+ libncursesw6 libtinfo6 libxml2 libxmlsec1 libffi8 liblzma5 libtk8.6 && \
125+ update-ca-certificates
126+
127+ # Copy pre-built Python from python-builder stage
128+ COPY --from=python-builder /usr/local/python /usr/local/python
129+
130+ # Create symlinks and update shared library cache
131+ RUN ln -s /usr/local/python/bin/python3.11 /usr/local/bin/python3.11 && \
132+ ln -s /usr/local/python/bin/python3 /usr/local/bin/python3 && \
133+ ln -s /usr/local/python/bin/pip3 /usr/local/bin/pip3 && \
134+ echo "/usr/local/python/lib" > /etc/ld.so.conf.d/python.conf && \
135+ ldconfig
92136
93137# Set Python 3.11 as default python3
94- RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1
138+ RUN update-alternatives --install /usr/bin/python3 python3 /usr/local/ bin/python3.11 1
95139
96- # Install Node.js 20 LTS using official NodeSource setup script
97- RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
98- && apt-get install -y nodejs \
99- && rm -rf /var/lib/apt/lists/*
140+ # Install Python packages
141+ RUN --mount=type=cache,target=/root/.cache/pip \
142+ pip3 install --no-cache-dir matplotlib numpy pandas ipython
143+
144+ # Install Node.js 20 LTS from official Node image
145+ COPY --from=node:20-slim /usr/local/bin/node /usr/local/bin/node
146+ COPY --from=node:20-slim /usr/local/lib/node_modules /usr/local/lib/node_modules
147+ RUN ln -s /usr/local/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm && \
148+ ln -s /usr/local/lib/node_modules/npm/bin/npx-cli.js /usr/local/bin/npx
100149
101150# Install Bun runtime from official image
102151COPY --from=oven/bun:1 /usr/local/bin/bun /usr/local/bin/bun
103152
104- # Install essential Python packages with cache mount
105- RUN --mount=type=cache,target=/root/.cache/pip \
106- pip3 install \
107- matplotlib \
108- numpy \
109- pandas \
110- ipython
111-
112153# Set up runtime container server directory
113154WORKDIR /container-server
114155
0 commit comments