Skip to content

Commit a70575c

Browse files
committed
Refactor dependencies handling to keep necessary runtime dependencies automatically, accounting for "tkinter" and "libssl" edge cases appropriately
1 parent c7fd135 commit a70575c

File tree

35 files changed

+223
-315
lines changed

35 files changed

+223
-315
lines changed

2.7/alpine3.6/Dockerfile

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ RUN set -ex \
3737
bzip2-dev \
3838
coreutils \
3939
dpkg-dev dpkg \
40+
findutils \
4041
gcc \
4142
gdbm-dev \
4243
libc-dev \
@@ -67,13 +68,11 @@ RUN set -ex \
6768
EXTRA_CFLAGS="-DTHREAD_STACK_SIZE=0x100000" \
6869
&& make install \
6970
\
70-
&& runDeps="$( \
71-
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local \
72-
| tr ',' '\n' \
73-
| sort -u \
74-
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
75-
)" \
76-
&& apk add --virtual .python-rundeps $runDeps \
71+
&& find /usr/local -type f -executable -not \( -name '*tkinter*' \) -exec scanelf --needed --nobanner --format '%n#p' '{}' ';' \
72+
| tr ',' '\n' \
73+
| sort -u \
74+
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
75+
| xargs -rt apk add --virtual .python-rundeps \
7776
&& apk del .build-deps \
7877
\
7978
&& find /usr/local -depth \
@@ -82,7 +81,9 @@ RUN set -ex \
8281
-o \
8382
\( -type f -a \( -name '*.pyc' -o -name '*.pyo' \) \) \
8483
\) -exec rm -rf '{}' + \
85-
&& rm -rf /usr/src/python
84+
&& rm -rf /usr/src/python \
85+
\
86+
&& python2 --version
8687

8788
# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'"
8889
ENV PYTHON_PIP_VERSION 10.0.1

2.7/alpine3.7/Dockerfile

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ RUN set -ex \
3737
bzip2-dev \
3838
coreutils \
3939
dpkg-dev dpkg \
40+
findutils \
4041
gcc \
4142
gdbm-dev \
4243
libc-dev \
@@ -69,13 +70,11 @@ RUN set -ex \
6970
EXTRA_CFLAGS="-DTHREAD_STACK_SIZE=0x100000" \
7071
&& make install \
7172
\
72-
&& runDeps="$( \
73-
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local \
74-
| tr ',' '\n' \
75-
| sort -u \
76-
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
77-
)" \
78-
&& apk add --virtual .python-rundeps $runDeps \
73+
&& find /usr/local -type f -executable -not \( -name '*tkinter*' \) -exec scanelf --needed --nobanner --format '%n#p' '{}' ';' \
74+
| tr ',' '\n' \
75+
| sort -u \
76+
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
77+
| xargs -rt apk add --virtual .python-rundeps \
7978
&& apk del .build-deps \
8079
\
8180
&& find /usr/local -depth \
@@ -84,7 +83,9 @@ RUN set -ex \
8483
-o \
8584
\( -type f -a \( -name '*.pyc' -o -name '*.pyo' \) \) \
8685
\) -exec rm -rf '{}' + \
87-
&& rm -rf /usr/src/python
86+
&& rm -rf /usr/src/python \
87+
\
88+
&& python2 --version
8889

8990
# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'"
9091
ENV PYTHON_PIP_VERSION 10.0.1

2.7/alpine3.8/Dockerfile

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ RUN set -ex \
3737
bzip2-dev \
3838
coreutils \
3939
dpkg-dev dpkg \
40+
findutils \
4041
gcc \
4142
gdbm-dev \
4243
libc-dev \
@@ -69,13 +70,11 @@ RUN set -ex \
6970
EXTRA_CFLAGS="-DTHREAD_STACK_SIZE=0x100000" \
7071
&& make install \
7172
\
72-
&& runDeps="$( \
73-
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local \
74-
| tr ',' '\n' \
75-
| sort -u \
76-
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
77-
)" \
78-
&& apk add --virtual .python-rundeps $runDeps \
73+
&& find /usr/local -type f -executable -not \( -name '*tkinter*' \) -exec scanelf --needed --nobanner --format '%n#p' '{}' ';' \
74+
| tr ',' '\n' \
75+
| sort -u \
76+
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
77+
| xargs -rt apk add --virtual .python-rundeps \
7978
&& apk del .build-deps \
8079
\
8180
&& find /usr/local -depth \
@@ -84,7 +83,9 @@ RUN set -ex \
8483
-o \
8584
\( -type f -a \( -name '*.pyc' -o -name '*.pyo' \) \) \
8685
\) -exec rm -rf '{}' + \
87-
&& rm -rf /usr/src/python
86+
&& rm -rf /usr/src/python \
87+
\
88+
&& python2 --version
8889

8990
# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'"
9091
ENV PYTHON_PIP_VERSION 10.0.1

2.7/jessie/Dockerfile

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,15 @@ ENV LANG C.UTF-8
99
# https://github.com/docker-library/python/issues/147
1010
ENV PYTHONIOENCODING UTF-8
1111

