Skip to content

Commit 8258fe1

Browse files
committed
Switch to unconditional invocation of "get-pip.py"
Combining `--without-ensurepip` / `Include_pip=0` and "get-pip.py", we can move the `pip` installation to an entirely separate layer, thus allowing for `pip`-only bumps to build faster, given that Python will not also need to be recompiled. This also insulates us from having to decide how often to bump `setuptools` (which has a fairly aggressive release cycle) -- it will naturally bump to the latest version at every `pip` release, every Python release, or every base-image-triggered rebuild.
1 parent 51d73ca commit 8258fe1

File tree

26 files changed

+524
-529
lines changed

26 files changed

+524
-529
lines changed

2.7/Dockerfile

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
1616
ENV GPG_KEY C01E1CAD5EA2C4F0B8E3571504C367C218ADD4FF
1717
ENV PYTHON_VERSION 2.7.13
1818

19-
# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'"
20-
ENV PYTHON_PIP_VERSION 9.0.1
21-
ENV PYTHON_SETUPTOOLS_VERSION 35.0.2
22-
ENV PYTHON_WHEEL_VERSION 0.29.0
23-
2419
RUN set -ex \
2520
&& buildDeps=' \
2621
tcl-dev \
@@ -42,30 +37,35 @@ RUN set -ex \
4237
&& ./configure \
4338
--enable-shared \
4439
--enable-unicode=ucs4 \
45-
&& make -j$(nproc) \
40+
&& make -j "$(nproc)" \
4641
&& make install \
4742
&& ldconfig \
4843
\
49-
&& wget -O /tmp/get-pip.py 'https://bootstrap.pypa.io/get-pip.py' \
50-
&& python2 /tmp/get-pip.py "pip==$PYTHON_PIP_VERSION" \
51-
&& rm /tmp/get-pip.py \
52-
# we use "--force-reinstall" for the case where the version of pip we're trying to install is the same as the version bundled with Python
53-
# ("Requirement already up-to-date: pip==8.1.2 in /usr/local/lib/python3.6/site-packages")
54-
# https://github.com/docker-library/python/pull/143#issuecomment-241032683
55-
&& pip install --no-cache-dir --upgrade --force-reinstall \
56-
"pip==$PYTHON_PIP_VERSION" \
57-
"setuptools==$PYTHON_SETUPTOOLS_VERSION" \
58-
"wheel==$PYTHON_WHEEL_VERSION" \
59-
\
44+
&& apt-get purge -y --auto-remove $buildDeps \
6045
&& find /usr/local -depth \
6146
\( \
6247
\( -type d -a -name test -o -name tests \) \
6348
-o \
6449
\( -type f -a -name '*.pyc' -o -name '*.pyo' \) \
6550
\) -exec rm -rf '{}' + \
66-
&& apt-get purge -y --auto-remove $buildDeps \
6751
&& rm -rf /usr/src/python ~/.cache
6852

53+
# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'"
54+
ENV PYTHON_PIP_VERSION 9.0.1
55+
56+
RUN set -ex; \
57+
\
58+
wget -O /tmp/get-pip.py 'https://bootstrap.pypa.io/get-pip.py'; \
59+
\
60+
python /tmp/get-pip.py "pip==$PYTHON_PIP_VERSION"; \
61+
find /usr/local -depth \
62+
\( \
63+
\( -type d -a -name test -o -name tests \) \
64+
-o \
65+
\( -type f -a -name '*.pyc' -o -name '*.pyo' \) \
66+
\) -exec rm -rf '{}' +; \
67+
rm -rf /tmp/get-pip.py ~/.cache
68+
6969
# install "virtualenv", since the vast majority of users of this image will want it
7070
RUN pip install --no-cache-dir virtualenv
7171

2.7/alpine/Dockerfile

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ RUN apk add --no-cache ca-certificates
1414
ENV GPG_KEY C01E1CAD5EA2C4F0B8E3571504C367C218ADD4FF
1515
ENV PYTHON_VERSION 2.7.13
1616

