Skip to content

Commit ea4449a

Browse files
authored
Merge pull request #311 from infosiftr/refactor-deps-handling
Refactor dependencies handling to keep necessary runtime dependencies automatically
2 parents 86e133d + c24c7b5 commit ea4449a

38 files changed

+1090
-273
lines changed

.travis.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,34 @@ services: docker
44
env:
55
- VERSION=3.7 VARIANT=stretch
66
- VERSION=3.7 VARIANT=stretch/slim
7+
- VERSION=3.7 VARIANT=alpine3.8
78
- VERSION=3.7 VARIANT=alpine3.7
89
- VERSION=3.6 VARIANT=stretch
910
- VERSION=3.6 VARIANT=stretch/slim
1011
- VERSION=3.6 VARIANT=jessie
1112
- VERSION=3.6 VARIANT=jessie/slim
13+
- VERSION=3.6 VARIANT=alpine3.8
1214
- VERSION=3.6 VARIANT=alpine3.7
1315
- VERSION=3.6 VARIANT=alpine3.6
1416
- VERSION=3.5 VARIANT=stretch
1517
- VERSION=3.5 VARIANT=stretch/slim
1618
- VERSION=3.5 VARIANT=jessie
1719
- VERSION=3.5 VARIANT=jessie/slim
20+
- VERSION=3.5 VARIANT=alpine3.8
1821
- VERSION=3.5 VARIANT=alpine3.7
22+
- VERSION=3.4 VARIANT=stretch
23+
- VERSION=3.4 VARIANT=stretch/slim
1924
- VERSION=3.4 VARIANT=jessie
2025
- VERSION=3.4 VARIANT=jessie/slim
2126
- VERSION=3.4 VARIANT=wheezy
27+
- VERSION=3.4 VARIANT=alpine3.8
2228
- VERSION=3.4 VARIANT=alpine3.7
2329
- VERSION=2.7 VARIANT=stretch
2430
- VERSION=2.7 VARIANT=stretch/slim
2531
- VERSION=2.7 VARIANT=jessie
2632
- VERSION=2.7 VARIANT=jessie/slim
2733
- VERSION=2.7 VARIANT=wheezy
34+
- VERSION=2.7 VARIANT=alpine3.8
2835
- VERSION=2.7 VARIANT=alpine3.7
2936
- VERSION=2.7 VARIANT=alpine3.6
3037

@@ -33,6 +40,7 @@ install:
3340

3441
before_script:
3542
- env | sort
43+
- wget -qO- 'https://github.com/tianon/pgp-happy-eyeballs/raw/master/hack-my-builds.sh' | bash
3644
- cd "$VERSION/$VARIANT"
3745
- slash='/'; image="python:${VERSION}-${VARIANT//$slash/-}"
3846

@@ -41,7 +49,7 @@ script:
4149
(
4250
set -Eeuo pipefail
4351
set -x
44-
travis_retry docker build -t "$image" .
52+
docker build -t "$image" .
4553
~/official-images/test/run.sh "$image"
4654
if [ -d onbuild ]; then
4755
onbuildFrom="$(awk 'toupper($1) == "FROM" { print $2; exit }' onbuild/Dockerfile)"

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: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
FROM alpine:3.8
2+
3+
# ensure local python is preferred over distribution python
4+
ENV PATH /usr/local/bin:$PATH
5+
6+
# http://bugs.python.org/issue19846
7+
# > At the moment, setting "LANG=C" on a Linux system *fundamentally breaks Python 3*, and that's not OK.
8+
ENV LANG C.UTF-8
9+
# https://github.com/docker-library/python/issues/147
10+
ENV PYTHONIOENCODING UTF-8
11+
12+
# install ca-certificates so that HTTPS works consistently
13+
# the other runtime dependencies for Python are installed later
14+
RUN apk add --no-cache ca-certificates
15+
16+
ENV GPG_KEY C01E1CAD5EA2C4F0B8E3571504C367C218ADD4FF
17+
ENV PYTHON_VERSION 2.7.15
18+
19+
RUN set -ex \
20+
&& apk add --no-cache --virtual .fetch-deps \
21+
gnupg \
22+
libressl \
23+
tar \
24+
xz \
25+
\
26+
&& wget -O python.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" \
27+
&& wget -O python.tar.xz.asc "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" \
28+
&& export GNUPGHOME="$(mktemp -d)" \
29+
&& gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$GPG_KEY" \
30+
&& gpg --batch --verify python.tar.xz.asc python.tar.xz \
31+
&& rm -rf "$GNUPGHOME" python.tar.xz.asc \
32+
&& mkdir -p /usr/src/python \
33+
&& tar -xJC /usr/src/python --strip-components=1 -f python.tar.xz \
34+
&& rm python.tar.xz \
35+
\
36+
&& apk add --no-cache --virtual .build-deps \
37+
bzip2-dev \
38+
coreutils \
39+
dpkg-dev dpkg \
40+
findutils \
41+
gcc \
42+
gdbm-dev \
43+
libc-dev \
44+
libnsl-dev \
45+
libressl \
46+
libressl-dev \
47+
libtirpc-dev \
48+
linux-headers \
49+
make \
50+
ncurses-dev \
51+
pax-utils \
52+
readline-dev \
53+
sqlite-dev \
54+
tcl-dev \
55+
tk \
56+
tk-dev \
57+
zlib-dev \
58+
# add build deps before removing fetch deps in case there's overlap
59+
&& apk del .fetch-deps \
60+
\
61+
&& cd /usr/src/python \
62+
&& gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)" \
63+
&& ./configure \
64+
--build="$gnuArch" \
65+
--enable-shared \
66+
--enable-unicode=ucs4 \
67+
&& make -j "$(nproc)" \
68+
# set thread stack size to 1MB so we don't segfault before we hit sys.getrecursionlimit()
69+
# https://github.com/alpinelinux/aports/commit/2026e1259422d4e0cf92391ca2d3844356c649d0
70+
EXTRA_CFLAGS="-DTHREAD_STACK_SIZE=0x100000" \
71+
&& make install \
72+
\
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 \
78+
&& apk del .build-deps \
79+
\
80+
&& find /usr/local -depth \
81+
\( \
82+
\( -type d -a \( -name test -o -name tests \) \) \
83+
-o \
84+
\( -type f -a \( -name '*.pyc' -o -name '*.pyo' \) \) \
85+
\) -exec rm -rf '{}' + \
86+
&& rm -rf /usr/src/python \
87+
\
88+
&& python2 --version
89+
90+
# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'"
91+
ENV PYTHON_PIP_VERSION 10.0.1
92+
93+
RUN set -ex; \
94+
\
95+
apk add --no-cache --virtual .fetch-deps libressl; \
96+
\
97+
wget -O get-pip.py 'https://bootstrap.pypa.io/get-pip.py'; \
98+
\
99+
apk del .fetch-deps; \
100+
\
101+
python get-pip.py \
102+
--disable-pip-version-check \
103+
--no-cache-dir \
104+
"pip==$PYTHON_PIP_VERSION" \
105+
; \
106+
pip --version; \
107+
\
108+
find /usr/local -depth \
109+
\( \
110+
\( -type d -a \( -name test -o -name tests \) \) \
111+
-o \
112+
\( -type f -a \( -name '*.pyc' -o -name '*.pyo' \) \) \
113+
\) -exec rm -rf '{}' +; \
114+
rm -f get-pip.py
115+
116+
CMD ["python2"]

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 \

0 commit comments

Comments
 (0)