Skip to content

Commit a25ed5f

Browse files
committed
Split cpython build by minor version
1 parent 0ddb4ce commit a25ed5f

File tree

5 files changed

+80
-96
lines changed

5 files changed

+80
-96
lines changed

docker/Dockerfile

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,48 @@ RUN export SQLITE_AUTOCONF_ROOT=sqlite-autoconf-3340000 && \
8585
export SQLITE_AUTOCONF_DOWNLOAD_URL=https://www.sqlite.org/2020 && \
8686
manylinux-entrypoint /build_scripts/build-sqlite3.sh
8787

88-
COPY build_scripts/*pubkey*.txt /build_scripts/
89-
COPY build_scripts/build_env.sh /build_scripts/
9088
COPY build_scripts/build-cpython.sh /build_scripts/
91-
RUN manylinux-entrypoint /build_scripts/build-cpython.sh
89+
90+
91+
FROM build_cpython AS build_cpython35
92+
COPY build_scripts/cpython-pubkeys.txt /build_scripts/cpython-pubkeys.txt
93+
RUN manylinux-entrypoint gpg --import /build_scripts/cpython-pubkeys.txt
94+
RUN manylinux-entrypoint /build_scripts/build-cpython.sh 3.5.10
95+
96+
97+
FROM build_cpython AS build_cpython36
98+
COPY build_scripts/cpython-pubkeys.txt /build_scripts/cpython-pubkeys.txt
99+
RUN manylinux-entrypoint gpg --import /build_scripts/cpython-pubkeys.txt
100+
RUN manylinux-entrypoint /build_scripts/build-cpython.sh 3.6.12
101+
102+
103+
FROM build_cpython AS build_cpython37
104+
COPY build_scripts/cpython-pubkeys.txt /build_scripts/cpython-pubkeys.txt
105+
RUN manylinux-entrypoint gpg --import /build_scripts/cpython-pubkeys.txt
106+
RUN manylinux-entrypoint /build_scripts/build-cpython.sh 3.7.9
107+
108+
109+
FROM build_cpython AS build_cpython38
110+
COPY build_scripts/ambv-pubkey.txt /build_scripts/ambv-pubkey.txt
111+
RUN manylinux-entrypoint gpg --import /build_scripts/ambv-pubkey.txt
112+
RUN manylinux-entrypoint /build_scripts/build-cpython.sh 3.8.7
113+
114+
115+
FROM build_cpython AS build_cpython39
116+
COPY build_scripts/ambv-pubkey.txt /build_scripts/ambv-pubkey.txt
117+
RUN manylinux-entrypoint gpg --import /build_scripts/ambv-pubkey.txt
118+
RUN manylinux-entrypoint /build_scripts/build-cpython.sh 3.9.1
92119

93120

94121
FROM runtime_base
95122
COPY --from=build_git /manylinux-rootfs /
96123
COPY --from=build_cmake /manylinux-rootfs /
97124
COPY --from=build_cpython /manylinux-rootfs /
98-
COPY --from=build_cpython /opt/_internal /opt/_internal/
125+
COPY --from=build_cpython35 /opt/_internal /opt/_internal/
126+
COPY --from=build_cpython36 /opt/_internal /opt/_internal/
127+
COPY --from=build_cpython37 /opt/_internal /opt/_internal/
128+
COPY --from=build_cpython38 /opt/_internal /opt/_internal/
129+
COPY --from=build_cpython39 /opt/_internal /opt/_internal/
99130
COPY build_scripts/finalize.sh /build_scripts/finalize.sh
100131
COPY build_scripts/python-tag-abi-tag.py /build_scripts/python-tag-abi-tag.py
101132
COPY build_scripts/ssl-check.py /build_scripts/ssl-check.py

docker/build_scripts/build-cpython.sh

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,50 @@
22
# Top-level build script called from Dockerfile
33

44
# Stop at any error, show all commands
5-
set -ex
5+
set -exuo pipefail
66

7-
# Set build environment variables
7+
# Get script directory
88
MY_DIR=$(dirname "${BASH_SOURCE[0]}")
9-
source $MY_DIR/build_env.sh
109

1110
# Get build utilities
1211
source $MY_DIR/build_utils.sh
1312

14-
# Compile the latest Python releases.
15-
# (In order to have a proper SSL module, Python is compiled
16-
# against a recent openssl [see env vars above], which is linked
17-
# statically.
18-
build_cpythons $CPYTHON_VERSIONS
13+
14+
CPYTHON_VERSION=$1
15+
CPYTHON_DOWNLOAD_URL=https://www.python.org/ftp/python
16+
17+
18+
function pyver_dist_dir {
19+
# Echoes the dist directory name of given pyver, removing alpha/beta prerelease
20+
# Thus:
21+
# 3.2.1 -> 3.2.1
22+
# 3.7.0b4 -> 3.7.0
23+
echo $1 | awk -F "." '{printf "%d.%d.%d", $1, $2, $3}'
24+
}
25+
26+
27+
CPYTHON_DIST_DIR=$(pyver_dist_dir ${CPYTHON_VERSION})
28+
fetch_source Python-${CPYTHON_VERSION}.tgz ${CPYTHON_DOWNLOAD_URL}/${CPYTHON_DIST_DIR}
29+
fetch_source Python-${CPYTHON_VERSION}.tgz.asc ${CPYTHON_DOWNLOAD_URL}/${CPYTHON_DIST_DIR}
30+
gpg --verify Python-${CPYTHON_VERSION}.tgz.asc
31+
tar -xzf Python-${CPYTHON_VERSION}.tgz
32+
pushd Python-${CPYTHON_VERSION}
33+
PREFIX="/opt/_internal/cpython-${CPYTHON_VERSION}"
34+
mkdir -p ${PREFIX}/lib
35+
./configure --prefix=${PREFIX} --disable-shared --with-ensurepip=no > /dev/null
36+
make -j$(nproc) > /dev/null
37+
make -j$(nproc) install > /dev/null
38+
popd
39+
rm -rf Python-${CPYTHON_VERSION} Python-${CPYTHON_VERSION}.tgz Python-${CPYTHON_VERSION}.tgz.asc
1940

2041
# we don't need libpython*.a, and they're many megabytes
21-
find /opt/_internal -name '*.a' -print0 | xargs -0 rm -f
22-
23-
# Strip what we can -- and ignore errors, because this just attempts to strip
24-
# *everything*, including non-ELF files:
25-
find /opt/_internal -type f -print0 \
26-
| xargs -0 -n1 strip --strip-unneeded 2>/dev/null || true
27-
find /manylinux-rootfs -type f -print0 \
28-
| xargs -0 -n1 strip --strip-unneeded 2>/dev/null || true
29-
30-
# We do not need the Python test suites, or indeed the precompiled .pyc and
31-
# .pyo files. Partially cribbed from:
32-
# https://github.com/docker-library/python/blob/master/3.4/slim/Dockerfile
33-
find /opt/_internal -depth \
34-
\( -type d -a -name test -o -name tests \) \
35-
-o \( -type f -a -name '*.pyc' -o -name '*.pyo' \) | xargs rm -rf
42+
find ${PREFIX} -name '*.a' -print0 | xargs -0 rm -f
43+
44+
# We do not need the Python test suites
45+
find ${PREFIX} -depth \( -type d -a -name test -o -name tests \) | xargs rm -rf
46+
47+
# We do not need precompiled .pyc and .pyo files.
48+
clean_pyc ${PREFIX}
49+
50+
# Strip ELF files found in ${PREFIX}
51+
strip_ ${PREFIX}

docker/build_scripts/build_env.sh

Lines changed: 0 additions & 5 deletions
This file was deleted.

docker/build_scripts/build_utils.sh

Lines changed: 4 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -10,67 +10,6 @@ function check_var {
1010
}
1111

1212

13-
function lex_pyver {
14-
# Echoes Python version string padded with zeros
15-
# Thus:
16-
# 3.2.1 -> 003002001
17-
# 3 -> 003000000
18-
echo $1 | awk -F "." '{printf "%03d%03d%03d", $1, $2, $3}'
19-
}
20-
21-
22-
function pyver_dist_dir {
23-
# Echoes the dist directory name of given pyver, removing alpha/beta prerelease
24-
# Thus:
25-
# 3.2.1 -> 3.2.1
26-
# 3.7.0b4 -> 3.7.0
27-
echo $1 | awk -F "." '{printf "%d.%d.%d", $1, $2, $3}'
28-
}
29-
30-
31-
function do_cpython_build {
32-
local py_ver=$1
33-
check_var $py_ver
34-
tar -xzf Python-$py_ver.tgz
35-
pushd Python-$py_ver
36-
local prefix="/opt/_internal/cpython-${py_ver}"
37-
mkdir -p ${prefix}/lib
38-
./configure --prefix=${prefix} --disable-shared --with-ensurepip=no > /dev/null
39-
make -j$(nproc) > /dev/null
40-
make -j$(nproc) install > /dev/null
41-
popd
42-
rm -rf Python-$py_ver
43-
}
44-
45-
46-
function build_cpython {
47-
local py_ver=$1
48-
check_var $py_ver
49-
check_var $PYTHON_DOWNLOAD_URL
50-
local py_dist_dir=$(pyver_dist_dir $py_ver)
51-
curl -fsSLO $PYTHON_DOWNLOAD_URL/$py_dist_dir/Python-$py_ver.tgz
52-
curl -fsSLO $PYTHON_DOWNLOAD_URL/$py_dist_dir/Python-$py_ver.tgz.asc
53-
gpg --verify Python-$py_ver.tgz.asc
54-
do_cpython_build $py_ver
55-
rm -f Python-$py_ver.tgz
56-
rm -f Python-$py_ver.tgz.asc
57-
}
58-
59-
60-
function build_cpythons {
61-
# Import public keys used to verify downloaded Python source tarballs.
62-
# https://www.python.org/static/files/pubkeys.txt
63-
gpg --import ${MY_DIR}/cpython-pubkeys.txt
64-
# Add version 3.8, 3.9 release manager's key
65-
gpg --import ${MY_DIR}/ambv-pubkey.txt
66-
for py_ver in $@; do
67-
build_cpython $py_ver
68-
done
69-
# Remove GPG hidden directory.
70-
rm -rf /root/.gnupg/
71-
}
72-
73-
7413
function fetch_source {
7514
# This is called both inside and outside the build context (e.g. in Travis) to prefetch
7615
# source tarballs, where curl exists (and works)
@@ -109,3 +48,7 @@ function strip_ {
10948
# *everything*, including non-ELF files:
11049
find $1 -type f -print0 | xargs -0 -n1 strip --strip-unneeded 2>/dev/null || true
11150
}
51+
52+
function clean_pyc {
53+
find $1 -type f -a \( -name '*.pyc' -o -name '*.pyo' \) -delete
54+
}

docker/build_scripts/finalize.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,8 @@ for PYTHON in /opt/python/*/bin/python; do
6161
$PYTHON $MY_DIR/ssl-check.py
6262
done
6363

64-
# We do not need the precompiled .pyc and .pyo files. Partially cribbed from:
65-
# https://github.com/docker-library/python/blob/master/3.4/slim/Dockerfile
66-
find /opt/_internal -type f -a \( -name '*.pyc' -o -name '*.pyo' \) | xargs rm -rf
64+
# We do not need the precompiled .pyc and .pyo files.
65+
clean_pyc /opt/_internal
6766

6867
# remove cache
6968
rm -rf /root/.cache

0 commit comments

Comments
 (0)