Skip to content

Commit db2d58d

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 db2d58d

26 files changed

+685
-531
lines changed

2.7/Dockerfile

+25-18
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,29 +37,41 @@ 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" \
44+
&& apt-get purge -y --auto-remove $buildDeps \
5945
\
6046
&& find /usr/local -depth \
6147
\( \
6248
\( -type d -a -name test -o -name tests \) \
6349
-o \
6450
\( -type f -a -name '*.pyc' -o -name '*.pyo' \) \
6551
\) -exec rm -rf '{}' + \
66-
&& apt-get purge -y --auto-remove $buildDeps \
67-
&& rm -rf /usr/src/python ~/.cache
52+
&& rm -rf /usr/src/python
53+
54+
# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'"
55+
ENV PYTHON_PIP_VERSION 9.0.1
56+
57+
RUN set -ex; \
58+
\
59+
wget -O get-pip.py 'https://bootstrap.pypa.io/get-pip.py'; \
60+
\
61+
python get-pip.py \
62+
--disable-pip-version-check \
63+
--no-cache-dir \
64+
"pip==$PYTHON_PIP_VERSION" \
65+
; \
66+
pip --version; \
67+
\
68+
find /usr/local -depth \
69+
\( \
70+
\( -type d -a -name test -o -name tests \) \
71+
-o \
72+
\( -type f -a -name '*.pyc' -o -name '*.pyo' \) \
73+
\) -exec rm -rf '{}' +; \
74+
rm -f get-pip.py
6875

6976
# install "virtualenv", since the vast majority of users of this image will want it
7077
RUN pip install --no-cache-dir virtualenv

2.7/alpine/Dockerfile

+35-24
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,39 @@ RUN set -ex \
8967
)" \
9068
&& apk add --virtual .python-rundeps $runDeps \
9169
&& apk del .build-deps \
92-
&& rm -rf /usr/src/python ~/.cache
70+
\
71+
&& find /usr/local -depth \
72+
\( \
73+
\( -type d -a -name test -o -name tests \) \
74+
-o \
75+
\( -type f -a -name '*.pyc' -o -name '*.pyo' \) \
76+
\) -exec rm -rf '{}' + \
77+
&& rm -rf /usr/src/python
78+
79+
# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'"
80+
ENV PYTHON_PIP_VERSION 9.0.1
81+
82+
RUN set -ex; \
83+
\
84+
apk add --no-cache --virtual .fetch-deps openssl; \
85+
\
86+
wget -O get-pip.py 'https://bootstrap.pypa.io/get-pip.py'; \
87+
\
88+
apk del .fetch-deps; \
89+
\
90+
python get-pip.py \
91+
--disable-pip-version-check \
92+
--no-cache-dir \
93+
"pip==$PYTHON_PIP_VERSION" \
94+
; \
95+
pip --version; \
96+
\
97+
find /usr/local -depth \
98+
\( \
99+
\( -type d -a -name test -o -name tests \) \
100+
-o \
101+
\( -type f -a -name '*.pyc' -o -name '*.pyo' \) \
102+
\) -exec rm -rf '{}' +; \
103+
rm -f get-pip.py
93104

94105
CMD ["python2"]

2.7/slim/Dockerfile

