Skip to content

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 #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 31, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion 3.5/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down
38 changes: 21 additions & 17 deletions 3.5/alpine/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
FROM alpine:3.3

# gpg: key F73C700D: public key "Larry Hastings <larry@hastings.org>" imported
ENV GPG_KEY 97FC712E4C024BBEA48A61ED3A5CA953F73C700D

ENV PYTHON_VERSION 3.5.1

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

# gpg: key F73C700D: public key "Larry Hastings <larry@hastings.org>" 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 \
Expand All @@ -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) \
Expand All @@ -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 \
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this second sort -u actually necessary? Our while loop has just filtered the output of the first sort, so this one should be a no-op.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, figured out something simpler that skips the loop. 😄

)" \
&& apk add --virtual .python-rundeps $runDeps \
&& apk del .build-deps \
&& rm -rf /usr/src/python

Expand Down
3 changes: 2 additions & 1 deletion 3.5/slim/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down