Skip to content

Commit

Permalink
Merge pull request #311 from infosiftr/refactor-deps-handling
Browse files Browse the repository at this point in the history
Refactor dependencies handling to keep necessary runtime dependencies automatically
  • Loading branch information
yosifkit authored Jul 16, 2018
2 parents 86e133d + c24c7b5 commit ea4449a
Show file tree
Hide file tree
Showing 38 changed files with 1,090 additions and 273 deletions.
10 changes: 9 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,34 @@ services: docker
env:
- VERSION=3.7 VARIANT=stretch
- VERSION=3.7 VARIANT=stretch/slim
- VERSION=3.7 VARIANT=alpine3.8
- VERSION=3.7 VARIANT=alpine3.7
- VERSION=3.6 VARIANT=stretch
- VERSION=3.6 VARIANT=stretch/slim
- VERSION=3.6 VARIANT=jessie
- VERSION=3.6 VARIANT=jessie/slim
- VERSION=3.6 VARIANT=alpine3.8
- VERSION=3.6 VARIANT=alpine3.7
- VERSION=3.6 VARIANT=alpine3.6
- VERSION=3.5 VARIANT=stretch
- VERSION=3.5 VARIANT=stretch/slim
- VERSION=3.5 VARIANT=jessie
- VERSION=3.5 VARIANT=jessie/slim
- VERSION=3.5 VARIANT=alpine3.8
- VERSION=3.5 VARIANT=alpine3.7
- VERSION=3.4 VARIANT=stretch
- VERSION=3.4 VARIANT=stretch/slim
- VERSION=3.4 VARIANT=jessie
- VERSION=3.4 VARIANT=jessie/slim
- VERSION=3.4 VARIANT=wheezy
- VERSION=3.4 VARIANT=alpine3.8
- VERSION=3.4 VARIANT=alpine3.7
- VERSION=2.7 VARIANT=stretch
- VERSION=2.7 VARIANT=stretch/slim
- VERSION=2.7 VARIANT=jessie
- VERSION=2.7 VARIANT=jessie/slim
- VERSION=2.7 VARIANT=wheezy
- VERSION=2.7 VARIANT=alpine3.8
- VERSION=2.7 VARIANT=alpine3.7
- VERSION=2.7 VARIANT=alpine3.6

Expand All @@ -33,6 +40,7 @@ install:

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

Expand All @@ -41,7 +49,7 @@ script:
(
set -Eeuo pipefail
set -x
travis_retry docker build -t "$image" .
docker build -t "$image" .
~/official-images/test/run.sh "$image"
if [ -d onbuild ]; then
onbuildFrom="$(awk 'toupper($1) == "FROM" { print $2; exit }' onbuild/Dockerfile)"
Expand Down
17 changes: 9 additions & 8 deletions 2.7/alpine3.6/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ RUN set -ex \
bzip2-dev \
coreutils \
dpkg-dev dpkg \
findutils \
gcc \
gdbm-dev \
libc-dev \
Expand Down Expand Up @@ -67,13 +68,11 @@ RUN set -ex \
EXTRA_CFLAGS="-DTHREAD_STACK_SIZE=0x100000" \
&& make install \
\
&& runDeps="$( \
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local \
| tr ',' '\n' \
| sort -u \
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
)" \
&& apk add --virtual .python-rundeps $runDeps \
&& find /usr/local -type f -executable -not \( -name '*tkinter*' \) -exec scanelf --needed --nobanner --format '%n#p' '{}' ';' \
| tr ',' '\n' \
| sort -u \
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
| xargs -rt apk add --virtual .python-rundeps \
&& apk del .build-deps \
\
&& find /usr/local -depth \
Expand All @@ -82,7 +81,9 @@ RUN set -ex \
-o \
\( -type f -a \( -name '*.pyc' -o -name '*.pyo' \) \) \
\) -exec rm -rf '{}' + \
&& rm -rf /usr/src/python
&& rm -rf /usr/src/python \
\
&& python2 --version

# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'"
ENV PYTHON_PIP_VERSION 10.0.1
Expand Down
17 changes: 9 additions & 8 deletions 2.7/alpine3.7/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ RUN set -ex \
bzip2-dev \
coreutils \
dpkg-dev dpkg \
findutils \
gcc \
gdbm-dev \
libc-dev \
Expand Down Expand Up @@ -69,13 +70,11 @@ RUN set -ex \
EXTRA_CFLAGS="-DTHREAD_STACK_SIZE=0x100000" \
&& make install \
\
&& runDeps="$( \
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local \
| tr ',' '\n' \
| sort -u \
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
)" \
&& apk add --virtual .python-rundeps $runDeps \
&& find /usr/local -type f -executable -not \( -name '*tkinter*' \) -exec scanelf --needed --nobanner --format '%n#p' '{}' ';' \
| tr ',' '\n' \
| sort -u \
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
| xargs -rt apk add --virtual .python-rundeps \
&& apk del .build-deps \
\
&& find /usr/local -depth \
Expand All @@ -84,7 +83,9 @@ RUN set -ex \
-o \
\( -type f -a \( -name '*.pyc' -o -name '*.pyo' \) \) \
\) -exec rm -rf '{}' + \
&& rm -rf /usr/src/python
&& rm -rf /usr/src/python \
\
&& python2 --version

# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'"
ENV PYTHON_PIP_VERSION 10.0.1
Expand Down
116 changes: 116 additions & 0 deletions 2.7/alpine3.8/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
FROM alpine:3.8

# ensure local python is preferred over distribution python
ENV PATH /usr/local/bin:$PATH

# http://bugs.python.org/issue19846
# > At the moment, setting "LANG=C" on a Linux system *fundamentally breaks Python 3*, and that's not OK.
ENV LANG C.UTF-8
# https://github.com/docker-library/python/issues/147
ENV PYTHONIOENCODING UTF-8

# install ca-certificates so that HTTPS works consistently
# the other runtime dependencies for Python are installed later
RUN apk add --no-cache ca-certificates

ENV GPG_KEY C01E1CAD5EA2C4F0B8E3571504C367C218ADD4FF
ENV PYTHON_VERSION 2.7.15

RUN set -ex \
&& apk add --no-cache --virtual .fetch-deps \
gnupg \
libressl \
tar \
xz \
\
&& wget -O python.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" \
&& wget -O python.tar.xz.asc "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" \
&& export GNUPGHOME="$(mktemp -d)" \
&& gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$GPG_KEY" \
&& gpg --batch --verify python.tar.xz.asc python.tar.xz \
&& rm -rf "$GNUPGHOME" python.tar.xz.asc \
&& mkdir -p /usr/src/python \
&& tar -xJC /usr/src/python --strip-components=1 -f python.tar.xz \
&& rm python.tar.xz \
\
&& apk add --no-cache --virtual .build-deps \
bzip2-dev \
coreutils \
dpkg-dev dpkg \
findutils \
gcc \
gdbm-dev \
libc-dev \
libnsl-dev \
libressl \
libressl-dev \
libtirpc-dev \
linux-headers \
make \
ncurses-dev \
pax-utils \
readline-dev \
sqlite-dev \
tcl-dev \
tk \
tk-dev \
zlib-dev \
# add build deps before removing fetch deps in case there's overlap
&& apk del .fetch-deps \
\
&& cd /usr/src/python \
&& gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)" \
&& ./configure \
--build="$gnuArch" \
--enable-shared \
--enable-unicode=ucs4 \
&& make -j "$(nproc)" \
# set thread stack size to 1MB so we don't segfault before we hit sys.getrecursionlimit()
# https://github.com/alpinelinux/aports/commit/2026e1259422d4e0cf92391ca2d3844356c649d0
EXTRA_CFLAGS="-DTHREAD_STACK_SIZE=0x100000" \
&& make install \
\
&& find /usr/local -type f -executable -not \( -name '*tkinter*' \) -exec scanelf --needed --nobanner --format '%n#p' '{}' ';' \
| tr ',' '\n' \
| sort -u \
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
| xargs -rt apk add --virtual .python-rundeps \
&& apk del .build-deps \
\
&& find /usr/local -depth \
\( \
\( -type d -a \( -name test -o -name tests \) \) \
-o \
\( -type f -a \( -name '*.pyc' -o -name '*.pyo' \) \) \
\) -exec rm -rf '{}' + \
&& rm -rf /usr/src/python \
\
&& python2 --version

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

RUN set -ex; \
\
apk add --no-cache --virtual .fetch-deps libressl; \
\
wget -O get-pip.py 'https://bootstrap.pypa.io/get-pip.py'; \
\
apk del .fetch-deps; \
\
python get-pip.py \
--disable-pip-version-check \
--no-cache-dir \
"pip==$PYTHON_PIP_VERSION" \
; \
pip --version; \
\
find /usr/local -depth \
\( \
\( -type d -a \( -name test -o -name tests \) \) \
-o \
\( -type f -a \( -name '*.pyc' -o -name '*.pyo' \) \) \
\) -exec rm -rf '{}' +; \
rm -f get-pip.py

