From 1c4831ea8e26f08020a8a355aca619d425d6d482 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Fri, 18 Dec 2015 16:40:15 +0100 Subject: [PATCH 1/5] Add 3.5/alpine variant --- 3.5/alpine/Dockerfile | 63 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 3.5/alpine/Dockerfile diff --git a/3.5/alpine/Dockerfile b/3.5/alpine/Dockerfile new file mode 100644 index 000000000..cdbcf71f7 --- /dev/null +++ b/3.5/alpine/Dockerfile @@ -0,0 +1,63 @@ +FROM alpine:edge + +RUN apk add -u --no-cache gnupg + +# gpg: key F73C700D: public key "Larry Hastings " imported +RUN gpg --keyserver ha.pool.sks-keyservers.net --recv-keys 97FC712E4C024BBEA48A61ED3A5CA953F73C700D + +ENV PYTHON_VERSION 3.5.1 + +# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value ''" +ENV PYTHON_PIP_VERSION 7.1.2 + +RUN set -x -e ;\ + build_deps=' \ + bzip2-dev \ + curl \ + gcc \ + libc-dev \ + libedit-dev \ + linux-headers \ + make \ + make \ + ncurses-dev \ + openssl-dev \ + sqlite-dev \ + zlib-dev \ + pax-utils \ + ' \ + && apk add --no-cache --virtual .build-deps $build_deps \ + && mkdir -p /usr/src/ \ + && curl -SL "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" -o python.tar.xz \ + && curl -SL "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" -o python.tar.xz.asc \ + && gpg --verify python.tar.xz.asc \ + && tar -xJC /usr/src -f python.tar.xz \ + && mv /usr/src/Python-${PYTHON_VERSION} /usr/src/python \ + && rm python.tar.xz* \ + && cd /usr/src/python \ + && ./configure --enable-shared --enable-unicode=ucs4 \ + && make -j$(getconf _NPROCESSORS_ONLN) \ + && make install \ + && pip3 install --no-cache-dir --upgrade --ignore-installed pip==$PYTHON_PIP_VERSION \ + && find /usr/local \ + \( -type d -a -name test -o -name tests \) \ + -o \( -type f -a -name '*.pyc' -o -name '*.pyo' \) \ + -exec rm -rf '{}' + \ + && rundeps=$(scanelf -R -n --nobanner /usr/local/ \ + | awk '{gsub(/,/,"\n",$2); print $2}' \ + | sort -u | sed 's/^/so:/' | while read dep; do \ + apk info --installed -q $dep && echo $dep; \ + done | sort -u) \ + && apk add --virtual .python-rundeps $rundeps \ + && apk del .build-deps gnupg \ + && rm -rf /usr/src/python + +# make some useful symlinks that are expected to exist +RUN cd /usr/local/bin \ + && ln -s easy_install-3.5 easy_install \ + && ln -s idle3 idle \ + && ln -s pydoc3 pydoc \ + && ln -s python3 python \ + && ln -s python-config3 python-config + +CMD ["python3"] From c43ed837d3d7f49a74f99278009b7bc65e26afa7 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Tue, 29 Dec 2015 12:10:51 +0100 Subject: [PATCH 2/5] alpine: Run fetch and gpg verify into same build step --- 3.5/alpine/Dockerfile | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/3.5/alpine/Dockerfile b/3.5/alpine/Dockerfile index cdbcf71f7..9f6242453 100644 --- a/3.5/alpine/Dockerfile +++ b/3.5/alpine/Dockerfile @@ -1,39 +1,36 @@ -FROM alpine:edge - -RUN apk add -u --no-cache gnupg - -# gpg: key F73C700D: public key "Larry Hastings " imported -RUN gpg --keyserver ha.pool.sks-keyservers.net --recv-keys 97FC712E4C024BBEA48A61ED3A5CA953F73C700D +FROM alpine:3.3 ENV PYTHON_VERSION 3.5.1 # if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value ''" ENV PYTHON_PIP_VERSION 7.1.2 -RUN set -x -e ;\ - build_deps=' \ +# gpg: key F73C700D: public key "Larry Hastings " imported +ENV GPG_KEY 97FC712E4C024BBEA48A61ED3A5CA953F73C700D + +RUN apk add --no-cache --virtual .fetch-deps curl gnupg \ + && gpg --keyserver ha.pool.sks-keyservers.net --recv-keys $GPG_KEY \ + && curl -fSL "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" -o python.tar.xz \ + && curl -fSL "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" -o python.tar.xz.asc \ + && gpg --verify python.tar.xz.asc \ + && mkdir -p /usr/src/ \ + && tar -xJC /usr/src -f python.tar.xz \ + && mv /usr/src/Python-${PYTHON_VERSION} /usr/src/python \ + && rm python.tar.xz* \ + && apk del .fetch-deps + +RUN apk add --no-cache --virtual .build-deps \ bzip2-dev \ - curl \ gcc \ libc-dev \ libedit-dev \ linux-headers \ make \ - make \ ncurses-dev \ openssl-dev \ sqlite-dev \ zlib-dev \ pax-utils \ - ' \ - && apk add --no-cache --virtual .build-deps $build_deps \ - && mkdir -p /usr/src/ \ - && curl -SL "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" -o python.tar.xz \ - && curl -SL "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" -o python.tar.xz.asc \ - && gpg --verify python.tar.xz.asc \ - && tar -xJC /usr/src -f python.tar.xz \ - && mv /usr/src/Python-${PYTHON_VERSION} /usr/src/python \ - && rm python.tar.xz* \ && cd /usr/src/python \ && ./configure --enable-shared --enable-unicode=ucs4 \ && make -j$(getconf _NPROCESSORS_ONLN) \ From d254b787381995fa9d54e858d080eb1d4f026d80 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Tue, 29 Dec 2015 12:13:25 +0100 Subject: [PATCH 3/5] add alpine to travis config --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 56cc07d27..192c37286 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,7 @@ services: docker env: - VERSION=3.5 VARIANT= - VERSION=3.5 VARIANT=slim + - VERSION=3.5 VARIANT=alpine - VERSION=3.4 VARIANT= - VERSION=3.4 VARIANT=slim - VERSION=3.4 VARIANT=wheezy From e677b04e461fb4314eb38e456cc2735a0a3a2ae6 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Tue, 29 Dec 2015 13:28:01 +0100 Subject: [PATCH 4/5] 3.5/alpine: fix uninstall of build time deps don't uninstall gnupg twice --- 3.5/alpine/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3.5/alpine/Dockerfile b/3.5/alpine/Dockerfile index 9f6242453..e8cb660c7 100644 --- a/3.5/alpine/Dockerfile +++ b/3.5/alpine/Dockerfile @@ -46,7 +46,7 @@ RUN apk add --no-cache --virtual .build-deps \ apk info --installed -q $dep && echo $dep; \ done | sort -u) \ && apk add --virtual .python-rundeps $rundeps \ - && apk del .build-deps gnupg \ + && apk del .build-deps \ && rm -rf /usr/src/python # make some useful symlinks that are expected to exist From 9c5b00f106e87639857134945d87fc7fca5e02f9 Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Wed, 30 Dec 2015 15:28:53 -0800 Subject: [PATCH 5/5] Adjust whitespace for better symmetry between Dockerfiles and cut image size in half by keeping fetch and compile in the same layer so the Python source goes away properly Before: ~163.2 MB After: ~89.05 MB --- 3.5/Dockerfile | 3 ++- 3.5/alpine/Dockerfile | 38 +++++++++++++++++++++----------------- 3.5/slim/Dockerfile | 3 ++- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/3.5/Dockerfile b/3.5/Dockerfile index 880fb05da..eaf89f4d3 100644 --- a/3.5/Dockerfile +++ b/3.5/Dockerfile @@ -16,12 +16,13 @@ ENV PYTHON_VERSION 3.5.1 ENV PYTHON_PIP_VERSION 7.1.2 RUN set -x \ - && mkdir -p /usr/src/python \ && curl -fSL "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" -o python.tar.xz \ && curl -fSL "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" -o python.tar.xz.asc \ && gpg --verify 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* \ + \ && cd /usr/src/python \ && ./configure --enable-shared --enable-unicode=ucs4 \ && make -j$(nproc) \ diff --git a/3.5/alpine/Dockerfile b/3.5/alpine/Dockerfile index e8cb660c7..4228ccec5 100644 --- a/3.5/alpine/Dockerfile +++ b/3.5/alpine/Dockerfile @@ -1,25 +1,27 @@ FROM alpine:3.3 +# gpg: key F73C700D: public key "Larry Hastings " imported +ENV GPG_KEY 97FC712E4C024BBEA48A61ED3A5CA953F73C700D + ENV PYTHON_VERSION 3.5.1 # if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value ''" ENV PYTHON_PIP_VERSION 7.1.2 -# gpg: key F73C700D: public key "Larry Hastings " imported -ENV GPG_KEY 97FC712E4C024BBEA48A61ED3A5CA953F73C700D - -RUN apk add --no-cache --virtual .fetch-deps curl gnupg \ - && gpg --keyserver ha.pool.sks-keyservers.net --recv-keys $GPG_KEY \ +RUN set -ex \ + && apk add --no-cache --virtual .fetch-deps curl gnupg \ + && gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$GPG_KEY" \ && curl -fSL "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" -o python.tar.xz \ && curl -fSL "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" -o python.tar.xz.asc \ && gpg --verify python.tar.xz.asc \ - && mkdir -p /usr/src/ \ + && mkdir -p /usr/src \ && tar -xJC /usr/src -f python.tar.xz \ - && mv /usr/src/Python-${PYTHON_VERSION} /usr/src/python \ + && mv "/usr/src/Python-$PYTHON_VERSION" /usr/src/python \ && rm python.tar.xz* \ - && apk del .fetch-deps - -RUN apk add --no-cache --virtual .build-deps \ + && apk del .fetch-deps \ + && rm -r ~/.gnupg \ + \ + && apk add --no-cache --virtual .build-deps \ bzip2-dev \ gcc \ libc-dev \ @@ -28,9 +30,9 @@ RUN apk add --no-cache --virtual .build-deps \ make \ ncurses-dev \ openssl-dev \ + pax-utils \ sqlite-dev \ zlib-dev \ - pax-utils \ && cd /usr/src/python \ && ./configure --enable-shared --enable-unicode=ucs4 \ && make -j$(getconf _NPROCESSORS_ONLN) \ @@ -40,12 +42,14 @@ RUN apk add --no-cache --virtual .build-deps \ \( -type d -a -name test -o -name tests \) \ -o \( -type f -a -name '*.pyc' -o -name '*.pyo' \) \ -exec rm -rf '{}' + \ - && rundeps=$(scanelf -R -n --nobanner /usr/local/ \ - | awk '{gsub(/,/,"\n",$2); print $2}' \ - | sort -u | sed 's/^/so:/' | while read dep; do \ - apk info --installed -q $dep && echo $dep; \ - done | sort -u) \ - && apk add --virtual .python-rundeps $rundeps \ + && runDeps="$( \ + scanelf --needed --nobanner --recursive /usr/local \ + | awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \ + | sort -u \ + | xargs -r apk info --installed \ + | sort -u \ + )" \ + && apk add --virtual .python-rundeps $runDeps \ && apk del .build-deps \ && rm -rf /usr/src/python diff --git a/3.5/slim/Dockerfile b/3.5/slim/Dockerfile index 390913e61..336afb633 100644 --- a/3.5/slim/Dockerfile +++ b/3.5/slim/Dockerfile @@ -36,12 +36,13 @@ RUN set -x \ zlib1g-dev \ ' \ && apt-get update && apt-get install -y $buildDeps --no-install-recommends && rm -rf /var/lib/apt/lists/* \ - && mkdir -p /usr/src/python \ && curl -fSL "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" -o python.tar.xz \ && curl -fSL "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" -o python.tar.xz.asc \ && gpg --verify 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* \ + \ && cd /usr/src/python \ && ./configure --enable-shared --enable-unicode=ucs4 \ && make -j$(nproc) \