17-
# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'"
18-
ENV PYTHON_PIP_VERSION 9.0.1
19-
ENV PYTHON_SETUPTOOLS_VERSION 35.0.2
20-
ENV PYTHON_WHEEL_VERSION 0.29.0
21-
2217
RUN set -ex \
2318
&& apk add --no-cache --virtual .fetch-deps \
2419
gnupg \
@@ -60,26 +55,9 @@ RUN set -ex \
6055
&& ./configure \
6156
--enable-shared \
6257
--enable-unicode=ucs4 \
63-
&& make -j$(getconf _NPROCESSORS_ONLN) \
58+
&& make -j "$(getconf _NPROCESSORS_ONLN)" \
6459
&& make install \
6560
\
66-
&& wget -O /tmp/get-pip.py 'https://bootstrap.pypa.io/get-pip.py' \
67-
&& python2 /tmp/get-pip.py "pip==$PYTHON_PIP_VERSION" \
68-
&& rm /tmp/get-pip.py \
69-
# we use "--force-reinstall" for the case where the version of pip we're trying to install is the same as the version bundled with Python
70-
# ("Requirement already up-to-date: pip==8.1.2 in /usr/local/lib/python3.6/site-packages")
71-
# https://github.com/docker-library/python/pull/143#issuecomment-241032683
72-
&& pip install --no-cache-dir --upgrade --force-reinstall \
73-
"pip==$PYTHON_PIP_VERSION" \
74-
"setuptools==$PYTHON_SETUPTOOLS_VERSION" \
75-
"wheel==$PYTHON_WHEEL_VERSION" \
76-
\
77-
&& find /usr/local -depth \
78-
\( \
79-
\( -type d -a -name test -o -name tests \) \
80-
-o \
81-
\( -type f -a -name '*.pyc' -o -name '*.pyo' \) \
82-
\) -exec rm -rf '{}' + \
8361
&& runDeps="$( \
8462
scanelf --needed --nobanner --recursive /usr/local \
8563
| awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \
@@ -89,6 +67,32 @@ RUN set -ex \
8967
)" \
9068
&& apk add --virtual .python-rundeps $runDeps \
9169
&& apk del .build-deps \
70+
&& find /usr/local -depth \
71+
\( \
72+
\( -type d -a -name test -o -name tests \) \
73+
-o \
74+
\( -type f -a -name '*.pyc' -o -name '*.pyo' \) \
75+
\) -exec rm -rf '{}' + \
9276
&& rm -rf /usr/src/python ~/.cache
9377

78+
# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'"
79+
ENV PYTHON_PIP_VERSION 9.0.1
80+
81+
RUN set -ex; \
82+
\
83+
apk add --no-cache --virtual .fetch-deps openssl; \
84+
\
85+
wget -O /tmp/get-pip.py 'https://bootstrap.pypa.io/get-pip.py'; \
86+
\
87+
apk del .fetch-deps; \
88+
\
89+
python /tmp/get-pip.py "pip==$PYTHON_PIP_VERSION"; \
90+
find /usr/local -depth \
91+
\( \
92+
\( -type d -a -name test -o -name tests \) \
93+
-o \
94+
\( -type f -a -name '*.pyc' -o -name '*.pyo' \) \
95+
\) -exec rm -rf '{}' +; \
96+
rm -rf /tmp/get-pip.py ~/.cache
97+
9498
CMD ["python2"]

2.7/slim/Dockerfile

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
1818
ENV GPG_KEY C01E1CAD5EA2C4F0B8E3571504C367C218ADD4FF
1919
ENV PYTHON_VERSION 2.7.13
2020

21-
# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'"
22-
ENV PYTHON_PIP_VERSION 9.0.1
23-
ENV PYTHON_SETUPTOOLS_VERSION 35.0.2
24-
ENV PYTHON_WHEEL_VERSION 0.29.0
25-
2621
RUN set -ex \
2722
&& buildDeps=' \
2823
gcc \
@@ -57,28 +52,39 @@ RUN set -ex \
5752
&& ./configure \
5853
--enable-shared \
5954
--enable-unicode=ucs4 \
60-
&& make -j$(nproc) \
55+
&& make -j "$(nproc)" \
6156
&& make install \
6257
&& ldconfig \
6358
\
64-
&& wget -O /tmp/get-pip.py 'https://bootstrap.pypa.io/get-pip.py' \
65-
&& python2 /tmp/get-pip.py "pip==$PYTHON_PIP_VERSION" \
66-
&& rm /tmp/get-pip.py \
67-
# we use "--force-reinstall" for the case where the version of pip we're trying to install is the same as the version bundled with Python
68-
# ("Requirement already up-to-date: pip==8.1.2 in /usr/local/lib/python3.6/site-packages")
69-
# https://github.com/docker-library/python/pull/143#issuecomment-241032683
70-
&& pip install --no-cache-dir --upgrade --force-reinstall \
71-
"pip==$PYTHON_PIP_VERSION" \
72-
"setuptools==$PYTHON_SETUPTOOLS_VERSION" \
73-
"wheel==$PYTHON_WHEEL_VERSION" \
74-
\
59+
&& apt-get purge -y --auto-remove $buildDeps \
7560
&& find /usr/local -depth \
7661
\( \
7762
\( -type d -a -name test -o -name tests \) \
7863
-o \
7964
\( -type f -a -name '*.pyc' -o -name '*.pyo' \) \
8065
\) -exec rm -rf '{}' + \
81-
&& apt-get purge -y --auto-remove $buildDeps \
8266
&& rm -rf /usr/src/python ~/.cache
8367

