Skip to content

Commit b7ef92d

Browse files
committed
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 parent e677b04 commit b7ef92d

File tree

3 files changed

+27
-19
lines changed

3 files changed

+27
-19
lines changed

3.5/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ ENV PYTHON_VERSION 3.5.1
1616
ENV PYTHON_PIP_VERSION 7.1.2
1717

1818
RUN set -x \
19-
&& mkdir -p /usr/src/python \
2019
&& curl -fSL "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" -o python.tar.xz \
2120
&& curl -fSL "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" -o python.tar.xz.asc \
2221
&& gpg --verify python.tar.xz.asc \
22+
&& mkdir -p /usr/src/python \
2323
&& tar -xJC /usr/src/python --strip-components=1 -f python.tar.xz \
2424
&& rm python.tar.xz* \
25+
\
2526
&& cd /usr/src/python \
2627
&& ./configure --enable-shared --enable-unicode=ucs4 \
2728
&& make -j$(nproc) \

3.5/alpine/Dockerfile

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
FROM alpine:3.3
22

3+
# gpg: key F73C700D: public key "Larry Hastings <larry@hastings.org>" imported
4+
ENV GPG_KEY 97FC712E4C024BBEA48A61ED3A5CA953F73C700D
5+
36
ENV PYTHON_VERSION 3.5.1
47

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

8-
# gpg: key F73C700D: public key "Larry Hastings <larry@hastings.org>" imported
9-
ENV GPG_KEY 97FC712E4C024BBEA48A61ED3A5CA953F73C700D
10-
11-
RUN apk add --no-cache --virtual .fetch-deps curl gnupg \
12-
&& gpg --keyserver ha.pool.sks-keyservers.net --recv-keys $GPG_KEY \
11+
RUN set -ex \
12+
&& apk add --no-cache --virtual .fetch-deps curl gnupg \
13+
&& gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$GPG_KEY" \
1314
&& curl -fSL "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" -o python.tar.xz \
1415
&& curl -fSL "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" -o python.tar.xz.asc \
1516
&& gpg --verify python.tar.xz.asc \
16-
&& mkdir -p /usr/src/ \
17+
&& mkdir -p /usr/src \
1718
&& tar -xJC /usr/src -f python.tar.xz \
18-
&& mv /usr/src/Python-${PYTHON_VERSION} /usr/src/python \
19+
&& mv "/usr/src/Python-$PYTHON_VERSION" /usr/src/python \
1920
&& rm python.tar.xz* \
20-
&& apk del .fetch-deps
21-
22-
RUN apk add --no-cache --virtual .build-deps \
21+
&& apk del .fetch-deps \
22+
&& rm -r ~/.gnupg \
23+
\
24+
&& apk add --no-cache --virtual .build-deps \
2325
bzip2-dev \
2426
gcc \
2527
libc-dev \
@@ -28,9 +30,9 @@ RUN apk add --no-cache --virtual .build-deps \
2830
make \
2931
ncurses-dev \
3032
openssl-dev \
33+
pax-utils \
3134
sqlite-dev \
3235
zlib-dev \
33-
pax-utils \
3436
&& cd /usr/src/python \
3537
&& ./configure --enable-shared --enable-unicode=ucs4 \
3638
&& make -j$(getconf _NPROCESSORS_ONLN) \
@@ -40,12 +42,16 @@ RUN apk add --no-cache --virtual .build-deps \
4042
\( -type d -a -name test -o -name tests \) \
4143
-o \( -type f -a -name '*.pyc' -o -name '*.pyo' \) \
4244
-exec rm -rf '{}' + \
43-
&& rundeps=$(scanelf -R -n --nobanner /usr/local/ \
44-
| awk '{gsub(/,/,"\n",$2); print $2}' \
45-
| sort -u | sed 's/^/so:/' | while read dep; do \
46-
apk info --installed -q $dep && echo $dep; \
47-
done | sort -u) \
48-
&& apk add --virtual .python-rundeps $rundeps \
45+
&& runDeps="$( \
46+
scanelf --needed --nobanner --recursive /usr/local \
47+
| awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \
48+
| sort -u \
49+
| while read dep; do \
50+
apk info --installed -q "$dep" && echo "$dep"; \
51+
done \
52+
| sort -u \
53+
)" \
54+
&& apk add --virtual .python-rundeps $runDeps \
4955
&& apk del .build-deps \
5056
&& rm -rf /usr/src/python
5157

3.5/slim/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@ RUN set -x \
3636
zlib1g-dev \
3737
' \
3838
&& apt-get update && apt-get install -y $buildDeps --no-install-recommends && rm -rf /var/lib/apt/lists/* \
39-
&& mkdir -p /usr/src/python \
4039
&& curl -fSL "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" -o python.tar.xz \
4140
&& curl -fSL "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" -o python.tar.xz.asc \
4241
&& gpg --verify python.tar.xz.asc \
42+
&& mkdir -p /usr/src/python \
4343
&& tar -xJC /usr/src/python --strip-components=1 -f python.tar.xz \
4444
&& rm python.tar.xz* \
45+
\
4546
&& cd /usr/src/python \
4647
&& ./configure --enable-shared --enable-unicode=ucs4 \
4748
&& make -j$(nproc) \

0 commit comments

Comments
 (0)