Skip to content

Commit cf5cb69

Browse files
committed
Refactor images per #25
1 parent 93c5c37 commit cf5cb69

File tree

10 files changed

+342
-210
lines changed

10 files changed

+342
-210
lines changed

2.7-onbuild/Dockerfile

Lines changed: 67 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
FROM alpine:3.7
22

3-
ENV ALPINE_VERSION=3.7
3+
# VERSIONS
4+
ENV ALPINE_VERSION=3.7 \
5+
PYTHON_VERSION=2.7.14
46

5-
# Install needed packages. Notes:
7+
# PATHS
8+
ENV PYTHON_PATH=/usr/lib/python$PYTHON_VERSION \
9+
PATH="/usr/lib/python$PYTHON_VERSION/bin/:${PATH}"
10+
11+
# PACKAGES
612
# * dumb-init: a proper init system for containers, to reap zombie children
713
# * musl: standard C library
814
# * lib6-compat: compatibility libraries for glibc
@@ -11,49 +17,72 @@ ENV ALPINE_VERSION=3.7
1117
# * bash: so we can access /bin/bash
1218
# * git: to ease up clones of repos
1319
# * ca-certificates: for SSL verification during Pip and easy_install
14-
# * python: the binaries themselves
15-
# * python-dev: are used for gevent e.g.
16-
# * py-setuptools: required only in major version 2, installs easy_install so we can install Pip.
1720
ENV PACKAGES="\
18-
dumb-init \
19-
musl \
20-
libc6-compat \
21-
linux-headers \
22-
build-base \
23-
bash \
24-
git \
25-
ca-certificates \
26-
python2 \
27-
python2-dev \
28-
py-setuptools \
21+
dumb-init \
22+
musl \
23+
libc6-compat \
24+
linux-headers \
25+
build-base \
26+
bash \
27+
git \
28+
ca-certificates \
29+
"
30+
31+
# PACKAGES needed to built python
32+
ENV PYTHON_BUILD_PACKAGES="\
33+
readline-dev \
34+
zlib-dev \
35+
bzip2-dev \
36+
sqlite-dev \
37+
libressl-dev \
2938
"
3039

31-
RUN echo \
32-
# replacing default repositories with edge ones
33-
&& echo "http://dl-cdn.alpinelinux.org/alpine/v$ALPINE_VERSION/testing" > /etc/apk/repositories \
34-
&& echo "http://dl-cdn.alpinelinux.org/alpine/v$ALPINE_VERSION/community" >> /etc/apk/repositories \
35-
&& echo "http://dl-cdn.alpinelinux.org/alpine/v$ALPINE_VERSION/main" >> /etc/apk/repositories \
40+
RUN set -ex ;\
41+
# find MAJOR and MINOR python versions based on $PYTHON_VERSION
42+
export PYTHON_MAJOR_VERSION=$(echo "${PYTHON_VERSION}" | rev | cut -d"." -f3- | rev) ;\
43+
export PYTHON_MINOR_VERSION=$(echo "${PYTHON_VERSION}" | rev | cut -d"." -f2- | rev) ;\
44+
# replacing default repositories with edge ones
45+
echo "http://dl-cdn.alpinelinux.org/alpine/v$ALPINE_VERSION/community" >> /etc/apk/repositories ;\
46+
echo "http://dl-cdn.alpinelinux.org/alpine/v$ALPINE_VERSION/main" >> /etc/apk/repositories ;\
3647

37-
# Add the packages, with a CDN-breakage fallback if needed
38-
&& apk add --no-cache $PACKAGES || \
39-
(sed -i -e 's/dl-cdn/dl-4/g' /etc/apk/repositories && apk add --no-cache $PACKAGES) \
48+
# Add the packages, with a CDN-breakage fallback if needed
49+
apk add --no-cache $PACKAGES || \
50+
(sed -i -e 's/dl-cdn/dl-4/g' /etc/apk/repositories && apk add --no-cache $PACKAGES) ;\
51+
# Add packages just for the python build process with a CDN-breakage fallback if needed
52+
apk add --no-cache --virtual .build-deps $PYTHON_BUILD_PACKAGES || \
53+
(sed -i -e 's/dl-cdn/dl-4/g' /etc/apk/repositories && apk add --no-cache --virtual .build-deps $PYTHON_BUILD_PACKAGES) ;\
4054