12-
# runtime dependencies
12+
# extra dependencies (over what buildpack-deps already includes)
1313
RUN apt-get update && apt-get install -y --no-install-recommends \
14-
tcl \
15-
tk \
14+
tk-dev \
1615
&& rm -rf /var/lib/apt/lists/*
1716

1817
ENV GPG_KEY C01E1CAD5EA2C4F0B8E3571504C367C218ADD4FF
1918
ENV PYTHON_VERSION 2.7.15
2019

2120
RUN set -ex \
22-
&& savedAptMark="$(apt-mark showmanual)" \
23-
&& apt-get update && apt-get install -y --no-install-recommends \
24-
tcl-dev \
25-
tk-dev \
26-
&& rm -rf /var/lib/apt/lists/* \
2721
\
2822
&& wget -O python.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" \
2923
&& wget -O python.tar.xz.asc "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" \
@@ -45,10 +39,6 @@ RUN set -ex \
4539
&& make install \
4640
&& ldconfig \
4741
\
48-
&& apt-mark auto '.*' > /dev/null \
49-
&& apt-mark manual $savedAptMark \
50-
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
51-
\
5242
&& find /usr/local -depth \
5343
\( \
5444
\( -type d -a \( -name test -o -name tests \) \) \

2.7/jessie/slim/Dockerfile

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,14 @@ ENV PYTHONIOENCODING UTF-8
1212
# runtime dependencies
1313
RUN apt-get update && apt-get install -y --no-install-recommends \
1414
ca-certificates \
15-
libgdbm3 \
16-
libreadline6 \
17-
libsqlite3-0 \
18-
libssl1.0.0 \
1915
netbase \
2016
&& rm -rf /var/lib/apt/lists/*
2117

2218
ENV GPG_KEY C01E1CAD5EA2C4F0B8E3571504C367C218ADD4FF
2319
ENV PYTHON_VERSION 2.7.15
2420

2521
RUN set -ex \
22+
\
2623
&& savedAptMark="$(apt-mark showmanual)" \
2724
&& apt-get update && apt-get install -y --no-install-recommends \
2825
dpkg-dev \
@@ -36,7 +33,6 @@ RUN set -ex \
3633
libsqlite3-dev \
3734
libssl-dev \
3835
make \
39-
tcl-dev \
4036
tk-dev \
4137
wget \
4238
xz-utils \
@@ -67,6 +63,13 @@ RUN set -ex \
6763
\
6864
&& apt-mark auto '.*' > /dev/null \
6965
&& apt-mark manual $savedAptMark \
66+
&& find /usr/local -type f -executable -not \( -name '*tkinter*' \) -exec ldd '{}' ';' \
67+
| awk '/=>/ { print $(NF-1) }' \
68+
| sort -u \
69+
| xargs -r dpkg-query --search \
70+
| cut -d: -f1 \
71+
| sort -u \
72+
| xargs -r apt-mark manual \
7073
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
7174
\
7275
&& find /usr/local -depth \

2.7/stretch/Dockerfile

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,15 @@ ENV LANG C.UTF-8
99
# https://github.com/docker-library/python/issues/147
1010
ENV PYTHONIOENCODING UTF-8
1111

12-
# runtime dependencies
12+
# extra dependencies (over what buildpack-deps already includes)
1313
RUN apt-get update && apt-get install -y --no-install-recommends \
14-
tcl \
15-
tk \
14+
tk-dev \
1615
&& rm -rf /var/lib/apt/lists/*
1716

1817
ENV GPG_KEY C01E1CAD5EA2C4F0B8E3571504C367C218ADD4FF
1918
ENV PYTHON_VERSION 2.7.15
2019

2120
RUN set -ex \
22-
&& savedAptMark="$(apt-mark showmanual)" \
23-
&& apt-get update && apt-get install -y --no-install-recommends \
24-
tcl-dev \
25-
tk-dev \
26-
&& rm -rf /var/lib/apt/lists/* \
2721
\
2822
&& wget -O python.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" \
2923
&& wget -O python.tar.xz.asc "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" \
@@ -45,10 +39,6 @@ RUN set -ex \
4539
&& make install \
4640
&& ldconfig \
4741
\
48-
&& apt-mark auto '.*' > /dev/null \
49-
&& apt-mark manual $savedAptMark \
50-
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
51-
\
5242
&& find /usr/local -depth \
5343
\( \
5444
\( -type d -a \( -name test -o -name tests \) \) \

2.7/stretch/slim/Dockerfile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ ENV GPG_KEY C01E1CAD5EA2C4F0B8E3571504C367C218ADD4FF
2323
ENV PYTHON_VERSION 2.7.15
2424

2525
RUN set -ex \
26+
\
2627
&& savedAptMark="$(apt-mark showmanual)" \
2728
&& apt-get update && apt-get install -y --no-install-recommends \
2829
dpkg-dev \
@@ -36,7 +37,6 @@ RUN set -ex \
3637
libsqlite3-dev \
3738
libssl-dev \
3839
make \
39-
tcl-dev \
4040
tk-dev \
4141
wget \
4242
xz-utils \
@@ -67,6 +67,13 @@ RUN set -ex \
6767
\
6868
&& apt-mark auto '.*' > /dev/null \
6969
&& apt-mark manual $savedAptMark \
70+
&& find /usr/local -type f -executable -not \( -name '*tkinter*' \) -exec ldd '{}' ';' \
71+
| awk '/=>/ { print $(NF-1) }' \
72+
| sort -u \
73+
| xargs -r dpkg-query --search \
74+
| cut -d: -f1 \
75+
| sort -u \
76+
| xargs -r apt-mark manual \
7077
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
7178
\
7279
&& find /usr/local -depth \

2.7/wheezy/Dockerfile

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,15 @@ ENV LANG C.UTF-8
99
# https://github.com/docker-library/python/issues/147
1010
ENV PYTHONIOENCODING UTF-8
1111

12-
# runtime dependencies
12+
# extra dependencies (over what buildpack-deps already includes)
1313
RUN apt-get update && apt-get install -y --no-install-recommends \
14-
tcl \
15-
tk \
14+
tk-dev \
1615
&& rm -rf /var/lib/apt/lists/*
1716

1817
ENV GPG_KEY C01E1CAD5EA2C4F0B8E3571504C367C218ADD4FF
1918
ENV PYTHON_VERSION 2.7.15
2019

2120
RUN set -ex \
22-
&& savedAptMark="$(apt-mark showmanual)" \
23-
&& apt-get update && apt-get install -y --no-install-recommends \
24-
tcl-dev \
25-
tk-dev \
26-
&& rm -rf /var/lib/apt/lists/* \
2721
\
2822
&& wget -O python.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" \
2923
&& wget -O python.tar.xz.asc "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" \
@@ -45,10 +39,6 @@ RUN set -ex \
4539
&& make install \
4640
&& ldconfig \
4741
\
48-
&& apt-mark auto '.*' > /dev/null \
49-
&& apt-mark manual $savedAptMark \
50-
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
51-
\
5242
&& find /usr/local -depth \
5343
\( \
5444
\( -type d -a \( -name test -o -name tests \) \) \

3.4/alpine3.7/Dockerfile

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ RUN set -ex \
4242
coreutils \
4343
dpkg-dev dpkg \
4444
expat-dev \
45+
findutils \
4546
gcc \
4647
gdbm-dev \
4748
libc-dev \
@@ -77,13 +78,11 @@ RUN set -ex \
7778
EXTRA_CFLAGS="-DTHREAD_STACK_SIZE=0x100000" \
7879
&& make install \
7980
\
80-
&& runDeps="$( \
81-
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local \
82-
| tr ',' '\n' \
83-
| sort -u \
84-
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
85-
)" \
86-
&& apk add --virtual .python-rundeps $runDeps \
81+
&& find /usr/local -type f -executable -not \( -name '*tkinter*' \) -exec scanelf --needed --nobanner --format '%n#p' '{}' ';' \
82+
| tr ',' '\n' \
83+
| sort -u \
84+
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
85+
| xargs -rt apk add --virtual .python-rundeps \
8786
&& apk del .build-deps \
8887
\
8988
&& find /usr/local -depth \
@@ -92,7 +91,9 @@ RUN set -ex \
9291
-o \
9392
\( -type f -a \( -name '*.pyc' -o -name '*.pyo' \) \) \
9493
\) -exec rm -rf '{}' + \
95-
&& rm -rf /usr/src/python
94+
&& rm -rf /usr/src/python \
95+
\
96+
&& python3 --version
9697

9798
# make some useful symlinks that are expected to exist
9899
RUN cd /usr/local/bin \

3.4/jessie/Dockerfile

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,15 @@ ENV PATH /usr/local/bin:$PATH
1313
# > At the moment, setting "LANG=C" on a Linux system *fundamentally breaks Python 3*, and that's not OK.
1414
ENV LANG C.UTF-8
1515

16-
# runtime dependencies
16+
# extra dependencies (over what buildpack-deps already includes)
1717
RUN apt-get update && apt-get install -y --no-install-recommends \
18-
tcl \
19-
tk \
18+
tk-dev \
2019
&& rm -rf /var/lib/apt/lists/*
2120

2221
ENV GPG_KEY 97FC712E4C024BBEA48A61ED3A5CA953F73C700D
2322
ENV PYTHON_VERSION 3.4.8
2423

2524
RUN set -ex \
26-
&& savedAptMark="$(apt-mark showmanual)" \
27-
&& apt-get update && apt-get install -y --no-install-recommends \
28-
tcl-dev \
29-
tk-dev \
30-
&& rm -rf /var/lib/apt/lists/* \
3125
\
3226
&& wget -O python.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" \
3327
&& wget -O python.tar.xz.asc "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" \
@@ -52,10 +46,6 @@ RUN set -ex \
5246
&& make install \
5347
&& ldconfig \
5448
\
55-
&& apt-mark auto '.*' > /dev/null \
56-
&& apt-mark manual $savedAptMark \
57-
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
58-
\
5949
&& find /usr/local -depth \
6050
\( \
6151
\( -type d -a \( -name test -o -name tests \) \) \

0 commit comments

Comments
 (0)