+31-18
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,46 @@ 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" \
59+
&& apt-get purge -y --auto-remove $buildDeps \
7460
\
7561
&& find /usr/local -depth \
7662
\( \
7763
\( -type d -a -name test -o -name tests \) \
7864
-o \
7965
\( -type f -a -name '*.pyc' -o -name '*.pyo' \) \
8066
\) -exec rm -rf '{}' + \
81-
&& apt-get purge -y --auto-remove $buildDeps \
82-
&& rm -rf /usr/src/python ~/.cache
67+
&& rm -rf /usr/src/python
68+
69+
# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'"
70+
ENV PYTHON_PIP_VERSION 9.0.1
71+
72+
RUN set -ex; \
73+
\
74+
apt-get update; \
75+
apt-get install -y --no-install-recommends wget; \
76+
rm -rf /var/lib/apt/lists/*; \
77+
\
78+
wget -O get-pip.py 'https://bootstrap.pypa.io/get-pip.py'; \
79+
\
80+
apt-get purge -y --auto-remove wget; \
81+
\
82+
python get-pip.py \
83+
--disable-pip-version-check \
84+
--no-cache-dir \
85+
"pip==$PYTHON_PIP_VERSION" \
86+
; \
87+
pip --version; \
88+
\
89+
find /usr/local -depth \
90+
\( \
91+
\( -type d -a -name test -o -name tests \) \
92+
-o \
93+
\( -type f -a -name '*.pyc' -o -name '*.pyo' \) \
94+
\) -exec rm -rf '{}' +; \
95+
rm -f get-pip.py
8396

8497
CMD ["python2"]

2.7/wheezy/Dockerfile

+25-18
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,29 +37,41 @@ 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" \
44+
&& apt-get purge -y --auto-remove $buildDeps \
5945
\
6046
&& find /usr/local -depth \
6147
\( \
6248
\( -type d -a -name test -o -name tests \) \
6349
-o \
6450
\( -type f -a -name '*.pyc' -o -name '*.pyo' \) \
6551
\) -exec rm -rf '{}' + \
66-
&& apt-get purge -y --auto-remove $buildDeps \
67-
&& rm -rf /usr/src/python ~/.cache
52+
&& rm -rf /usr/src/python
53+
54+
# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'"
55+
ENV PYTHON_PIP_VERSION 9.0.1
56+
57+
RUN set -ex; \
58+
\
59+
wget -O get-pip.py 'https://bootstrap.pypa.io/get-pip.py'; \
60+
\
61+
python get-pip.py \
62+
--disable-pip-version-check \
63+
--no-cache-dir \
64+
"pip==$PYTHON_PIP_VERSION" \
65+
; \
66+
pip --version; \
67+
\
68+
find /usr/local -depth \
69+
\( \
70+
\( -type d -a -name test -o -name tests \) \
71+
-o \
72+
\( -type f -a -name '*.pyc' -o -name '*.pyo' \) \
73+
\) -exec rm -rf '{}' +; \
74+
rm -f get-pip.py
6875

6976
# install "virtualenv", since the vast majority of users of this image will want it
7077
RUN pip install --no-cache-dir virtualenv

2.7/windows/windowsservercore/Dockerfile

+11-6
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,10 +31,18 @@ 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); \
38-
Write-Host ('Installing {0} ...' -f $pipInstall); \
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 Write-Host ('Installing pip=={0} ...' -f $env:PYTHON_PIP_VERSION); \
3940
(New-Object System.Net.WebClient).DownloadFile('https://bootstrap.pypa.io/get-pip.py', 'get-pip.py'); \
40-
python get-pip.py $pipInstall; \
41+
python get-pip.py \
42+
--disable-pip-version-check \
43+
--no-cache-dir \
44+
('pip=={0}' -f $env:PYTHON_PIP_VERSION) \
45+
; \
4146
Remove-Item get-pip.py -Force; \
4247
\
4348
Write-Host 'Verifying pip install ...'; \

3.3/Dockerfile

+26-22
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,48 @@ 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" \
51+
&& apt-get purge -y --auto-remove $buildDeps \
6852
\
6953
&& find /usr/local -depth \
7054
\( \
7155
\( -type d -a -name test -o -name tests \) \
7256
-o \
7357
\( -type f -a -name '*.pyc' -o -name '*.pyo' \) \
7458
\) -exec rm -rf '{}' + \
75-
&& apt-get purge -y --auto-remove $buildDeps \
76-
&& rm -rf /usr/src/python ~/.cache
59+
&& rm -rf /usr/src/python
7760

7861
# make some useful symlinks that are expected to exist
7962
RUN cd /usr/local/bin \
80-
&& { [ -e easy_install ] || ln -s easy_install-* easy_install; } \
8163
&& ln -s idle3 idle \
8264
&& ln -s pydoc3 pydoc \
8365
&& ln -s python3 python \
8466
&& ln -s python3-config python-config
8567

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+
wget -O get-pip.py 'https://bootstrap.pypa.io/get-pip.py'; \
74+
\
75+
python get-pip.py \
76+
--disable-pip-version-check \
77+
--no-cache-dir \
78+
"pip==$PYTHON_PIP_VERSION" \
79+
; \
80+
pip --version; \
81+
\
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 -f get-pip.py
89+
8690
CMD ["python3"]

0 commit comments

Comments
 (0)