41-
# turn back the clock -- so hacky!
42-
&& echo "http://dl-cdn.alpinelinux.org/alpine/v$ALPINE_VERSION/main/" > /etc/apk/repositories \
43-
# && echo "@community http://dl-cdn.alpinelinux.org/alpine/v$ALPINE_VERSION/community" >> /etc/apk/repositories \
44-
# && echo "@testing http://dl-cdn.alpinelinux.org/alpine/v$ALPINE_VERSION/testing" >> /etc/apk/repositories \
45-
# && echo "@edge-main http://dl-cdn.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories \
55+
# turn back the clock -- so hacky!
56+
echo "http://dl-cdn.alpinelinux.org/alpine/v$ALPINE_VERSION/main/" > /etc/apk/repositories ;\
57+
# echo "@community http://dl-cdn.alpinelinux.org/alpine/v$ALPINE_VERSION/community" >> /etc/apk/repositories ;\
58+
# echo "@testing http://dl-cdn.alpinelinux.org/alpine/v$ALPINE_VERSION/testing" >> /etc/apk/repositories ;\
59+
# echo "@edge-main http://dl-cdn.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories ;\
4660

47-
# make some useful symlinks that are expected to exist
48-
&& if [[ ! -e /usr/bin/python ]]; then ln -sf /usr/bin/python2.7 /usr/bin/python; fi \
49-
&& if [[ ! -e /usr/bin/python-config ]]; then ln -sf /usr/bin/python2.7-config /usr/bin/python-config; fi \
50-
&& if [[ ! -e /usr/bin/easy_install ]]; then ln -sf /usr/bin/easy_install-2.7 /usr/bin/easy_install; fi \
61+
# use pyenv to download and compile specific python version
62+
git clone --depth 1 https://github.com/pyenv/pyenv /usr/lib/pyenv ;\
63+
PYENV_ROOT=/usr/lib/pyenv /usr/lib/pyenv/bin/pyenv install $PYTHON_VERSION ;\
64+
# move specific version to correct path delete pyenv, no longer needed
65+
mv /usr/lib/pyenv/versions/$PYTHON_VERSION/ $PYTHON_PATH ;\
66+
rm -rfv /usr/lib/pyenv ;\
67+
# change the path on the header of every file from PYENV_ROOT to PYTHON_PATH
68+
cd $PYTHON_PATH/bin/ && sed -i "s+/usr/lib/pyenv/versions/$PYTHON_VERSION/+$PYTHON_PATH/+g" * ;\
69+
# delete binary "duplicates" and replace them with symlinks
70+
# this also optimizes space since they are actually the same binary
71+
rm -f $PYTHON_PATH/bin/python$PYTHON_MAJOR_VERSION \
72+
$PYTHON_PATH/bin/python$PYTHON_MINOR_VERSION \
73+
$PYTHON_PATH/bin/python$PYTHON_MAJOR_VERSION-config \
74+
$PYTHON_PATH/bin/python$PYTHON_MINOR_VERSION-config ;\
75+
ln -sf $PYTHON_PATH/bin/python $PYTHON_PATH/bin/python$PYTHON_MAJOR_VERSION ;\
76+
ln -sf $PYTHON_PATH/bin/python $PYTHON_PATH/bin/python$PYTHON_MINOR_VERSION ;\
77+
ln -sf $PYTHON_PATH/bin/python-config $PYTHON_PATH/bin/python$PYTHON_MAJOR_VERSION-config ;\
78+
ln -sf $PYTHON_PATH/bin/python-config $PYTHON_PATH/bin/python$PYTHON_MINOR_VERSION-config ;\
79+
# delete files to to reduce container size
80+
# tips taken from main python docker repo
81+
find /usr/lib/python$PYTHON_VERSION -depth \( -name '*.pyo' -o -name '*.pyc' -o -name 'test' -o -name 'tests' \) -exec rm -rf '{}' + ;\
5182

