Skip to content

Commit f288b6d

Browse files
authored
feat: Use docker multistage build (#8)
Using this approach the image reduced from 829MB -> 675MB
1 parent 267ae35 commit f288b6d

1 file changed

Lines changed: 42 additions & 6 deletions

File tree

Dockerfile

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,55 @@
1-
FROM python:3.9.1-slim-buster
1+
FROM python:3.9.1-slim-buster as python-base
22

33
LABEL maintainer="Igor Davydenko <iam@igordavydenko.com>"
44
LABEL description="Add poetry, pre-commit, and other dev-tools to official Python slim Docker image."
55

6+
# poetry envirnment
7+
ENV POETRY_HOME="/opt/poetry"
8+
ENV POETRY_NO_INTERACTION=1
9+
10+
# versions
11+
ENV POETRY_VERSION=1.1.4
12+
ENV PIP_VERSION 20.3.3
13+
ENV PRE_COMMIT_VERSION 2.9.3
14+
ENV TOX_VERSION 3.20.1
15+
ENV VIRTUALENV_VERSION 20.2.2
16+
17+
# additonal applications to install
18+
ENV ADDITIONAL_APPS \
19+
curl \
20+
gettext \
21+
git \
22+
locales \
23+
locales-all \
24+
make \
25+
nano \
26+
openssh-client \
27+
rsync
28+
29+
# prepend poetry
30+
ENV PATH="$POETRY_HOME/bin:$PATH"
31+
632
RUN apt update -qq \
733
&& apt upgrade -y \
8-
&& apt install -y curl gcc g++ gettext git locales locales-all make nano openssh-client rsync \
934
&& apt autoremove -y
1035

11-
ENV PATH="/root/.local/bin:/root/.poetry/bin:${PATH}"
36+
FROM python-base as poetry-builder-base
37+
RUN apt install -y \
38+
curl \
39+
build-essential
40+
RUN curl -sSL https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py | python
41+
RUN poetry --version
1242

13-
RUN pip install pip==20.3.3 pre-commit==2.9.3 tox==3.20.1 virtualenv==20.2.2
1443

15-
ENV POETRY_VERSION=1.1.4
16-
RUN curl -sSL https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py | python
44+
FROM python-base as development-base
45+
RUN apt install -y $ADDITIONAL_APPS && apt autoremove -y
46+
RUN pip install \
47+
pip==$PIP_VERSION \
48+
pre-commit==$PRE_COMMIT_VERSION \
49+
tox==$TOX_VERSION \
50+
virtualenv==$VIRTUALENV_VERSION
51+
52+
COPY --from=poetry-builder-base $POETRY_HOME $POETRY_HOME
1753

1854
WORKDIR /app
1955
CMD ["python3"]

0 commit comments

Comments
 (0)