Add a few simple Python 3 templates based on existing Dockerfiles#139
Merged
yosifkit merged 3 commits intodocker-library:masterfrom Aug 8, 2016
Merged
Add a few simple Python 3 templates based on existing Dockerfiles#139yosifkit merged 3 commits intodocker-library:masterfrom
yosifkit merged 3 commits intodocker-library:masterfrom
Conversation
Member
Author
Member
Author
|
And a slightly easier to review view of that first commit: $ git log -p -1 -C -C -C 5bfe66dd879e8fa3a6744ad444b6315acca2a490
commit 5bfe66dd879e8fa3a6744ad444b6315acca2a490
Author: Tianon Gravi <admwiggin@gmail.com>
Date: Mon Aug 8 13:50:03 2016 -0700
Add a few simple Python 3 templates based on existing Dockerfiles
diff --git a/3.5/alpine/Dockerfile b/Dockerfile-alpine.template
similarity index 63%
copy from 3.5/alpine/Dockerfile
copy to Dockerfile-alpine.template
index f21e0b7..015a88b 100644
--- a/3.5/alpine/Dockerfile
+++ b/Dockerfile-alpine.template
@@ -1,5 +1,8 @@
FROM alpine:3.4
+# ensure local python is used over alpine 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
@@ -8,18 +11,21 @@ ENV LANG C.UTF-8
# the other runtime dependencies for Python are installed later
RUN apk add --no-cache ca-certificates
-# gpg: key F73C700D: public key "Larry Hastings <larry@hastings.org>" imported
-ENV GPG_KEY 97FC712E4C024BBEA48A61ED3A5CA953F73C700D
-
-ENV PYTHON_VERSION 3.5.2
+ENV GPG_KEY %%PLACEHOLDER%%
+ENV PYTHON_VERSION %%PLACEHOLDER%%
# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'"
-ENV PYTHON_PIP_VERSION 8.1.2
+ENV PYTHON_PIP_VERSION %%PLACEHOLDER%%
RUN set -ex \
- && apk add --no-cache --virtual .fetch-deps curl gnupg tar xz \
- && 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 \
+ && apk add --no-cache --virtual .fetch-deps \
+ gnupg \
+ openssl \
+ 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 \
@@ -27,7 +33,6 @@ RUN set -ex \
&& mkdir -p /usr/src/python \
&& tar -xJC /usr/src/python --strip-components=1 -f python.tar.xz \
&& rm python.tar.xz \
- && apk del .fetch-deps \
\
&& apk add --no-cache --virtual .build-deps \
bzip2-dev \
@@ -36,6 +41,7 @@ RUN set -ex \
linux-headers \
make \
ncurses-dev \
+ openssl \
openssl-dev \
pax-utils \
readline-dev \
@@ -45,14 +51,25 @@ RUN set -ex \
tk-dev \
xz-dev \
zlib-dev \
+# add build deps before removing fetch deps in case there's overlap
+ && apk del .fetch-deps \
+ \
&& cd /usr/src/python \
&& ./configure \
--enable-loadable-sqlite-extensions \
--enable-shared \
&& make -j$(getconf _NPROCESSORS_ONLN) \
&& make install \
- && pip3 install --no-cache-dir --upgrade pip==$PYTHON_PIP_VERSION \
- && [ "$(pip list | awk -F '[ ()]+' '$1 == "pip" { print $2; exit }')" = "$PYTHON_PIP_VERSION" ] \
+ \
+# explicit path to "pip3" to ensure Debian "pip3" cannot interfere
+ && if [ ! -e /usr/local/bin/pip3 ]; then : \
+ && wget -O /tmp/get-pip.py 'https://bootstrap.pypa.io/get-pip.py' \
+ && python3 /tmp/get-pip.py "pip==$PYTHON_PIP_VERSION" \
+ && rm /tmp/get-pip.py \
+ ; fi \
+ && pip3 install --no-cache-dir --upgrade "pip==$PYTHON_PIP_VERSION" \
+ && [ "$(pip list |tac|tac| awk -F '[ ()]+' '$1 == "pip" { print $2; exit }')" = "$PYTHON_PIP_VERSION" ] \
+ \
&& find /usr/local -depth \
\( \
\( -type d -a -name test -o -name tests \) \
@@ -72,7 +89,7 @@ RUN set -ex \
# make some useful symlinks that are expected to exist
RUN cd /usr/local/bin \
- && ln -s easy_install-3.5 easy_install \
+ && { [ -e easy_install ] || ln -s easy_install-* easy_install; } \
&& ln -s idle3 idle \
&& ln -s pydoc3 pydoc \
&& ln -s python3 python \
diff --git a/3.5/slim/Dockerfile b/Dockerfile-debian.template
similarity index 62%
copy from 3.5/slim/Dockerfile
copy to Dockerfile-debian.template
index 4a5ed56..6aec3bc 100644
--- a/3.5/slim/Dockerfile
+++ b/Dockerfile-debian.template
@@ -1,4 +1,4 @@
-FROM debian:jessie
+FROM buildpack-deps:jessie
# ensure local python is used over debian python
ENV PATH /usr/local/bin:$PATH
@@ -7,40 +7,27 @@ ENV PATH /usr/local/bin:$PATH
# > At the moment, setting "LANG=C" on a Linux system *fundamentally breaks Python 3*, and that's not OK.
ENV LANG C.UTF-8
+# runtime dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
- ca-certificates \
- libsqlite3-0 \
- libssl1.0.0 \
+ tcl \
+ tk \
&& rm -rf /var/lib/apt/lists/*
-# gpg: key F73C700D: public key "Larry Hastings <larry@hastings.org>" imported
-ENV GPG_KEY 97FC712E4C024BBEA48A61ED3A5CA953F73C700D
-
-ENV PYTHON_VERSION 3.5.2
+ENV GPG_KEY %%PLACEHOLDER%%
+ENV PYTHON_VERSION %%PLACEHOLDER%%
# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'"
-ENV PYTHON_PIP_VERSION 8.1.2
+ENV PYTHON_PIP_VERSION %%PLACEHOLDER%%
RUN set -ex \
&& buildDeps=' \
- curl \
- gcc \
- libbz2-dev \
- libc6-dev \
- liblzma-dev \
- libncurses-dev \
- libreadline-dev \
- libsqlite3-dev \
- libssl-dev \
- make \
tcl-dev \
tk-dev \
- xz-utils \
- zlib1g-dev \
' \
&& apt-get update && apt-get install -y $buildDeps --no-install-recommends && rm -rf /var/lib/apt/lists/* \
- && 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 \
+ \
+ && 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 \
@@ -56,8 +43,16 @@ RUN set -ex \
&& make -j$(nproc) \
&& make install \
&& ldconfig \
- && pip3 install --no-cache-dir --upgrade pip==$PYTHON_PIP_VERSION \
- && [ "$(pip list | awk -F '[ ()]+' '$1 == "pip" { print $2; exit }')" = "$PYTHON_PIP_VERSION" ] \
+ \
+# explicit path to "pip3" to ensure Debian "pip3" cannot interfere
+ && if [ ! -e /usr/local/bin/pip3 ]; then : \
+ && wget -O /tmp/get-pip.py 'https://bootstrap.pypa.io/get-pip.py' \
+ && python3 /tmp/get-pip.py "pip==$PYTHON_PIP_VERSION" \
+ && rm /tmp/get-pip.py \
+ ; fi \
+ && pip3 install --no-cache-dir --upgrade "pip==$PYTHON_PIP_VERSION" \
+ && [ "$(pip list |tac|tac| awk -F '[ ()]+' '$1 == "pip" { print $2; exit }')" = "$PYTHON_PIP_VERSION" ] \
+ \
&& find /usr/local -depth \
\( \
\( -type d -a -name test -o -name tests \) \
@@ -69,7 +64,7 @@ RUN set -ex \
# make some useful symlinks that are expected to exist
RUN cd /usr/local/bin \
- && ln -s easy_install-3.5 easy_install \
+ && { [ -e easy_install ] || ln -s easy_install-* easy_install; } \
&& ln -s idle3 idle \
&& ln -s pydoc3 pydoc \
&& ln -s python3 python \
diff --git a/3.3/onbuild/Dockerfile b/Dockerfile-onbuild.template
similarity index 86%
copy from 3.3/onbuild/Dockerfile
copy to Dockerfile-onbuild.template
index b200ef8..2950ec1 100644
--- a/3.3/onbuild/Dockerfile
+++ b/Dockerfile-onbuild.template
@@ -1,4 +1,4 @@
-FROM python:3.3
+FROM python:%%PLACEHOLDER%%
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
diff --git a/3.6/slim/Dockerfile b/Dockerfile-slim.template
similarity index 66%
copy from 3.6/slim/Dockerfile
copy to Dockerfile-slim.template
index 5ceb89d..0c3736f 100644
--- a/3.6/slim/Dockerfile
+++ b/Dockerfile-slim.template
@@ -7,23 +7,21 @@ ENV PATH /usr/local/bin:$PATH
# > At the moment, setting "LANG=C" on a Linux system *fundamentally breaks Python 3*, and that's not OK.
ENV LANG C.UTF-8
+# runtime dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
libsqlite3-0 \
libssl1.0.0 \
&& rm -rf /var/lib/apt/lists/*
-# gpg: key AA65421D: public key "Ned Deily (Python release signing key) <nad@acm.org>" imported
-ENV GPG_KEY 0D96DF4D4110E5C43FBFB17F2D347EA6AA65421D
-
-ENV PYTHON_VERSION 3.6.0a3
+ENV GPG_KEY %%PLACEHOLDER%%
+ENV PYTHON_VERSION %%PLACEHOLDER%%
# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'"
-ENV PYTHON_PIP_VERSION 8.1.2
+ENV PYTHON_PIP_VERSION %%PLACEHOLDER%%
RUN set -ex \
&& buildDeps=' \
- curl \
gcc \
libbz2-dev \
libc6-dev \
@@ -35,12 +33,14 @@ RUN set -ex \
make \
tcl-dev \
tk-dev \
+ wget \
xz-utils \
zlib1g-dev \
' \
&& apt-get update && apt-get install -y $buildDeps --no-install-recommends && rm -rf /var/lib/apt/lists/* \
- && 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 \
+ \
+ && 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 \
@@ -56,8 +56,16 @@ RUN set -ex \
&& make -j$(nproc) \
&& make install \
&& ldconfig \
- && pip3 install --no-cache-dir --upgrade pip==$PYTHON_PIP_VERSION \
- && [ "$(pip list | awk -F '[ ()]+' '$1 == "pip" { print $2; exit }')" = "$PYTHON_PIP_VERSION" ] \
+ \
+# explicit path to "pip3" to ensure Debian "pip3" cannot interfere
+ && if [ ! -e /usr/local/bin/pip3 ]; then : \
+ && wget -O /tmp/get-pip.py 'https://bootstrap.pypa.io/get-pip.py' \
+ && python3 /tmp/get-pip.py "pip==$PYTHON_PIP_VERSION" \
+ && rm /tmp/get-pip.py \
+ ; fi \
+ && pip3 install --no-cache-dir --upgrade "pip==$PYTHON_PIP_VERSION" \
+ && [ "$(pip list |tac|tac| awk -F '[ ()]+' '$1 == "pip" { print $2; exit }')" = "$PYTHON_PIP_VERSION" ] \
+ \
&& find /usr/local -depth \
\( \
\( -type d -a -name test -o -name tests \) \
@@ -69,7 +77,7 @@ RUN set -ex \
# make some useful symlinks that are expected to exist
RUN cd /usr/local/bin \
- && ln -s easy_install-3.6 easy_install \
+ && { [ -e easy_install ] || ln -s easy_install-* easy_install; } \
&& ln -s idle3 idle \
&& ln -s pydoc3 pydoc \
&& ln -s python3 python \
diff --git a/update.sh b/update.sh
index 937bf37..3a363a6 100755
--- a/update.sh
+++ b/update.sh
@@ -1,6 +1,28 @@
#!/bin/bash
set -e
+declare -A gpgKeys=(
+ # gpg: key 18ADD4FF: public key "Benjamin Peterson <benjamin@python.org>" imported
+ [2.7]='C01E1CAD5EA2C4F0B8E3571504C367C218ADD4FF'
+ # https://www.python.org/dev/peps/pep-0373/#release-manager-and-crew
+
+ # gpg: key 36580288: public key "Georg Brandl (Python release signing key) <georg@python.org>" imported
+ [3.3]='26DEA9D4613391EF3E25C9FF0A5B101836580288'
+ # https://www.python.org/dev/peps/pep-0398/#release-manager-and-crew
+
+ # gpg: key F73C700D: public key "Larry Hastings <larry@hastings.org>" imported
+ [3.4]='97FC712E4C024BBEA48A61ED3A5CA953F73C700D'
+ # https://www.python.org/dev/peps/pep-0429/#release-manager-and-crew
+
+ # gpg: key F73C700D: public key "Larry Hastings <larry@hastings.org>" imported
+ [3.5]='97FC712E4C024BBEA48A61ED3A5CA953F73C700D'
+ # https://www.python.org/dev/peps/pep-0478/#release-manager-and-crew
+
+ # gpg: key AA65421D: public key "Ned Deily (Python release signing key) <nad@acm.org>" imported
+ [3.6]='0D96DF4D4110E5C43FBFB17F2D347EA6AA65421D'
+ # https://www.python.org/dev/peps/pep-0494/#release-manager-and-crew
+)
+
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
versions=( "$@" )
@@ -11,6 +33,17 @@ versions=( "${versions[@]%/}" )
pipVersion="$(curl -fsSL 'https://pypi.python.org/pypi/pip/json' | awk -F '"' '$2 == "version" { print $4 }')"
+generated_warning() {
+ cat <<-EOH
+ #
+ # NOTE: THIS DOCKERFILE IS GENERATED VIA "update.sh"
+ #
+ # PLEASE DO NOT EDIT IT DIRECTLY.
+ #
+
+ EOH
+}
+
travisEnv=
for version in "${versions[@]}"; do
# <span class="release-number"><a href="/downloads/release/python-278/">Python 2.7.8</a></span>
@@ -26,13 +59,34 @@ for version in "${versions[@]}"; do
echo
} >&2
else
+ if [[ "$version" != 2.* ]]; then
+ for variant in \
+ debian \
+ alpine \
+ slim \
+ onbuild \
+ ; do
+ if [ "$variant" = 'debian' ]; then
+ dir="$version"
+ else
+ dir="$version/$variant"
+ fi
+ template="Dockerfile-$variant.template"
+ { generated_warning; cat "$template"; } > "$dir/Dockerfile"
+ done
+ if [ -d "$version/wheezy" ]; then
+ cp "$version/Dockerfile" "$version/wheezy/Dockerfile"
+ sed -ri 's/:jessie/:wheezy/g' "$version/wheezy/Dockerfile"
+ fi
+ fi
(
set -x
- sed -ri '
- s/^(ENV PYTHON_VERSION) .*/\1 '"$fullVersion"'/;
- s/^(ENV PYTHON_PIP_VERSION) .*/\1 '"$pipVersion"'/;
- ' "$version"/{,*/}Dockerfile
- sed -ri 's/^(FROM python):.*/\1:'"$version"'/' "$version/onbuild/Dockerfile"
+ sed -ri \
+ -e 's/^(ENV GPG_KEY) .*/\1 '"${gpgKeys[$version]}"'/' \
+ -e 's/^(ENV PYTHON_VERSION) .*/\1 '"$fullVersion"'/' \
+ -e 's/^(ENV PYTHON_PIP_VERSION) .*/\1 '"$pipVersion"'/' \
+ -e 's/^(FROM python):.*/\1:'"$version"'/' \
+ "$version"/{,*/}Dockerfile
)
fi
for variant in wheezy alpine slim; do |
Member
Author
|
Green! |
Dockerfile-alpine.template
Outdated
| && make -j$(getconf _NPROCESSORS_ONLN) \ | ||
| && make install \ | ||
| \ | ||
| # explicit path to "pip3" to ensure Debian "pip3" cannot interfere |
Member
There was a problem hiding this comment.
"Debian version"? Maybe we should just say distribution instead of alpine/debian to keep the diff small between the two.
This is just in a comment so it doesn't really matter. I'm just being pedantic.
Member
Author
|
Worth noting that Travis failing on 2.7 |
Member
|
LGTM |
tianon
added a commit
to infosiftr/stackbrew
that referenced
this pull request
Aug 9, 2016
- `elasticsearch`: 5.0.0-alpha5 (docker-library/elasticsearch#113) - `php`: `/etc/apache2/envvars` tweaks (docker-library/php#282), `--enable-ftp` (docker-library/php#287) - `piwik`: swap from merge commit to commit with substance (direct output of `generate-stackbrew-library.sh`) - `python`: templates (docker-library/python#139), fix `import dbm` (docker-library/python#140)
tianon
added a commit
to infosiftr/stackbrew
that referenced
this pull request
Aug 9, 2016
- `elasticsearch`: 5.0.0-alpha5 (docker-library/elasticsearch#113) - `piwik`: swap from merge commit to commit with substance (direct output of `generate-stackbrew-library.sh`) - `python`: templates (docker-library/python#139), fix `import dbm` (docker-library/python#140)
3 tasks
JayH5
added a commit
to praekeltfoundation/docker-alpine-python
that referenced
this pull request
Aug 10, 2016
JayH5
added a commit
to JayH5/pypy
that referenced
this pull request
Sep 1, 2016
JayH5
added a commit
to JayH5/pypy
that referenced
this pull request
Sep 1, 2016
* Most of the rest of docker-library/python#139
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds templates for the bulk of the
Dockerfiles here (those based on Python 3), notably excluding 2.7 (not worth mucking the templates for) and 3.6 (not yet officially released, and thus not 100% supported byupdate.shyet).I've also applied some/most of the template changes manually against 2.7 and 3.6 to ensure continued parity.