52-
# Install and upgrade Pip
53-
&& easy_install pip \
54-
&& pip install --upgrade pip \
55-
&& if [[ ! -e /usr/bin/pip ]]; then ln -sf /usr/bin/pip2.7 /usr/bin/pip; fi \
56-
&& echo
83+
# remove build dependencies and any leftover apk cache
84+
apk del --no-cache --purge .build-deps ;\
85+
rm -rf /var/cache/apk/*
5786

5887
# Copy in the entrypoint script -- this installs prerequisites on container start.
5988
COPY entrypoint.sh /entrypoint.sh

2.7/Dockerfile

Lines changed: 71 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
FROM alpine:3.7
22

3-
ENV ALPINE_VERSION=3.7
3+
# VERSIONS
4+
ENV ALPINE_VERSION=3.7 \
5+
PYTHON_VERSION=2.7.14
46

5-
# Install needed packages. Notes:
7+
# PATHS
8+
ENV PYTHON_PATH=/usr/lib/python$PYTHON_VERSION \
9+
PATH="/usr/lib/python$PYTHON_VERSION/bin/:${PATH}"
10+
11+
# PACKAGES
612
# * dumb-init: a proper init system for containers, to reap zombie children
713
# * musl: standard C library
814
# * lib6-compat: compatibility libraries for glibc
@@ -11,49 +17,72 @@ ENV ALPINE_VERSION=3.7
1117
# * bash: so we can access /bin/bash
1218
# * git: to ease up clones of repos
1319
# * ca-certificates: for SSL verification during Pip and easy_install
14-
# * python: the binaries themselves
15-
# * python-dev: are used for gevent e.g.
16-
# * py-setuptools: required only in major version 2, installs easy_install so we can install Pip.
1720
ENV PACKAGES="\
18-
dumb-init \
19-
musl \
20-
libc6-compat \
21-
linux-headers \
22-
build-base \
23-
bash \
24-
git \
25-
ca-certificates \
26-
python2 \
27-
python2-dev \
28-
py-setuptools \
21+
dumb-init \
22+
musl \
23+
libc6-compat \
24+
linux-headers \
25+
build-base \
26+
bash \
27+
git \
28+
ca-certificates \
29+
"
30+
31+
# PACKAGES needed to built python
32+
ENV PYTHON_BUILD_PACKAGES="\
33+
readline-dev \
34+
zlib-dev \
35+
bzip2-dev \
36+
sqlite-dev \
37+
libressl-dev \
2938
"
3039

31-
RUN echo \
32-
# replacing default repositories with edge ones
33-
&& echo "http://dl-cdn.alpinelinux.org/alpine/v$ALPINE_VERSION/testing" > /etc/apk/repositories \
34-
&& echo "http://dl-cdn.alpinelinux.org/alpine/v$ALPINE_VERSION/community" >> /etc/apk/repositories \
35-
&& echo "http://dl-cdn.alpinelinux.org/alpine/v$ALPINE_VERSION/main" >> /etc/apk/repositories \
36-
37-
# Add the packages, with a CDN-breakage fallback if needed
38-
&& apk add --no-cache $PACKAGES || \
39-
(sed -i -e 's/dl-cdn/dl-4/g' /etc/apk/repositories && apk add --no-cache $PACKAGES) \
40-
41-
# turn back the clock -- so hacky!
42-
&& echo "http://dl-cdn.alpinelinux.org/alpine/v$ALPINE_VERSION/main/" > /etc/apk/repositories \
43-
# && echo "@community http://dl-cdn.alpinelinux.org/alpine/v$ALPINE_VERSION/community" >> /etc/apk/repositories \
44-
# && echo "@testing http://dl-cdn.alpinelinux.org/alpine/v$ALPINE_VERSION/testing" >> /etc/apk/repositories \
45-
# && echo "@edge-main http://dl-cdn.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories \
46-
47-
# make some useful symlinks that are expected to exist
48-
&& if [[ ! -e /usr/bin/python ]]; then ln -sf /usr/bin/python2.7 /usr/bin/python; fi \
49-
&& if [[ ! -e /usr/bin/python-config ]]; then ln -sf /usr/bin/python2.7-config /usr/bin/python-config; fi \
50-
&& if [[ ! -e /usr/bin/easy_install ]]; then ln -sf /usr/bin/easy_install-2.7 /usr/bin/easy_install; fi \
51-
52-
# Install and upgrade Pip
53-
&& easy_install pip \
54-
&& pip install --upgrade pip \
55-
&& if [[ ! -e /usr/bin/pip ]]; then ln -sf /usr/bin/pip2.7 /usr/bin/pip; fi \
56-
&& echo
40+
RUN set -ex ;\
41+
# find MAJOR and MINOR python versions based on $PYTHON_VERSION
42+
export PYTHON_MAJOR_VERSION=$(echo "${PYTHON_VERSION}" | rev | cut -d"." -f3- | rev) ;\
43+
export PYTHON_MINOR_VERSION=$(echo "${PYTHON_VERSION}" | rev | cut -d"." -f2- | rev) ;\
44+
# replacing default repositories with edge ones
45+
echo "http://dl-cdn.alpinelinux.org/alpine/v$ALPINE_VERSION/community" >> /etc/apk/repositories ;\
46+
echo "http://dl-cdn.alpinelinux.org/alpine/v$ALPINE_VERSION/main" >> /etc/apk/repositories ;\
47+
48+
# Add the packages, with a CDN-breakage fallback if needed
49+
apk add --no-cache $PACKAGES || \
50+
(sed -i -e 's/dl-cdn/dl-4/g' /etc/apk/repositories && apk add --no-cache $PACKAGES) ;\
51+
# Add packages just for the python build process with a CDN-breakage fallback if needed
52+
apk add --no-cache --virtual .build-deps $PYTHON_BUILD_PACKAGES || \
53+
(sed -i -e 's/dl-cdn/dl-4/g' /etc/apk/repositories && apk add --no-cache --virtual .build-deps $PYTHON_BUILD_PACKAGES) ;\
54+
55+
# turn back the clock -- so hacky!
56+
echo "http://dl-cdn.alpinelinux.org/alpine/v$ALPINE_VERSION/main/" > /etc/apk/repositories ;\
57+
# echo "@community http://dl-cdn.alpinelinux.org/alpine/v$ALPINE_VERSION/community" >> /etc/apk/repositories ;\
58+
# echo "@testing http://dl-cdn.alpinelinux.org/alpine/v$ALPINE_VERSION/testing" >> /etc/apk/repositories ;\
59+
# echo "@edge-main http://dl-cdn.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories ;\
60+
61+
# use pyenv to download and compile specific python version
62+
git clone --depth 1 https://github.com/pyenv/pyenv /usr/lib/pyenv ;\
63+
PYENV_ROOT=/usr/lib/pyenv /usr/lib/pyenv/bin/pyenv install $PYTHON_VERSION ;\
64+
# move specific version to correct path delete pyenv, no longer needed
65+
mv /usr/lib/pyenv/versions/$PYTHON_VERSION/ $PYTHON_PATH ;\
66+
rm -rfv /usr/lib/pyenv ;\
67+
# change the path on the header of every file from PYENV_ROOT to PYTHON_PATH
68+
cd $PYTHON_PATH/bin/ && sed -i "s+/usr/lib/pyenv/versions/$PYTHON_VERSION/+$PYTHON_PATH/+g" * ;\
69+
# delete binary "duplicates" and replace them with symlinks
70+
# this also optimizes space since they are actually the same binary
71+
rm -f $PYTHON_PATH/bin/python$PYTHON_MAJOR_VERSION \
72+
$PYTHON_PATH/bin/python$PYTHON_MINOR_VERSION \
73+
$PYTHON_PATH/bin/python$PYTHON_MAJOR_VERSION-config \
74+
$PYTHON_PATH/bin/python$PYTHON_MINOR_VERSION-config ;\
75+
ln -sf $PYTHON_PATH/bin/python $PYTHON_PATH/bin/python$PYTHON_MAJOR_VERSION ;\
76+
ln -sf $PYTHON_PATH/bin/python $PYTHON_PATH/bin/python$PYTHON_MINOR_VERSION ;\
77+
ln -sf $PYTHON_PATH/bin/python-config $PYTHON_PATH/bin/python$PYTHON_MAJOR_VERSION-config ;\
78+
ln -sf $PYTHON_PATH/bin/python-config $PYTHON_PATH/bin/python$PYTHON_MINOR_VERSION-config ;\
79+
# delete files to to reduce container size
80+
# tips taken from main python docker repo
81+
find /usr/lib/python$PYTHON_VERSION -depth \( -name '*.pyo' -o -name '*.pyc' -o -name 'test' -o -name 'tests' \) -exec rm -rf '{}' + ;\
82+
83+
# remove build dependencies and any leftover apk cache
84+
apk del --no-cache --purge .build-deps ;\
85+
rm -rf /var/cache/apk/*
5786

5887
# since we will be "always" mounting the volume, we can set this up
5988
ENTRYPOINT ["/usr/bin/dumb-init"]

3.6-onbuild/Dockerfile

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
FROM alpine:3.7
2+
3+
# VERSIONS
4+
ENV ALPINE_VERSION=3.7 \
5+
PYTHON_VERSION=3.6.5
6+
7+
# PATHS
8+
ENV PYTHON_PATH=/usr/lib/python$PYTHON_VERSION \
9+
PATH="/usr/lib/python$PYTHON_VERSION/bin/:${PATH}"
10+
11+
# PACKAGES
12+
# * dumb-init: a proper init system for containers, to reap zombie children
13+
# * musl: standard C library
14+
# * lib6-compat: compatibility libraries for glibc
15+
# * linux-headers: commonly needed, and an unusual package name from Alpine.
16+
# * build-base: used so we include the basic development packages (gcc)
17+
# * bash: so we can access /bin/bash
18+
# * git: to ease up clones of repos
19+
# * ca-certificates: for SSL verification during Pip and easy_install
20+
ENV PACKAGES="\
21+
dumb-init \
22+
musl \
23+
libc6-compat \
24+
linux-headers \
25+
build-base \
26+
bash \
27+
git \
28+
ca-certificates \
29+
"
30+
31+
# PACKAGES needed to built python
32+
ENV PYTHON_BUILD_PACKAGES="\
33+
readline-dev \
34+
zlib-dev \
35+
bzip2-dev \
36+
sqlite-dev \
37+
libressl-dev \
38+
"
39+
40+
RUN set -ex ;\
41+
# find MAJOR and MINOR python versions based on $PYTHON_VERSION
42+
export PYTHON_MAJOR_VERSION=$(echo "${PYTHON_VERSION}" | rev | cut -d"." -f3- | rev) ;\
43+
export PYTHON_MINOR_VERSION=$(echo "${PYTHON_VERSION}" | rev | cut -d"." -f2- | rev) ;\
44+
# replacing default repositories with edge ones
45+
echo "http://dl-cdn.alpinelinux.org/alpine/v$ALPINE_VERSION/community" >> /etc/apk/repositories ;\
46+
echo "http://dl-cdn.alpinelinux.org/alpine/v$ALPINE_VERSION/main" >> /etc/apk/repositories ;\
47+
48+
# Add the packages, with a CDN-breakage fallback if needed
49+
apk add --no-cache $PACKAGES || \
50+
(sed -i -e 's/dl-cdn/dl-4/g' /etc/apk/repositories && apk add --no-cache $PACKAGES) ;\
51+
# Add packages just for the python build process with a CDN-breakage fallback if needed
52+
apk add --no-cache --virtual .build-deps $PYTHON_BUILD_PACKAGES || \
53+
(sed -i -e 's/dl-cdn/dl-4/g' /etc/apk/repositories && apk add --no-cache --virtual .build-deps $PYTHON_BUILD_PACKAGES) ;\
54+
55+
# turn back the clock -- so hacky!
56+
echo "http://dl-cdn.alpinelinux.org/alpine/v$ALPINE_VERSION/main/" > /etc/apk/repositories ;\
57+
# echo "@community http://dl-cdn.alpinelinux.org/alpine/v$ALPINE_VERSION/community" >> /etc/apk/repositories ;\
58+
# echo "@testing http://dl-cdn.alpinelinux.org/alpine/v$ALPINE_VERSION/testing" >> /etc/apk/repositories ;\
59+
# echo "@edge-main http://dl-cdn.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories ;\
60+
61+
# use pyenv to download and compile specific python version
62+
git clone --depth 1 https://github.com/pyenv/pyenv /usr/lib/pyenv ;\
63+
PYENV_ROOT=/usr/lib/pyenv /usr/lib/pyenv/bin/pyenv install $PYTHON_VERSION ;\
64+
# move specific version to correct path delete pyenv, no longer needed
65+
mv /usr/lib/pyenv/versions/$PYTHON_VERSION/ $PYTHON_PATH ;\
66+
rm -rfv /usr/lib/pyenv ;\
67+
# change the path on the header of every file from PYENV_ROOT to PYTHON_PATH
68+
cd $PYTHON_PATH/bin/ && sed -i "s+/usr/lib/pyenv/versions/$PYTHON_VERSION/+$PYTHON_PATH/+g" * ;\
69+
# delete binary "duplicates" and replace them with symlinks
70+
# this also optimizes space since they are actually the same binary
71+
rm -f $PYTHON_PATH/bin/python$PYTHON_MAJOR_VERSION \
72+
$PYTHON_PATH/bin/python$PYTHON_MINOR_VERSION \
73+
$PYTHON_PATH/bin/python$PYTHON_MAJOR_VERSION-config \
74+
$PYTHON_PATH/bin/python$PYTHON_MINOR_VERSION-config ;\
75+
ln -sf $PYTHON_PATH/bin/python $PYTHON_PATH/bin/python$PYTHON_MAJOR_VERSION ;\
76+
ln -sf $PYTHON_PATH/bin/python $PYTHON_PATH/bin/python$PYTHON_MINOR_VERSION ;\
77+
ln -sf $PYTHON_PATH/bin/python-config $PYTHON_PATH/bin/python$PYTHON_MAJOR_VERSION-config ;\
78+
ln -sf $PYTHON_PATH/bin/python-config $PYTHON_PATH/bin/python$PYTHON_MINOR_VERSION-config ;\
79+
# delete files to to reduce container size
80+
# tips taken from main python docker repo
81+
find /usr/lib/python$PYTHON_VERSION -depth \( -name '*.pyo' -o -name '*.pyc' -o -name 'test' -o -name 'tests' \) -exec rm -rf '{}' + ;\
82+
83+
# remove build dependencies and any leftover apk cache
84+
apk del --no-cache --purge .build-deps ;\
85+
rm -rf /var/cache/apk/*
86+
87+
# Copy in the entrypoint script -- this installs prerequisites on container start.
88+
COPY entrypoint.sh /entrypoint.sh
89+
90+
# install requirements
91+
# this way when you build you won't need to install again
92+
# and since COPY is cached we don't need to wait
93+
ONBUILD COPY requirements.txt /tmp/requirements.txt
94+
95+
# Run the dependencies installer and then allow it to be run again if needed.
96+
ONBUILD RUN /entrypoint.sh -r /tmp/requirements.txt
97+
ONBUILD RUN rm -f /requirements.installed
98+
99+
# since we will be "always" mounting the volume, we can set this up
100+
ENTRYPOINT ["/usr/bin/dumb-init"]
101+
CMD ["python"]
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)