Bug 1396154 - Docker image to build a standalone Python tarball; r?dustin draft
authorGregory Szorc <gps@mozilla.com>
Fri, 01 Sep 2017 16:29:26 -0700
changeset 659323 2ce173e918efc5cceca07845c74b2afe1f85578d
parent 659322 9a9313b3b12931b8f0fc550bf1e4325e2855fc31
child 659324 6de2b9ebd49204c95136f7208f16ad3ca88ee4db
push id78111
push usergszorc@mozilla.com
push dateTue, 05 Sep 2017 22:50:25 +0000
reviewersdustin
bugs1396154
milestone57.0a1
Bug 1396154 - Docker image to build a standalone Python tarball; r?dustin An upcoming commit will introduce a standalone Python mini framework for building Docker images within Docker images. We want to use Python for this. But we don't want to litter a Docker image with the system's Python package nor worry about installing a modern version of Python in all Docker images. In this commit, we introduce a Docker image used for building a semi-standalone Python 3.6 tarball. Ideally, the binaries would be statically linked. And we'd probably build with CentOS 6 for maximum glibc portability. These optimizations can be done as a follow-up. MozReview-Commit-ID: Ge9tQ9g1yYw
taskcluster/docker/python-ubuntu1604/Dockerfile
taskcluster/docker/python-ubuntu1604/run.sh
new file mode 100644
--- /dev/null
+++ b/taskcluster/docker/python-ubuntu1604/Dockerfile
@@ -0,0 +1,19 @@
+FROM ubuntu:16.04
+
+ENV PYTHON_VERSION=3.6.2
+ENV PYTHON_HASH=a8270a09a9e9b39f69ece6cdade2fa964665d2107b5acbad4453f1b921107b329c697c137185928fb4a576fc0f2ae2a98dbf26a8b7ea17219e990ddbc216db8b
+
+RUN apt update
+
+RUN apt install -y \
+    build-essential \
+    liblzma-dev \
+    libbz2-dev \
+    libgdbm-dev \
+    libssl-dev \
+    wget \
+    xz-utils \
+    zlib1g-dev
+
+ADD run.sh /run.sh
+RUN /run.sh
new file mode 100755
--- /dev/null
+++ b/taskcluster/docker/python-ubuntu1604/run.sh
@@ -0,0 +1,39 @@
+#!/bin/bash
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+# This script builds a self-contained Python distribution for use
+# with the image builder tool.
+
+set -ex
+
+SHORT=`echo ${PYTHON_VERSION} | awk -F. '{print $1"."$2}'`
+
+wget --progress=dot:giga https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tar.xz
+echo "${PYTHON_HASH}  Python-${PYTHON_VERSION}.tar.xz" | sha512sum -c
+
+tar -xf Python-${PYTHON_VERSION}.tar.xz
+cd Python-${PYTHON_VERSION}
+
+./configure \
+    --prefix /image-build/python-bootstrap \
+    --without-ensurepip
+
+make -j$(grep -c ^processor /proc/cpuinfo)
+
+# We don't need the test modules.
+rm -rf Lib/test
+make -j$(grep -c ^processor /proc/cpuinfo) install
+# Don't need the static library.
+find /image-build/python-bootstrap -name libpython${SHORT}.a -exec rm {} \;
+# Don't need .pyo files.
+find /image-build/python-bootstrap -type f -name '*.pyo' -exec rm {} \;
+
+# Copy some shared libraries into the Python distribution so we don't
+# have a dependency on system packages.
+for lib in libssl.so.1.0.0 libcrypto.so.1.0.0; do
+    cp /lib/x86_64-linux-gnu/${lib} /image-build/python-bootstrap/lib/
+done
+
+tar -C /image-build -czvf /python-bootstrap.tar.gz python-bootstrap