Skip to content

Commit dc66b83

Browse files
committed
Convert to multi-stage build
This should result in smaller images. Signed-off-by: Stephen Finucane <[email protected]>
1 parent db0f81e commit dc66b83

File tree

1 file changed

+47
-8
lines changed

1 file changed

+47
-8
lines changed

Dockerfile

+47-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,38 @@
1-
FROM ubuntu:20.04
1+
FROM ubuntu:20.04 AS base
22

33
ENV LANG="C.UTF-8"
44
ENV LC_ALL="C.UTF-8"
55
ENV PATH="/opt/pyenv/shims:/opt/pyenv/bin:$PATH"
66
ENV PYENV_ROOT="/opt/pyenv"
77
ENV PYENV_SHELL="bash"
88

9+
# runtime dependencies
10+
RUN apt-get update --quiet && \
11+
apt-get install -y --no-install-recommends \
12+
bzip2 \
13+
ca-certificates \
14+
curl \
15+
git \
16+
libexpat1 \
17+
$(apt-cache search --names-only 'libffi[0-9]+$' 2>/dev/null | awk '{print $1}') \
18+
$(apt-cache search --names-only 'libmpdec[0-9]+$' 2>/dev/null | awk '{print $1}') \
19+
libncursesw5 \
20+
$(apt-cache show libncursesw6 >/dev/null 2>&1 && echo libncursesw6 || true) \
21+
$(apt-cache search --names-only 'libreadline[0-9]+$' 2>/dev/null | awk '{print $1}') \
22+
libsqlite3-0 \
23+
libssl1.1 \
24+
lzma \
25+
zlib1g
26+
27+
RUN curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash && \
28+
git clone https://github.com/momo-lab/xxenv-latest $PYENV_ROOT/plugins/xxenv-latest && \
29+
pyenv update
30+
31+
# ---
32+
33+
FROM base as build
34+
35+
# builder dependencies
936
RUN apt-get update && apt-get install -y --no-install-recommends \
1037
build-essential \
1138
ca-certificates \
@@ -18,14 +45,26 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
1845
libssl-dev \
1946
zlib1g-dev
2047

21-
RUN curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash && \
22-
git clone https://github.com/momo-lab/xxenv-latest $PYENV_ROOT/plugins/xxenv-latest && \
23-
pyenv update
24-
2548
RUN pyenv latest install 3.6 && \
2649
pyenv latest install 3.7 && \
2750
pyenv latest install 3.8 && \
28-
pyenv latest install 3.9
29-
RUN pyenv global $(pyenv versions --bare | tac)
51+
pyenv latest install 3.9 && \
52+
pyenv global $(pyenv versions --bare | tac) && \
53+
pyenv versions && \
54+
find ${PYENV_ROOT}/versions -depth \
55+
\( \
56+
\( -type d -a \( -name test -o -name tests -o -name idle_test \) \) \
57+
-o \( -type f -a \( -name '*.pyc' -o -name '*.pyo' -o -name '*.a' \) \) \
58+
-o \( -type f -a -name 'wininst-*.exe' \) \
59+
\) -exec rm -rf '{}' + && \
60+
pip install tox tox-pyenv
61+
62+
# ---
63+
64+
FROM base
65+
66+
COPY --from=build ${PYENV_ROOT}/versions/ ${PYENV_ROOT}/versions/
3067

31-
RUN pip install tox tox-pyenv
68+
RUN pyenv rehash && \
69+
pyenv global $(pyenv versions --bare | tac) && \
70+
pyenv versions

0 commit comments

Comments
 (0)