68+
# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'"
69+
ENV PYTHON_PIP_VERSION 9.0.1
70+
71+
RUN set -ex; \
72+
\
73+
apt-get update; \
74+
apt-get install -y --no-install-recommends wget; \
75+
rm -rf /var/lib/apt/lists/*; \
76+
\
77+
wget -O /tmp/get-pip.py 'https://bootstrap.pypa.io/get-pip.py'; \
78+
\
79+
apt-get purge -y --auto-remove wget; \
80+
\
81+
python /tmp/get-pip.py "pip==$PYTHON_PIP_VERSION"; \
82+
find /usr/local -depth \
83+
\( \
84+
\( -type d -a -name test -o -name tests \) \
85+
-o \
86+
\( -type f -a -name '*.pyc' -o -name '*.pyo' \) \
87+
\) -exec rm -rf '{}' +; \
88+
rm -rf /tmp/get-pip.py ~/.cache
89+
8490
CMD ["python2"]

2.7/wheezy/Dockerfile

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
1616
ENV GPG_KEY C01E1CAD5EA2C4F0B8E3571504C367C218ADD4FF
1717
ENV PYTHON_VERSION 2.7.13
1818

19-
# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'"
20-
ENV PYTHON_PIP_VERSION 9.0.1
21-
ENV PYTHON_SETUPTOOLS_VERSION 35.0.2
22-
ENV PYTHON_WHEEL_VERSION 0.29.0
23-
2419
RUN set -ex \
2520
&& buildDeps=' \
2621
tcl-dev \
@@ -42,30 +37,35 @@ RUN set -ex \
4237
&& ./configure \
4338
--enable-shared \
4439
--enable-unicode=ucs4 \
45-
&& make -j$(nproc) \
40+
&& make -j "$(nproc)" \
4641
&& make install \
4742
&& ldconfig \
4843
\
49-
&& wget -O /tmp/get-pip.py 'https://bootstrap.pypa.io/get-pip.py' \
50-
&& python2 /tmp/get-pip.py "pip==$PYTHON_PIP_VERSION" \
51-
&& rm /tmp/get-pip.py \
52-
# we use "--force-reinstall" for the case where the version of pip we're trying to install is the same as the version bundled with Python
53-
# ("Requirement already up-to-date: pip==8.1.2 in /usr/local/lib/python3.6/site-packages")
54-
# https://github.com/docker-library/python/pull/143#issuecomment-241032683
55-
&& pip install --no-cache-dir --upgrade --force-reinstall \
56-
"pip==$PYTHON_PIP_VERSION" \
57-
"setuptools==$PYTHON_SETUPTOOLS_VERSION" \
58-
"wheel==$PYTHON_WHEEL_VERSION" \
59-
\
44+
&& apt-get purge -y --auto-remove $buildDeps \
6045
&& find /usr/local -depth \
6146
\( \
6247
\( -type d -a -name test -o -name tests \) \
6348
-o \
6449
\( -type f -a -name '*.pyc' -o -name '*.pyo' \) \
6550
\) -exec rm -rf '{}' + \
66-
&& apt-get purge -y --auto-remove $buildDeps \
6751
&& rm -rf /usr/src/python ~/.cache
6852

53+
# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'"
54+
ENV PYTHON_PIP_VERSION 9.0.1
55+
56+
RUN set -ex; \
57+
\
58+
wget -O /tmp/get-pip.py 'https://bootstrap.pypa.io/get-pip.py'; \
59+
\
60+
python /tmp/get-pip.py "pip==$PYTHON_PIP_VERSION"; \
61+
find /usr/local -depth \
62+
\( \
63+
\( -type d -a -name test -o -name tests \) \
64+
-o \
65+
\( -type f -a -name '*.pyc' -o -name '*.pyo' \) \
66+
\) -exec rm -rf '{}' +; \
67+
rm -rf /tmp/get-pip.py ~/.cache
68+
6969
# install "virtualenv", since the vast majority of users of this image will want it
7070
RUN pip install --no-cache-dir virtualenv
7171

2.7/windows/windowsservercore/Dockerfile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';"]
55
ENV PYTHON_VERSION 2.7.13
66
ENV PYTHON_RELEASE 2.7.13
77

8-
# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'"
9-
ENV PYTHON_PIP_VERSION 9.0.1
10-
118
RUN $url = ('https://www.python.org/ftp/python/{0}/python-{1}.amd64.msi' -f $env:PYTHON_RELEASE, $env:PYTHON_VERSION); \
129
Write-Host ('Downloading {0} ...' -f $url); \
1310
(New-Object System.Net.WebClient).DownloadFile($url, 'python.msi'); \
@@ -34,7 +31,12 @@ RUN $url = ('https://www.python.org/ftp/python/{0}/python-{1}.amd64.msi' -f $env
3431
Write-Host 'Removing ...'; \
3532
Remove-Item python.msi -Force; \
3633
\
37-
$pipInstall = ('pip=={0}' -f $env:PYTHON_PIP_VERSION); \
34+
Write-Host 'Complete.';
35+
36+
# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'"
37+
ENV PYTHON_PIP_VERSION 9.0.1
38+
39+
RUN $pipInstall = ('pip=={0}' -f $env:PYTHON_PIP_VERSION); \
3840
Write-Host ('Installing {0} ...' -f $pipInstall); \
3941
(New-Object System.Net.WebClient).DownloadFile('https://bootstrap.pypa.io/get-pip.py', 'get-pip.py'); \
4042
python get-pip.py $pipInstall; \

3.3/Dockerfile

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
2222
ENV GPG_KEY 26DEA9D4613391EF3E25C9FF0A5B101836580288
2323
ENV PYTHON_VERSION 3.3.6
2424

25-
# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'"
26-
ENV PYTHON_PIP_VERSION 9.0.1
27-
ENV PYTHON_SETUPTOOLS_VERSION 35.0.2
28-
ENV PYTHON_WHEEL_VERSION 0.29.0
29-
3025
RUN set -ex \
3126
&& buildDeps=' \
3227
tcl-dev \
@@ -48,39 +43,41 @@ RUN set -ex \
4843
&& ./configure \
4944
--enable-loadable-sqlite-extensions \
5045
--enable-shared \
51-
&& make -j$(nproc) \
46+
--without-ensurepip \
47+
&& make -j "$(nproc)" \
5248
&& make install \
5349
&& ldconfig \
5450
\
55-
# explicit path to "pip3" to ensure distribution-provided "pip3" cannot interfere
56-
&& if [ ! -e /usr/local/bin/pip3 ]; then : \
57-
&& wget -O /tmp/get-pip.py 'https://bootstrap.pypa.io/get-pip.py' \
58-
&& python3 /tmp/get-pip.py "pip==$PYTHON_PIP_VERSION" \
59-
&& rm /tmp/get-pip.py \
60-
; fi \
61-
# we use "--force-reinstall" for the case where the version of pip we're trying to install is the same as the version bundled with Python
62-
# ("Requirement already up-to-date: pip==8.1.2 in /usr/local/lib/python3.6/site-packages")
63-
# https://github.com/docker-library/python/pull/143#issuecomment-241032683
64-
&& pip3 install --no-cache-dir --upgrade --force-reinstall \
65-
"pip==$PYTHON_PIP_VERSION" \
66-
"setuptools==$PYTHON_SETUPTOOLS_VERSION" \
67-
"wheel==$PYTHON_WHEEL_VERSION" \
68-
\
51+
&& apt-get purge -y --auto-remove $buildDeps \
6952
&& find /usr/local -depth \
7053
\( \
7154
\( -type d -a -name test -o -name tests \) \
7255
-o \
7356
\( -type f -a -name '*.pyc' -o -name '*.pyo' \) \
7457
\) -exec rm -rf '{}' + \
75-
&& apt-get purge -y --auto-remove $buildDeps \
7658
&& rm -rf /usr/src/python ~/.cache
7759

7860
# make some useful symlinks that are expected to exist
7961
RUN cd /usr/local/bin \
80-
&& { [ -e easy_install ] || ln -s easy_install-* easy_install; } \
8162
&& ln -s idle3 idle \
8263
&& ln -s pydoc3 pydoc \
8364
&& ln -s python3 python \
8465
&& ln -s python3-config python-config
8566

67+
# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'"
68+
ENV PYTHON_PIP_VERSION 9.0.1
69+
70+
RUN set -ex; \
71+
\
72+
wget -O /tmp/get-pip.py 'https://bootstrap.pypa.io/get-pip.py'; \
73+
\
74+
python /tmp/get-pip.py "pip==$PYTHON_PIP_VERSION"; \
75+
find /usr/local -depth \
76+
\( \
77+
\( -type d -a -name test -o -name tests \) \
78+
-o \
79+
\( -type f -a -name '*.pyc' -o -name '*.pyo' \) \
80+
\) -exec rm -rf '{}' +; \
81+
rm -rf /tmp/get-pip.py ~/.cache
82+
8683
CMD ["python3"]

0 commit comments

Comments
 (0)