CMD ["python2"]
14 changes: 2 additions & 12 deletions 2.7/jessie/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,15 @@ ENV LANG C.UTF-8
# https://github.com/docker-library/python/issues/147
ENV PYTHONIOENCODING UTF-8

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

ENV GPG_KEY C01E1CAD5EA2C4F0B8E3571504C367C218ADD4FF
ENV PYTHON_VERSION 2.7.15

RUN set -ex \
&& savedAptMark="$(apt-mark showmanual)" \
&& apt-get update && apt-get install -y --no-install-recommends \
tcl-dev \
tk-dev \
&& rm -rf /var/lib/apt/lists/* \
\
&& wget -O python.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" \
&& wget -O python.tar.xz.asc "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" \
Expand All @@ -45,10 +39,6 @@ RUN set -ex \
&& make install \
&& ldconfig \
\
&& apt-mark auto '.*' > /dev/null \
&& apt-mark manual $savedAptMark \
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
\
&& find /usr/local -depth \
\( \
\( -type d -a \( -name test -o -name tests \) \) \
Expand Down
13 changes: 8 additions & 5 deletions 2.7/jessie/slim/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,14 @@ ENV PYTHONIOENCODING UTF-8
# runtime dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
libgdbm3 \
libreadline6 \
libsqlite3-0 \
libssl1.0.0 \
netbase \
&& rm -rf /var/lib/apt/lists/*

ENV GPG_KEY C01E1CAD5EA2C4F0B8E3571504C367C218ADD4FF
ENV PYTHON_VERSION 2.7.15

RUN set -ex \
\
&& savedAptMark="$(apt-mark showmanual)" \
&& apt-get update && apt-get install -y --no-install-recommends \
dpkg-dev \
Expand All @@ -36,7 +33,6 @@ RUN set -ex \
libsqlite3-dev \
libssl-dev \
make \
tcl-dev \
tk-dev \
wget \
xz-utils \
Expand Down Expand Up @@ -67,6 +63,13 @@ RUN set -ex \
\
&& apt-mark auto '.*' > /dev/null \
&& apt-mark manual $savedAptMark \
&& find /usr/local -type f -executable -not \( -name '*tkinter*' \) -exec ldd '{}' ';' \
| awk '/=>/ { print $(NF-1) }' \
| sort -u \
| xargs -r dpkg-query --search \
| cut -d: -f1 \
| sort -u \
| xargs -r apt-mark manual \
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
\
&& find /usr/local -depth \
Expand Down
14 changes: 2 additions & 12 deletions 2.7/stretch/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,15 @@ ENV LANG C.UTF-8
# https://github.com/docker-library/python/issues/147
ENV PYTHONIOENCODING UTF-8

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

ENV GPG_KEY C01E1CAD5EA2C4F0B8E3571504C367C218ADD4FF
ENV PYTHON_VERSION 2.7.15

RUN set -ex \
&& savedAptMark="$(apt-mark showmanual)" \
&& apt-get update && apt-get install -y --no-install-recommends \
tcl-dev \
tk-dev \
&& rm -rf /var/lib/apt/lists/* \
\
&& wget -O python.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" \
&& wget -O python.tar.xz.asc "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" \
Expand All @@ -45,10 +39,6 @@ RUN set -ex \
&& make install \
&& ldconfig \
\
&& apt-mark auto '.*' > /dev/null \
&& apt-mark manual $savedAptMark \
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
\
&& find /usr/local -depth \
\( \
\( -type d -a \( -name test -o -name tests \) \) \
Expand Down
9 changes: 8 additions & 1 deletion 2.7/stretch/slim/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ ENV GPG_KEY C01E1CAD5EA2C4F0B8E3571504C367C218ADD4FF
ENV PYTHON_VERSION 2.7.15

RUN set -ex \
\
&& savedAptMark="$(apt-mark showmanual)" \
&& apt-get update && apt-get install -y --no-install-recommends \
dpkg-dev \
Expand All @@ -36,7 +37,6 @@ RUN set -ex \
libsqlite3-dev \
libssl-dev \
make \
tcl-dev \
tk-dev \
wget \
xz-utils \
Expand Down Expand Up @@ -67,6 +67,13 @@ RUN set -ex \
\
&& apt-mark auto '.*' > /dev/null \
&& apt-mark manual $savedAptMark \
&& find /usr/local -type f -executable -not \( -name '*tkinter*' \) -exec ldd '{}' ';' \
| awk '/=>/ { print $(NF-1) }' \
| sort -u \
| xargs -r dpkg-query --search \
| cut -d: -f1 \
| sort -u \
| xargs -r apt-mark manual \
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
\
&& find /usr/local -depth \
Expand Down
Loading

0 comments on commit ea4449a

Please sign in to comment.